From 8ab7886e6ba891b312248e95e5f1515f3074ebb5 Mon Sep 17 00:00:00 2001 From: Beu Date: Thu, 13 Jul 2023 10:00:29 +0200 Subject: [PATCH] Detect when a player change from Player to Spectator --- LastManStanding.Script.txt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/LastManStanding.Script.txt b/LastManStanding.Script.txt index a060271..d245a87 100644 --- a/LastManStanding.Script.txt +++ b/LastManStanding.Script.txt @@ -380,9 +380,17 @@ foreach (Event in PendingEvents) { } } -if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player - Net_TimeBeforeMalus = -1; - MB_StopRound(); +// Detect when a players count changed without having triggered any of Event (when becoming spectator for example) +if (!ThrottleUpdate && Net_PlayersNbAlive != PlayersNbAlive) { + log("Trying to detect why the player count changed"); + foreach (Player in AllPlayers) { + if (Player.User == Null || Player.Score == Null) continue; + if (!AccountIdsOfPlayers.exists(Player.User.WebServicesUserId)) continue; + if (Player.SpawnStatus != CSmPlayer::ESpawnStatus::NotSpawned) continue; + if (IsEliminated(Player.User, Player.Score)) continue; + UpdateCustomRanking(Player.User, True); + ThrottleUpdate = True; + } } if (ThrottleUpdate) { @@ -397,6 +405,11 @@ if (ThrottleUpdate) { } } +if (PlayersNbAlive <= 1 && AccountIdsOfPlayers.count >= 2) { //TODO just respawn in case of 1 player + Net_TimeBeforeMalus = -1; + MB_StopRound(); +} + // Update the map duration setting if (Map_TimeBeforeMalus != S_TimeBeforeMalus || Map_TimeBeforeMalus != S_TimeBeforeNightmare || Map_MalusEveryNSecs != S_MalusEveryNSecs || Map_NextMalusPreparationTime != S_NextMalusPreparationTime || Map_MalusDuration != S_MalusDuration || Map_RoundsPerMap != S_RoundsPerMap) {