2020-09-16 15:30:58 +00:00
|
|
|
-- Capture The Flag mod: anticoward
|
2020-09-19 21:35:32 +00:00
|
|
|
|
2020-10-31 16:48:47 +00:00
|
|
|
potential_cowards = {}
|
2020-09-19 21:35:32 +00:00
|
|
|
local TIMER_UPDATE_INTERVAL = 2
|
2020-09-20 18:39:34 +00:00
|
|
|
local COMBAT_TIMEOUT_TIME = 20
|
2020-09-19 21:35:32 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
--- Make suicides and combat logs award last puncher with kill
|
|
|
|
--
|
|
|
|
|
|
|
|
minetest.register_on_punchplayer(function(player, hitter,
|
|
|
|
time_from_last_punch, tool_capabilities, dir, damage)
|
|
|
|
if player and hitter then
|
2020-11-21 16:31:36 +00:00
|
|
|
if ctf_respawn_immunity.is_immune(player) or ctf_match.is_in_build_time() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-09-19 21:35:32 +00:00
|
|
|
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
|
|
|
|
player:hud_remove(potential_cowards[pname].hud or 0)
|
|
|
|
potential_cowards[pname] = nil
|
|
|
|
end
|
|
|
|
|
2020-09-19 22:00:57 +00:00
|
|
|
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
|
|
|
|
|
2020-09-19 21:35:32 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if not potential_cowards[pname] then
|
|
|
|
potential_cowards[pname] = {
|
|
|
|
hud = player:hud_add({
|
|
|
|
hud_elem_type = "text",
|
|
|
|
position = {x=1, y=0.3},
|
|
|
|
name = "combat_hud",
|
|
|
|
scale = {x = 2, y = 2},
|
|
|
|
text = "You are in combat. If you leave/suicide your attacker will get the kill",
|
|
|
|
number = 0xff0000,
|
|
|
|
direction = 0,
|
|
|
|
alignment = {x=-1, y=1},
|
|
|
|
size = {x=1},
|
|
|
|
z_index = 100,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
potential_cowards[pname].timer = 0
|
|
|
|
potential_cowards[pname].puncher = hname
|
|
|
|
potential_cowards[pname].toolcaps = tool_capabilities
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_dieplayer(function(player, reason)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
|
2020-10-13 15:51:53 +00:00
|
|
|
if reason.type == "node_damage" or reason.type == "drown" or reason.type == "fall" then
|
2020-09-19 21:35:32 +00:00
|
|
|
if potential_cowards[pname] then
|
2020-09-19 22:00:57 +00:00
|
|
|
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
|
2020-09-19 21:35:32 +00:00
|
|
|
|
2020-09-19 22:00:57 +00:00
|
|
|
return
|
|
|
|
end
|
2020-09-19 21:35:32 +00:00
|
|
|
|
|
|
|
potential_cowards[pname].toolcaps.damage_groups.suicide = 1
|
|
|
|
|
|
|
|
for i = 1, #ctf.registered_on_killedplayer do
|
|
|
|
ctf.registered_on_killedplayer[i](
|
|
|
|
pname,
|
2020-09-19 22:00:57 +00:00
|
|
|
hname,
|
2020-09-19 21:35:32 +00:00
|
|
|
last_attacker:get_wielded_item(),
|
|
|
|
potential_cowards[pname].toolcaps
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-09-19 22:00:57 +00:00
|
|
|
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
|
|
|
|
|
2020-10-19 02:52:20 +00:00
|
|
|
if potential_cowards[pname] then
|
|
|
|
player:hud_remove(potential_cowards[pname].hud or 0)
|
|
|
|
potential_cowards[pname] = nil
|
|
|
|
end
|
2020-09-20 16:04:02 +00:00
|
|
|
else
|
|
|
|
for victim in pairs(potential_cowards) do
|
|
|
|
if potential_cowards[victim].puncher == pname then
|
|
|
|
local victimobj = minetest.get_player_by_name(victim)
|
|
|
|
|
|
|
|
if victimobj then
|
|
|
|
victimobj:hud_remove(potential_cowards[victim].hud or 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
potential_cowards[victim] = nil
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2020-09-19 21:35:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2020-09-20 16:04:02 +00:00
|
|
|
minetest.register_on_leaveplayer(function(player, timeout)
|
|
|
|
if timeout == true then return end
|
2020-09-19 21:35:32 +00:00
|
|
|
local pname = player:get_player_name()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
potential_cowards[pname] = nil
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
local globtimer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
globtimer = globtimer + dtime
|
|
|
|
|
|
|
|
if globtimer >= TIMER_UPDATE_INTERVAL then
|
|
|
|
for k in pairs(potential_cowards) do
|
|
|
|
potential_cowards[k].timer = potential_cowards[k].timer + globtimer
|
|
|
|
|
|
|
|
if potential_cowards[k].timer >= COMBAT_TIMEOUT_TIME then
|
2020-09-20 16:04:02 +00:00
|
|
|
local player = minetest.get_player_by_name(k)
|
2020-09-19 21:35:32 +00:00
|
|
|
|
|
|
|
if player then
|
|
|
|
player:hud_remove(potential_cowards[k].hud or 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
potential_cowards[k] = nil
|
2021-02-09 00:03:03 +00:00
|
|
|
kill_assist.clear_assists(k)
|
2020-09-19 21:35:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
globtimer = 0
|
|
|
|
end
|
|
|
|
end)
|
2020-11-22 22:06:25 +00:00
|
|
|
|
|
|
|
ctf_match.register_on_new_match(function()
|
|
|
|
potential_cowards = {}
|
|
|
|
end)
|
|
|
|
|
|
|
|
ctf.register_on_new_game(function()
|
|
|
|
potential_cowards = {}
|
|
|
|
end)
|