Store custom hands for spectators and give them back when leaving

master
Zughy 2022-01-22 17:29:05 +01:00
parent a3a5d9c1e7
commit 091b297cd9
2 changed files with 17 additions and 9 deletions

View File

@ -7,9 +7,10 @@ minetest.register_on_joinplayer(function(player)
end
local p_meta = player:get_meta()
local p_inv = player:get_inventory()
-- nel caso qualcuno si fosse disconnesso da dentro all'editor o fosse crashato il server con qualcuno nell'editor
if player:get_inventory():contains_item("main", "arena_lib:editor_quit") then
if p_inv:contains_item("main", "arena_lib:editor_quit") then
p_meta:set_string("arena_lib_editor.mod", "")
p_meta:set_string("arena_lib_editor.arena", "")
@ -19,12 +20,13 @@ minetest.register_on_joinplayer(function(player)
if minetest.get_modpath("hub_manager") then return end -- se c'è hub_manager, ci pensa quest'ultimo allo svuotamento dell'inventario
player:get_inventory():set_list("main", {})
player:get_inventory():set_list("craft",{})
p_inv:set_list("main", {})
p_inv:set_list("craft", {})
-- se invece era in spettatore
elseif player:get_inventory():get_list("hand") and player:get_inventory():contains_item("hand", "arena_lib:spectate_hand") then
player:get_inventory():set_size("hand", 0)
elseif p_inv:get_list("hand") and p_inv:contains_item("hand", "arena_lib:spectate_hand") then
p_inv:set_stack("hand", 1, nil)
p_inv:set_size("hand", 0)
end
p_meta:set_string("arenalib_infobox_mod", "")

View File

@ -59,9 +59,10 @@ function arena_lib.enter_spectate_mode(p_name, arena)
return end
local arena_ID = arena_lib.get_arenaID_by_player(p_name)
local team_ID = #arena.teams > 1 and 1 or nil
local team_ID = #arena.teams > 1 and 1 or nil
local hand = player:get_inventory():get_list("hand")
players_in_spectate_mode[p_name] = { minigame = mod, arenaID = arena_ID, teamID = team_ID}
players_in_spectate_mode[p_name] = { minigame = mod, arenaID = arena_ID, teamID = team_ID, hand = hand}
arena.spectators[p_name] = true
arena.players_and_spectators[p_name] = true
arena.spectators_amount = arena.spectators_amount + 1
@ -128,9 +129,14 @@ function arena_lib.leave_spectate_mode(p_name, to_join_match)
arena.spectators_amount = arena.spectators_amount -1
local player = minetest.get_player_by_name(p_name)
local p_inv = player:get_inventory()
-- rimuovo mano finta
player:get_inventory():set_size("hand", 0)
-- rimuovo mano finta e reimposto eventuale mano precedente
p_inv:set_list("hand", players_in_spectate_mode[p_name].hand)
if not players_in_spectate_mode[p_name].hand then
p_inv:set_size("hand", 0)
end
-- se il giocatore non è mai entrato in partita, riassegno le proprietà salvate qui
if not arena.past_present_players_inside[p_name] then