Fix class change on captured flag not working
This commit is contained in:
parent
63b543a8fb
commit
917e362d39
2 changed files with 24 additions and 36 deletions
|
@ -153,44 +153,30 @@ 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",
|
local class = ctf_classes.get(player)
|
||||||
"ctf_flag:flag_top_blue",
|
if not class.properties.can_capture then
|
||||||
}
|
local pname = player:get_player_name()
|
||||||
|
local flag = ctf_flag.get(pos)
|
||||||
for _, flagname in pairs(flags) do
|
local team = ctf.player(pname).team
|
||||||
local old_func = minetest.registered_nodes[flagname].on_punch
|
if flag and flag.team and team and team ~= flag.team then
|
||||||
local function on_punch(pos, node, player, ...)
|
minetest.chat_send_player(pname,
|
||||||
local fpos = pos
|
"You need to change classes to capture the flag!")
|
||||||
if node.name:sub(1, 18) == "ctf_flag:flag_top_" then
|
return
|
||||||
fpos = vector.new(pos)
|
|
||||||
fpos.y = fpos.y - 1
|
|
||||||
end
|
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
|
end
|
||||||
local function show(_, _, player)
|
|
||||||
ctf_classes.show_gui(player:get_player_name(), player)
|
return old_func(pos, node, 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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue