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