From 917e362d393b79fd597a3a8f98be68cf84e4c811 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 14 Mar 2020 19:52:40 +0000 Subject: [PATCH] Fix class change on captured flag not working --- mods/ctf/ctf_classes/init.lua | 54 +++++++++++++---------------------- mods/ctf/ctf_flag/flags.lua | 6 ++-- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index dc161d2..b6bc99d 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -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 diff --git a/mods/ctf/ctf_flag/flags.lua b/mods/ctf/ctf_flag/flags.lua index a7a9d8d..776d06e 100644 --- a/mods/ctf/ctf_flag/flags.lua +++ b/mods/ctf/ctf_flag/flags.lua @@ -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