From abf1fa2ad540424044a94da7d847e0e76f9f19b0 Mon Sep 17 00:00:00 2001 From: savilli <78875209+savilli@users.noreply.github.com> Date: Sun, 14 Feb 2021 01:17:05 +0300 Subject: [PATCH] Don't count kill assist on build time or player immunity (#795) * Don't count kill assist on build time or player immunity * Remove register_can_attack, use can_attack global func --- mods/ctf/ctf/teams.lua | 20 ++++++++++---- mods/ctf/ctf_match/buildtime.lua | 9 ++++--- mods/ctf/ctf_respawn_immunity/init.lua | 36 ++++++++++++-------------- mods/pvp/anticoward/init.lua | 16 ++---------- mods/pvp/kill_assist/init.lua | 2 +- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/mods/ctf/ctf/teams.lua b/mods/ctf/ctf/teams.lua index 69afa9c..115020a 100644 --- a/mods/ctf/ctf/teams.lua +++ b/mods/ctf/ctf/teams.lua @@ -446,12 +446,16 @@ function ctf.register_on_killedplayer(func) table.insert(ctf.registered_on_killedplayer, func) end -ctf.registered_on_punchplayer = {} -function ctf.register_on_punchplayer(func) +function ctf.can_attack(player, hitter, time_from_last_punch, tool_capabilities, dir, damage, ...) + return true +end + +ctf.registered_on_attack = {} +function ctf.register_on_attack(func) if ctf._mt_loaded then error("You can't register callbacks at game time!") end - table.insert(ctf.registered_on_punchplayer, func) + table.insert(ctf.registered_on_attack, func) end local dead_players = {} @@ -482,6 +486,12 @@ minetest.register_on_punchplayer(function(player, hitter, end end + if ctf.can_attack(player, hitter, time_from_last_punch, tool_capabilities, + dir, damage, ...) == false + then + return true + end + local hp = player:get_hp() if hp == 0 then return false @@ -497,8 +507,8 @@ minetest.register_on_punchplayer(function(player, hitter, return false end - for i = 1, #ctf.registered_on_punchplayer do - ctf.registered_on_punchplayer[i]( + for i = 1, #ctf.registered_on_attack do + ctf.registered_on_attack[i]( player, hitter, time_from_last_punch, tool_capabilities, dir, damage, ... ) diff --git a/mods/ctf/ctf_match/buildtime.lua b/mods/ctf/ctf_match/buildtime.lua index 5caead3..b2f52e4 100644 --- a/mods/ctf/ctf_match/buildtime.lua +++ b/mods/ctf/ctf_match/buildtime.lua @@ -62,14 +62,17 @@ minetest.register_globalstep(function(delta) end end) -minetest.register_on_punchplayer(function(_, hitter) +local old_can_attack = ctf.can_attack +function ctf.can_attack(player, hitter, ...) if ctf_match.is_in_build_time() then if hitter:is_player() then minetest.chat_send_player(hitter:get_player_name(), "Match hasn't started yet!") end - return true + return false end -end) + + return old_can_attack(player, hitter, ...) +end ctf_match.register_on_build_time_start(function() minetest.chat_send_all(minetest.colorize("#fcca05", ("Prepare your base! Match starts in " .. diff --git a/mods/ctf/ctf_respawn_immunity/init.lua b/mods/ctf/ctf_respawn_immunity/init.lua index ae64984..8004be4 100644 --- a/mods/ctf/ctf_respawn_immunity/init.lua +++ b/mods/ctf/ctf_respawn_immunity/init.lua @@ -34,32 +34,30 @@ function ctf_respawn_immunity.update_effects(player) -- end end -minetest.register_on_punchplayer(function(player, hitter, - time_from_last_punch, tool_capabilities, dir, damage) +local old_can_attack = ctf.can_attack +function ctf.can_attack(player, hitter, ...) if not player or not hitter then - return false + return end local pname = player:get_player_name() local hname = hitter:get_player_name() - local pteam = ctf.player(pname).team - local hteam = ctf.player(hname).team - if pteam ~= hteam then - if player and ctf_respawn_immunity.is_immune(player) then - minetest.chat_send_player(hname, minetest.colorize("#EE8822", pname .. - " just respawned or joined," .. " and is immune to attacks!")) - return true - end - - if hitter and ctf_respawn_immunity.is_immune(hitter) then - minetest.chat_send_player(hname, minetest.colorize("#FF8C00", - "Your immunity has ended because you attacked a player")) - immune_players[hname] = nil - ctf_respawn_immunity.update_effects(hitter) - end + if ctf_respawn_immunity.is_immune(player) then + minetest.chat_send_player(hname, minetest.colorize("#EE8822", pname .. + " just respawned or joined," .. " and is immune to attacks!")) + return false end -end) + + if ctf_respawn_immunity.is_immune(hitter) then + minetest.chat_send_player(hname, minetest.colorize("#FF8C00", + "Your immunity has ended because you attacked a player")) + immune_players[hname] = nil + ctf_respawn_immunity.update_effects(hitter) + end + + return old_can_attack(player, hitter, ...) +end minetest.register_on_joinplayer(ctf_respawn_immunity.set_immune) minetest.register_on_respawnplayer(ctf_respawn_immunity.set_immune) diff --git a/mods/pvp/anticoward/init.lua b/mods/pvp/anticoward/init.lua index e8165d9..238ba29 100644 --- a/mods/pvp/anticoward/init.lua +++ b/mods/pvp/anticoward/init.lua @@ -9,24 +9,12 @@ local COMBATLOG_SCORE_PENALTY = 10 --- Make suicides and combat logs award last puncher with kill -- -minetest.register_on_punchplayer(function(player, hitter, +ctf.register_on_attack(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) if player and hitter then - if ctf_respawn_immunity.is_immune(player) or ctf_match.is_in_build_time() then - return - end - local pname = player:get_player_name() local hname = hitter:get_player_name() - local to = ctf.player(pname) - local from = ctf.player(hname) - - if to.team == from.team and to.team ~= "" and - to.team ~= nil and to.name ~= from.name then - return - end - local hp = player:get_hp() - damage if hp <= 0 then if potential_cowards[pname] then @@ -39,7 +27,7 @@ minetest.register_on_punchplayer(function(player, hitter, potential_cowards[hname] = nil end - return false + return end if not potential_cowards[pname] then diff --git a/mods/pvp/kill_assist/init.lua b/mods/pvp/kill_assist/init.lua index 25d5e38..b813500 100644 --- a/mods/pvp/kill_assist/init.lua +++ b/mods/pvp/kill_assist/init.lua @@ -75,7 +75,7 @@ ctf.register_on_killedplayer(function(victim, killer, _, toolcaps) kill_assist.reward_assists(victim, killer, reward) end) -ctf.register_on_punchplayer(function(player, hitter, _, _, _, damage) +ctf.register_on_attack(function(player, hitter, _, _, _, damage) kill_assist.add_assist(player:get_player_name(), hitter:get_player_name(), damage) end)