Remove attacker from combat if attacking victim dies

This commit is contained in:
LoneWolfHT 2020-09-19 15:00:57 -07:00
parent 744a14cd10
commit 15b8e84589

View file

@ -42,6 +42,11 @@ time_from_last_punch, tool_capabilities, dir, damage)
potential_cowards[pname] = nil potential_cowards[pname] = nil
end end
if potential_cowards[hname] and potential_cowards[hname].puncher == pname then
hitter:hud_remove(potential_cowards[hname].hud or 0)
potential_cowards[hname] = nil
end
return false return false
end end
@ -72,28 +77,34 @@ end)
minetest.register_on_dieplayer(function(player, reason) minetest.register_on_dieplayer(function(player, reason)
local pname = player:get_player_name() local pname = player:get_player_name()
if reason.type == "node_damage" then if reason.type ~= "punch" and reason.type ~= "fall" and reason.type ~= "respawn" then
if potential_cowards[pname] then if potential_cowards[pname] then
local last_attacker = minetest.get_player_by_name(potential_cowards[pname].puncher) local hname = potential_cowards[pname].puncher
local last_attacker = minetest.get_player_by_name(hname)
if not last_attacker then return end if not last_attacker then
player:hud_remove(potential_cowards[pname].hud or 0)
potential_cowards[pname] = nil
return
end
potential_cowards[pname].toolcaps.damage_groups.suicide = 1 potential_cowards[pname].toolcaps.damage_groups.suicide = 1
for i = 1, #ctf.registered_on_killedplayer do for i = 1, #ctf.registered_on_killedplayer do
ctf.registered_on_killedplayer[i]( ctf.registered_on_killedplayer[i](
pname, pname,
potential_cowards[pname].puncher, hname,
last_attacker:get_wielded_item(), last_attacker:get_wielded_item(),
potential_cowards[pname].toolcaps potential_cowards[pname].toolcaps
) )
end end
player:hud_remove(potential_cowards[pname].hud or 0) if potential_cowards[hname] and potential_cowards[hname].puncher == pname then
potential_cowards[pname] = nil last_attacker:hud_remove(potential_cowards[hname].hud or 0)
potential_cowards[hname] = nil
end end
elseif reason.type ~= "punch" then
if potential_cowards[pname] then
player:hud_remove(potential_cowards[pname].hud or 0) player:hud_remove(potential_cowards[pname].hud or 0)
potential_cowards[pname] = nil potential_cowards[pname] = nil
end end