2019-06-25 13:24:57 +00:00
|
|
|
ctf_respawn_immunity = {}
|
2017-11-07 00:32:35 +00:00
|
|
|
|
2020-05-10 17:34:59 +00:00
|
|
|
local IMMUNE_TIME = 5
|
2017-11-07 00:32:35 +00:00
|
|
|
local immune_serial = 0
|
|
|
|
local immune_players = {}
|
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
function ctf_respawn_immunity.is_immune(player)
|
2017-11-07 00:32:35 +00:00
|
|
|
return immune_players[player:get_player_name()]
|
|
|
|
end
|
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
function ctf_respawn_immunity.set_immune(player)
|
2017-11-07 00:32:35 +00:00
|
|
|
immune_serial = immune_serial + 1
|
|
|
|
immune_players[player:get_player_name()] = immune_serial
|
|
|
|
minetest.after(1, function()
|
2019-06-25 13:24:57 +00:00
|
|
|
ctf_respawn_immunity.update_effects(player)
|
2017-11-07 00:32:35 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Set time out
|
2017-11-07 01:07:49 +00:00
|
|
|
minetest.after(IMMUNE_TIME, function(name, id)
|
|
|
|
if immune_players[name] == id then
|
|
|
|
immune_players[name] = nil
|
2019-06-25 13:24:57 +00:00
|
|
|
ctf_respawn_immunity.update_effects(minetest.get_player_by_name(name))
|
2017-11-07 00:32:35 +00:00
|
|
|
end
|
2017-11-07 01:07:49 +00:00
|
|
|
end, player:get_player_name(), immune_serial)
|
2017-11-07 00:32:35 +00:00
|
|
|
end
|
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
function ctf_respawn_immunity.update_effects(player)
|
2017-11-07 01:07:49 +00:00
|
|
|
-- TODO: transparent player when immune
|
|
|
|
--
|
|
|
|
-- if immune_players[player:get_player_name()] then
|
|
|
|
-- player:set_texture_mod("[multiply:#1f1")
|
|
|
|
-- else
|
|
|
|
-- player:set_texture_mod(nil)
|
|
|
|
-- end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_punchplayer(function(player, hitter,
|
2017-11-07 00:32:35 +00:00
|
|
|
time_from_last_punch, tool_capabilities, dir, damage)
|
2019-04-12 09:52:32 +00:00
|
|
|
if not player or not hitter then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local hname = hitter:get_player_name()
|
2019-06-25 13:24:57 +00:00
|
|
|
local pteam = ctf.player(pname).team
|
|
|
|
local hteam = ctf.player(hname).team
|
2019-04-12 09:52:32 +00:00
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
if player and ctf_respawn_immunity.is_immune(player) and pteam ~= hteam then
|
|
|
|
minetest.chat_send_player(hname, minetest.colorize("#EE8822", pname ..
|
|
|
|
" just respawned or joined," .. " and is immune to attacks!"))
|
2017-11-07 00:32:35 +00:00
|
|
|
return true
|
|
|
|
end
|
2017-11-07 01:07:49 +00:00
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
if hitter and ctf_respawn_immunity.is_immune(hitter) then
|
2019-04-12 09:52:32 +00:00
|
|
|
minetest.chat_send_player(hname, minetest.colorize("#FF8C00",
|
2018-04-06 13:04:56 +00:00
|
|
|
"Your immunity has ended because you attacked a player"))
|
2019-04-12 09:52:32 +00:00
|
|
|
immune_players[hname] = nil
|
2019-06-25 13:24:57 +00:00
|
|
|
ctf_respawn_immunity.update_effects(hitter)
|
2017-11-07 01:07:49 +00:00
|
|
|
end
|
2017-11-07 00:32:35 +00:00
|
|
|
end)
|
|
|
|
|
2019-06-25 13:24:57 +00:00
|
|
|
minetest.register_on_joinplayer(ctf_respawn_immunity.set_immune)
|
|
|
|
minetest.register_on_respawnplayer(ctf_respawn_immunity.set_immune)
|