Fix class change on captured flag not working

This commit is contained in:
rubenwardy 2020-03-14 19:52:40 +00:00
parent 63b543a8fb
commit 917e362d39
2 changed files with 24 additions and 36 deletions

View file

@ -153,25 +153,12 @@ ctf_colors.set_skin = function(player, color)
ctf_classes.set_skin(player, color, ctf_classes.get(player)) ctf_classes.set_skin(player, color, ctf_classes.get(player))
end end
local flags = { local old_func = ctf_flag.on_punch
"ctf_flag:flag", local function on_punch(pos, node, player, ...)
"ctf_flag:flag_top_red",
"ctf_flag:flag_top_blue",
}
for _, flagname in pairs(flags) do
local old_func = minetest.registered_nodes[flagname].on_punch
local function on_punch(pos, node, player, ...)
local fpos = pos
if node.name:sub(1, 18) == "ctf_flag:flag_top_" then
fpos = vector.new(pos)
fpos.y = fpos.y - 1
end
local class = ctf_classes.get(player) local class = ctf_classes.get(player)
if not class.properties.can_capture then if not class.properties.can_capture then
local pname = player:get_player_name() local pname = player:get_player_name()
local flag = ctf_flag.get(fpos) local flag = ctf_flag.get(pos)
local team = ctf.player(pname).team local team = ctf.player(pname).team
if flag and flag.team and team and team ~= flag.team then if flag and flag.team and team and team ~= flag.team then
minetest.chat_send_player(pname, minetest.chat_send_player(pname,
@ -181,16 +168,15 @@ for _, flagname in pairs(flags) do
end end
return old_func(pos, node, player, ...) return old_func(pos, node, player, ...)
end
local function show(_, _, player)
ctf_classes.show_gui(player:get_player_name(), player)
end
minetest.override_item(flagname, {
on_punch = on_punch,
on_rightclick = show,
})
end end
local function show(_, _, player)
ctf_classes.show_gui(player:get_player_name(), player)
end
ctf_flag.on_rightclick = show
ctf_flag.on_punch = on_punch
ctf_classes.register_on_changed(function(player, old, new) ctf_classes.register_on_changed(function(player, old, new)
if not old then if not old then
return return

View file

@ -20,8 +20,10 @@ minetest.register_node("ctf_flag:flag", {
} }
}, },
groups = {immortal=1,is_flag=1,flag_bottom=1}, groups = {immortal=1,is_flag=1,flag_bottom=1},
on_punch = ctf_flag.on_punch,
on_rightclick = ctf_flag.on_rightclick, -- Wrap fuctions to allow overriding
on_punch = function(...) ctf_flag.on_punch(...) end,
on_rightclick = function(...) ctf_flag.on_rightclick(...) end,
on_construct = ctf_flag.on_construct, on_construct = ctf_flag.on_construct,
after_place_node = ctf_flag.after_place_node, after_place_node = ctf_flag.after_place_node,
on_timer = ctf_flag.flag_tick on_timer = ctf_flag.flag_tick