Show players how much time there is left until immunity runs out (closes #112)

This commit is contained in:
Zughy 2024-01-13 21:31:52 +01:00
parent ecfdbf1edf
commit aeb08d64d1
2 changed files with 37 additions and 9 deletions

View File

@ -8,6 +8,7 @@ arena_lib.on_celebration("block_league", function(arena, winners)
player:get_meta():set_int("bl_immunity", 1)
panel_lib.get_panel(pl_name, "bl_info_panel"):show()
arena_lib.HUD_hide("broadcast", pl_name)
end
-- se è pareggio, passa una stringa (no one)
@ -27,4 +28,4 @@ arena_lib.on_celebration("block_league", function(arena, winners)
minetest.sound_play("bl_jingle_victory", {to_player = pl_name})
end
end
end)
end)

View File

@ -1,10 +1,13 @@
local S = minetest.get_translator("block_league")
local function countdown() end
local old_textures = {} -- KEY: p_name; VALUE: {textures}
function block_league.start_immunity_countdown(player)
local p_name = player:get_player_name()
local arena = arena_lib.get_arena_by_player(p_name)
local textures = player:get_properties().textures
old_textures[p_name] = player:get_properties().textures
@ -15,13 +18,9 @@ function block_league.start_immunity_countdown(player)
player:set_properties({textures = textures})
-- TODO: immunity countdown HUD
local arena = arena_lib.get_arena_by_player(p_name)
minetest.after(arena.immunity_time, function()
if not player or not arena.players[p_name] or arena.in_celebration then return end
block_league.remove_immunity(player)
end)
countdown(arena, player, arena.immunity_time)
end
@ -32,6 +31,34 @@ function block_league.remove_immunity(player)
if p_meta:get_int("bl_immunity") == 0 or p_meta:get_int("bl_death_delay") == 1 then return end
arena_lib.HUD_hide("broadcast", p_name)
p_meta:set_int("bl_immunity", 0)
player:set_properties({textures = old_textures[p_name]})
end
end
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function countdown(arena, player, seconds_left)
local p_name = player:get_player_name()
arena_lib.HUD_send_msg("broadcast", p_name, S("Immunity off in: @1", seconds_left))
if seconds_left == 0 then
block_league.remove_immunity(player)
else
minetest.after(1, function()
if not arena.players[p_name] or arena.in_celebration then return end
local p_meta = player:get_meta()
if p_meta:get_int("bl_immunity") == 0 or p_meta:get_int("bl_death_delay") == 1 then return end
countdown(arena, player, seconds_left -1)
end)
end
end