diff --git a/ctf_flag/init.lua b/ctf_flag/init.lua index 5484e42..893955e 100644 --- a/ctf_flag/init.lua +++ b/ctf_flag/init.lua @@ -6,16 +6,23 @@ ctf.register_on_init(function() ctf._set("flag.names", true) ctf._set("flag.waypoints", true) ctf._set("flag.protect_distance", 25) + ctf._set("flag.nobuild_radius", 3) ctf._set("flag.capture_mode", "take") ctf._set("gui.team.teleport_to_flag", true) ctf._set("gui.team.teleport_to_spawn", false) end) +dofile(minetest.get_modpath("ctf_flag") .. "/hud.lua") +dofile(minetest.get_modpath("ctf_flag") .. "/gui.lua") +dofile(minetest.get_modpath("ctf_flag") .. "/flag_func.lua") +dofile(minetest.get_modpath("ctf_flag") .. "/api.lua") +dofile(minetest.get_modpath("ctf_flag") .. "/flags.lua") + ctf.register_on_new_team(function(team) team.flags = {} end) -ctf.register_on_territory_query(function(pos) +function ctf_flag.get_nearest(pos) local closest = nil local closest_team = nil local closest_distSQ = 1000000 @@ -34,7 +41,9 @@ ctf.register_on_territory_query(function(pos) end return closest_team, closest_distSQ -end) +end + +ctf.register_on_territory_query(ctf_flag.get_nearest) function ctf.get_spawn(team) if not ctf.team(team) then @@ -54,8 +63,21 @@ function ctf.get_spawn(team) end end -dofile(minetest.get_modpath("ctf_flag") .. "/hud.lua") -dofile(minetest.get_modpath("ctf_flag") .. "/gui.lua") -dofile(minetest.get_modpath("ctf_flag") .. "/flag_func.lua") -dofile(minetest.get_modpath("ctf_flag") .. "/api.lua") -dofile(minetest.get_modpath("ctf_flag") .. "/flags.lua") +-- Add minimum build range +local old_is_protected = minetest.is_protected +local r = ctf.setting("flag.nobuild_radius") +local rs = r * r +function minetest.is_protected(pos, name) + if rs == 0 then + return old_is_protected(pos, name) + end + + local tname, distsq = ctf_flag.get_nearest(pos) + if distsq < rs then + minetest.chat_send_player(name, + "Too close to the flag! You need to be at least " .. r .. " nodes away.") + return true + else + return old_is_protected(pos, name) + end +end