Make your last hitter get a kill if you suicide any possible way (#840)
This commit is contained in:
parent
87f7212f43
commit
054e1389c4
1 changed files with 53 additions and 69 deletions
|
@ -15,18 +15,7 @@ ctf.register_on_attack(function(player, hitter,
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local hname = hitter:get_player_name()
|
local hname = hitter:get_player_name()
|
||||||
|
|
||||||
local hp = player:get_hp() - damage
|
if pname == hname then
|
||||||
if hp <= 0 then
|
|
||||||
if potential_cowards[pname] then
|
|
||||||
player:hud_remove(potential_cowards[pname].hud or 0)
|
|
||||||
potential_cowards[pname] = nil
|
|
||||||
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,41 +38,46 @@ ctf.register_on_attack(function(player, hitter,
|
||||||
|
|
||||||
potential_cowards[pname].timer = 0
|
potential_cowards[pname].timer = 0
|
||||||
potential_cowards[pname].puncher = hname
|
potential_cowards[pname].puncher = hname
|
||||||
|
potential_cowards[pname].wielded_item = hitter:get_wielded_item()
|
||||||
potential_cowards[pname].toolcaps = tool_capabilities
|
potential_cowards[pname].toolcaps = tool_capabilities
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_dieplayer(function(player, reason)
|
ctf.register_on_killedplayer(function(victim, killer, _, toolcaps)
|
||||||
local pname = player:get_player_name()
|
if toolcaps.damage_groups.combat_log or toolcaps.damage_groups.suicide then
|
||||||
|
|
||||||
if reason.type == "node_damage" or reason.type == "drown" or reason.type == "fall" then
|
|
||||||
if potential_cowards[pname] then
|
|
||||||
local hname = potential_cowards[pname].puncher
|
|
||||||
local last_attacker = minetest.get_player_by_name(hname)
|
|
||||||
|
|
||||||
if not last_attacker then
|
|
||||||
player:hud_remove(potential_cowards[pname].hud or 0)
|
|
||||||
potential_cowards[pname] = nil
|
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if victim ~= killer and potential_cowards[victim] then -- if player is killed then killer is already awarded
|
||||||
|
local player = minetest.get_player_by_name(victim)
|
||||||
|
if player then
|
||||||
|
player:hud_remove(potential_cowards[victim].hud or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
potential_cowards[victim] = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function handle_leave_or_die(pname, leave)
|
||||||
|
if potential_cowards[pname] then
|
||||||
|
local hname = potential_cowards[pname].puncher
|
||||||
|
|
||||||
|
if leave then
|
||||||
|
potential_cowards[pname].toolcaps.damage_groups.combat_log = 1
|
||||||
|
else
|
||||||
potential_cowards[pname].toolcaps.damage_groups.suicide = 1
|
potential_cowards[pname].toolcaps.damage_groups.suicide = 1
|
||||||
|
end
|
||||||
|
|
||||||
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,
|
||||||
hname,
|
hname,
|
||||||
last_attacker:get_wielded_item(),
|
potential_cowards[pname].wielded_item,
|
||||||
potential_cowards[pname].toolcaps
|
potential_cowards[pname].toolcaps
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
if potential_cowards[hname] and potential_cowards[hname].puncher == pname then
|
|
||||||
last_attacker:hud_remove(potential_cowards[hname].hud or 0)
|
|
||||||
potential_cowards[hname] = nil
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
for victim in pairs(potential_cowards) do
|
for victim in pairs(potential_cowards) do
|
||||||
if potential_cowards[victim].puncher == pname then
|
if potential_cowards[victim].puncher == pname then
|
||||||
local victimobj = minetest.get_player_by_name(victim)
|
local victimobj = minetest.get_player_by_name(victim)
|
||||||
|
@ -93,12 +87,15 @@ minetest.register_on_dieplayer(function(player, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
potential_cowards[victim] = nil
|
potential_cowards[victim] = nil
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player, reason)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
|
handle_leave_or_die(pname, false)
|
||||||
|
|
||||||
if potential_cowards[pname] 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
|
||||||
|
@ -109,22 +106,9 @@ minetest.register_on_leaveplayer(function(player, timeout)
|
||||||
if timeout == true then return end
|
if timeout == true then return end
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
|
handle_leave_or_die(pname, true)
|
||||||
|
|
||||||
if potential_cowards[pname] then
|
if potential_cowards[pname] then
|
||||||
local last_attacker = minetest.get_player_by_name(potential_cowards[pname].puncher)
|
|
||||||
|
|
||||||
if not last_attacker then return end
|
|
||||||
|
|
||||||
potential_cowards[pname].toolcaps.damage_groups.combat_log = 1
|
|
||||||
|
|
||||||
for i = 1, #ctf.registered_on_killedplayer do
|
|
||||||
ctf.registered_on_killedplayer[i](
|
|
||||||
pname,
|
|
||||||
potential_cowards[pname].puncher,
|
|
||||||
last_attacker:get_wielded_item(),
|
|
||||||
potential_cowards[pname].toolcaps
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
local main, match = ctf_stats.player(pname)
|
local main, match = ctf_stats.player(pname)
|
||||||
|
|
||||||
if main and match then
|
if main and match then
|
||||||
|
|
Loading…
Reference in a new issue