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,44 +153,30 @@ ctf_colors.set_skin = function(player, color)
ctf_classes.set_skin(player, color, ctf_classes.get(player))
end
local flags = {
"ctf_flag:flag",
"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
local old_func = ctf_flag.on_punch
local function on_punch(pos, node, player, ...)
local class = ctf_classes.get(player)
if not class.properties.can_capture then
local pname = player:get_player_name()
local flag = ctf_flag.get(pos)
local team = ctf.player(pname).team
if flag and flag.team and team and team ~= flag.team then
minetest.chat_send_player(pname,
"You need to change classes to capture the flag!")
return
end
local class = ctf_classes.get(player)
if not class.properties.can_capture then
local pname = player:get_player_name()
local flag = ctf_flag.get(fpos)
local team = ctf.player(pname).team
if flag and flag.team and team and team ~= flag.team then
minetest.chat_send_player(pname,
"You need to change classes to capture the flag!")
return
end
end
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,
})
return old_func(pos, node, player, ...)
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)
if not old then
return

View file

@ -20,8 +20,10 @@ minetest.register_node("ctf_flag:flag", {
}
},
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,
after_place_node = ctf_flag.after_place_node,
on_timer = ctf_flag.flag_tick