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
This commit is contained in:
savilli 2021-02-14 01:17:05 +03:00 committed by GitHub
parent 3e95d92359
commit abf1fa2ad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 42 deletions

View file

@ -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, ...
)

View file

@ -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 " ..

View file

@ -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
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 true
return false
end
if hitter and ctf_respawn_immunity.is_immune(hitter) then
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
end
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)

View file

@ -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

View file

@ -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)