Initialise players_spectated when the match loads and clear it when it ends

master
Zughy 2022-01-22 13:17:48 +01:00
parent 8807cf56e5
commit 6b22891f59
2 changed files with 38 additions and 13 deletions

View File

@ -45,13 +45,13 @@ function arena_lib.load_arena(mod, arena_ID)
end
end
-- randomizzo gli spawner se non è a team
-- randomizzo gli spawner se non è a squadre
if not arena.teams_enabled then
for i = #shuffled_spawners, 2, -1 do
local j = math.random(i)
shuffled_spawners[i], shuffled_spawners[j] = shuffled_spawners[j], shuffled_spawners[i]
end
-- sennò ordino i giocatori per team
-- sennò ordino i giocatori per squadra
else
local j = 1
for i = 1, #arena.teams do
@ -62,7 +62,7 @@ function arena_lib.load_arena(mod, arena_ID)
end
end
-- e aggiungo eventuali proprietà per ogni team
-- e aggiungo eventuali proprietà per ogni squadra
for k, v in pairs(mod_ref.team_properties) do
arena.teams[i][k] = v
end
@ -265,7 +265,7 @@ function arena_lib.end_arena(mod_ref, mod, arena, winner_name, is_forced)
arena[temp_property] = nil
end
-- e quelle eventuali di team
-- e quelle eventuali di squadra
if arena.teams_enabled then
for i = 1, #arena.teams do
for t_property, _ in pairs(mod_ref.team_properties) do
@ -741,6 +741,11 @@ function operations_before_playing_arena(mod_ref, arena, p_name)
arena.past_present_players[p_name] = true
arena.past_present_players_inside[p_name] = true
-- inizializzo eventuale mod spettatore
if mod_ref.spectate_mode then
arena_lib.add_spectate_container(p_name)
end
local player = minetest.get_player_by_name(p_name)
-- applico eventuale fov
@ -851,6 +856,11 @@ function operations_before_leaving_arena(mod_ref, arena, p_name, reason)
-- se ha partecipato come giocatore
if arena.past_present_players_inside[p_name] then
-- rimuovo eventuale mod spettatore
if mod_ref.spectate_mode then
arena_lib.remove_spectate_container(p_name)
end
-- resetto eventuali texture
if arena.teams_enabled and mod_ref.teams_color_overlay then
player:set_properties({

View File

@ -9,6 +9,29 @@ local spectate_temp_storage = {} -- KEY: player_name, VALUE: {(table)
----------------------------------------------
--------------INTERNAL USE ONLY---------------
----------------------------------------------
-- gestisco qui le tabelle che possono contenere i vari spettatori per ogni
-- giocatore, onde evitare di fare dei controlli ogni volta che si cambia giocatore
-- seguito (che rischierebbero di riempire/svuotare queste tabelle a ogni cambio)
function arena_lib.add_spectate_container(p_name)
players_spectated[p_name] = {}
end
function arena_lib.remove_spectate_container(p_name)
players_spectated[p_name] = nil
end
----------------------------------------------
---------------------CORE---------------------
----------------------------------------------
function arena_lib.enter_spectate_mode(p_name, arena)
local mod = arena_lib.get_mod_by_player(p_name)
@ -140,7 +163,7 @@ end
function arena_lib.is_player_spectated(p_name)
return players_spectated[p_name] ~= nil
return next(players_spectated[p_name])
end
@ -264,14 +287,6 @@ function set_spectator(spectator, p_name, i, prev_spectated)
-- se stava già seguendo qualcuno, lo rimuovo da questo
if prev_spectated then
players_spectated[prev_spectated][sp_name] = nil
if not next(players_spectated[prev_spectated]) then
players_spectated[prev_spectated] = nil
end
end
if not arena_lib.is_player_spectated(p_name) then
players_spectated[p_name] = {}
end
players_spectated[p_name][sp_name] = true