Add immunity end on enemy attack, and fix potential crash

This commit is contained in:
rubenwardy 2017-11-07 01:07:49 +00:00
parent 6f49ff4066
commit 1f621760bf
2 changed files with 27 additions and 18 deletions

View file

@ -0,0 +1 @@
ctf

View file

@ -8,6 +8,22 @@ function respawn_immunity.is_immune(player)
return immune_players[player:get_player_name()] return immune_players[player:get_player_name()]
end end
function respawn_immunity.set_immune(player)
immune_serial = immune_serial + 1
immune_players[player:get_player_name()] = immune_serial
minetest.after(1, function()
respawn_immunity.update_effects(player)
end)
-- Set time out
minetest.after(IMMUNE_TIME, function(name, id)
if immune_players[name] == id then
immune_players[name] = nil
respawn_immunity.update_effects(minetest.get_player_by_name(name))
end
end, player:get_player_name(), immune_serial)
end
function respawn_immunity.update_effects(player) function respawn_immunity.update_effects(player)
-- TODO: transparent player when immune -- TODO: transparent player when immune
-- --
@ -18,29 +34,21 @@ function respawn_immunity.update_effects(player)
-- end -- end
end end
function respawn_immunity.set_immune(player) minetest.register_on_punchplayer(function(player, hitter,
immune_serial = immune_serial + 1
immune_players[player:get_player_name()] = immune_serial
minetest.after(1, function()
respawn_immunity.update_effects(player)
end)
-- Set time out
minetest.after(IMMUNE_TIME, function(id)
if immune_players[player:get_player_name()] == id then
immune_players[player:get_player_name()] = nil
respawn_immunity.update_effects(player)
end
end, immune_serial)
end
table.insert(minetest.registered_on_punchplayers, 1, function(player, hitter,
time_from_last_punch, tool_capabilities, dir, damage) time_from_last_punch, tool_capabilities, dir, damage)
if player and respawn_immunity.is_immune(player) then if player and respawn_immunity.is_immune(player) then
minetest.chat_send_player(hitter:get_player_name(), minetest.chat_send_player(hitter:get_player_name(),
player:get_player_name() .. " just respawned or joined, and is immune to attacks!") player:get_player_name() ..
" just respawned or joined, and is immune to attacks!")
return true return true
end end
if hitter and respawn_immunity.is_immune(hitter) then
minetest.chat_send_player(hitter:get_player_name(),
"Your immunity has ended because you attacked a player")
immune_players[hitter:get_player_name()] = nil
respawn_immunity.update_effects(hitter)
end
end) end)
minetest.register_on_joinplayer(respawn_immunity.set_immune) minetest.register_on_joinplayer(respawn_immunity.set_immune)