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
|
|
|
|
|
2021-02-13 22:17:05 +00:00
|
|
|
local old_can_attack = ctf.can_attack
|
|
|
|
function ctf.can_attack(player, hitter, ...)
|
2019-04-12 09:52:32 +00:00
|
|
|
if not player or not hitter then
|
2021-02-13 22:17:05 +00:00
|
|
|
return
|
2019-04-12 09:52:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local hname = hitter:get_player_name()
|
|
|
|
|
2021-02-13 22:17:05 +00:00
|
|
|
if ctf_respawn_immunity.is_immune(player) then
|
2021-03-29 21:00:46 +00:00
|
|
|
hud_event.new(hname, {
|
|
|
|
name = "ctf_respawn_immunity:hit",
|
|
|
|
color = 0xEE8822,
|
|
|
|
value = pname .. " has respawn immunity!",
|
|
|
|
})
|
2021-02-13 22:17:05 +00:00
|
|
|
return false
|
|
|
|
end
|
2017-11-07 01:07:49 +00:00
|
|
|
|
2021-02-13 22:17:05 +00:00
|
|
|
if ctf_respawn_immunity.is_immune(hitter) then
|
2021-03-29 21:00:46 +00:00
|
|
|
hud_event.new(hname, {
|
|
|
|
name = "ctf_respawn_immunity:end",
|
|
|
|
color = 0xFF8C00,
|
|
|
|
value = "Your immunity has ended!",
|
|
|
|
})
|
2021-02-13 22:17:05 +00:00
|
|
|
immune_players[hname] = nil
|
|
|
|
ctf_respawn_immunity.update_effects(hitter)
|
2017-11-07 01:07:49 +00:00
|
|
|
end
|
2021-02-13 22:17:05 +00:00
|
|
|
|
|
|
|
return old_can_attack(player, hitter, ...)
|
|
|
|
end
|
2017-11-07 00:32:35 +00:00
|
|
|
|
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)
|