Add prepick_up and precapture callbacks to ctf_flag to allow cancelling
This commit is contained in:
parent
e672344383
commit
43b7d2c86c
@ -14,6 +14,22 @@ function ctf_flag.register_on_pick_up(func)
|
|||||||
table.insert(ctf_flag.registered_on_pick_up, func)
|
table.insert(ctf_flag.registered_on_pick_up, func)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ctf_flag.registered_on_precapture = {}
|
||||||
|
function ctf_flag.register_on_precapture(func)
|
||||||
|
if ctf._mt_loaded then
|
||||||
|
error("You can't register callbacks at game time!")
|
||||||
|
end
|
||||||
|
table.insert(ctf_flag.registered_on_precapture, func)
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf_flag.registered_on_prepick_up = {}
|
||||||
|
function ctf_flag.register_on_prepick_up(func)
|
||||||
|
if ctf._mt_loaded then
|
||||||
|
error("You can't register callbacks at game time!")
|
||||||
|
end
|
||||||
|
table.insert(ctf_flag.registered_on_prepick_up, func)
|
||||||
|
end
|
||||||
|
|
||||||
function ctf_flag.collect_claimed()
|
function ctf_flag.collect_claimed()
|
||||||
local claimed = {}
|
local claimed = {}
|
||||||
for _, team in pairs(ctf.teams) do
|
for _, team in pairs(ctf.teams) do
|
||||||
|
@ -10,6 +10,12 @@ local function do_capture(attname, flag, returned)
|
|||||||
|
|
||||||
|
|
||||||
if ctf.setting("flag.capture_take") and not returned then
|
if ctf.setting("flag.capture_take") and not returned then
|
||||||
|
for i = 1, #ctf_flag.registered_on_prepick_up do
|
||||||
|
if not ctf_flag.registered_on_prepick_up[i](attname, flag) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.chat_send_all(flag_name.." has been picked up by "..
|
minetest.chat_send_all(flag_name.." has been picked up by "..
|
||||||
attname.." (team "..attacker.team..")")
|
attname.." (team "..attacker.team..")")
|
||||||
|
|
||||||
@ -39,6 +45,12 @@ local function do_capture(attname, flag, returned)
|
|||||||
ctf_flag.registered_on_pick_up[i](attname, flag)
|
ctf_flag.registered_on_pick_up[i](attname, flag)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
for i = 1, #ctf_flag.registered_on_prepick_up do
|
||||||
|
if not ctf_flag.registered_on_precapture[i](attname, flag) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.chat_send_all(flag_name.." has been captured "..
|
minetest.chat_send_all(flag_name.." has been captured "..
|
||||||
" by "..attname.." (team "..attacker.team..")")
|
" by "..attname.." (team "..attacker.team..")")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user