When eliminated by a player, automatically spectate them (if spectate mode is enabled) | Bugfix: set the correct team ID of a player when forced to spectate them

This commit is contained in:
Zughy 2023-10-21 15:05:46 +02:00
parent eb1914513f
commit c9baec1d15
3 changed files with 15 additions and 5 deletions

View File

@ -504,7 +504,7 @@ function arena_lib.remove_player_from_arena(p_name, reason, xc_name)
-- se è stato eliminato e c'è la spettatore, non va rimosso, bensì solo spostato in spettatore
if reason == 1 and mod_ref.spectate_mode and arena.players_amount > 0 then
eliminate_player(mod, arena, p_name, xc_name)
arena_lib.enter_spectate_mode(p_name, arena)
arena_lib.enter_spectate_mode(p_name, arena, xc_name)
-- sennò procedo a rimuoverlo normalmente
else

View File

@ -170,7 +170,7 @@ minetest.register_on_respawnplayer(function(player)
if not arena_lib.is_player_in_arena(p_name) then return end
if arena_lib.is_player_spectating(p_name) then
if arena_lib.is_player_spectating(p_name) then -- lɜ spettatorɜ non dovrebbero proprio morire, ma in caso...
arena_lib.find_and_spectate_player(p_name)
else

View File

@ -74,7 +74,7 @@ end
-- entering / leaving
----------------------------
function arena_lib.enter_spectate_mode(p_name, arena)
function arena_lib.enter_spectate_mode(p_name, arena, xc_name)
local mod = arena_lib.get_mod_by_player(p_name)
local arena_ID = arena_lib.get_arenaID_by_player(p_name)
local team_ID = #arena.teams > 1 and 1 or nil
@ -139,7 +139,11 @@ function arena_lib.enter_spectate_mode(p_name, arena)
minetest.chat_send_player(p_name, minetest.colorize("#cfc6b8", curr_spectators))
-- inizia a seguire
if xc_name and minetest.get_player_by_name(xc_name) then
arena_lib.spectate_target(mod, arena, p_name, "player", xc_name)
else
arena_lib.find_and_spectate_player(p_name)
end
override_hotbar(player, mod, arena)
return true
@ -499,7 +503,12 @@ end
function arena_lib.spectate_target(mod, arena, sp_name, type, t_name)
if type == "player" then
if arena.players_amount == 0 or not players_spectated[t_name]then return end
if arena.players_amount == 0 or not players_spectated[t_name] then return end
-- se ci son le squadre, assegna l'ID della squadra
if arena.teams_enabled then
players_in_spectate_mode[sp_name].teamID = arena.players[t_name].teamID
end
elseif type == "entity" then
if arena.spectate_entities_amount == 0 or not entities_spectated[mod][arena.name][t_name] then return end
elseif type == "area" then
@ -682,3 +691,4 @@ function override_hotbar(player, mod, arena)
player:hud_set_hotbar_itemcount(#tools)
player:get_inventory():set_list("main", tools)
end