From b2ef8afebded5c5b8176ca115790febc109709eb Mon Sep 17 00:00:00 2001 From: Dollan Date: Mon, 8 Apr 2024 22:05:01 +0200 Subject: [PATCH] bug: does not work --- CS2-Multi-1v1.csproj | 2 +- CS2Multi1v1.cs | 21 +++++++++++++++------ Helper.cs | 5 +++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CS2-Multi-1v1.csproj b/CS2-Multi-1v1.csproj index 954ada0..4fb1001 100644 --- a/CS2-Multi-1v1.csproj +++ b/CS2-Multi-1v1.csproj @@ -10,7 +10,7 @@ - + none runtime compile; build; native; contentfiles; analyzers; buildtransitive diff --git a/CS2Multi1v1.cs b/CS2Multi1v1.cs index 94d9e8d..1421d08 100644 --- a/CS2Multi1v1.cs +++ b/CS2Multi1v1.cs @@ -86,14 +86,23 @@ public HookResult OnPlayerActivate(EventPlayerActivate @event, GameEventInfo inf CCSPlayerController playerController = @event.Userid; _logger?.LogInformation($"Player Activated: {playerController.Connected.ToString()}"); - if (!playerController.IsValid) return HookResult.Continue; - if (_rankedArenas.Where(x => x?._player1?.PlayerController == playerController).FirstOrDefault() != null) return HookResult.Continue; - if (_rankedArenas.Where(x => x?._player2?.PlayerController == playerController).FirstOrDefault() != null) return HookResult.Continue; - playerController.ChangeTeam(CsTeam.Spectator); + if (!playerController.IsValid) return HookResult.Continue; + if (playerController.Connected != PlayerConnectedState.PlayerConnected) return HookResult.Continue; + if (!playerController.Pawn.IsValid) return HookResult.Continue; + if (_rankedArenas.FirstOrDefault(x => x?._player1?.PlayerController == playerController) != null) return HookResult.Continue; + if (_rankedArenas.FirstOrDefault(x => x?._player2?.PlayerController == playerController) != null) return HookResult.Continue; + playerController.ChangeTeam(CsTeam.Spectator); ArenaPlayer arenaPlayer = new ArenaPlayer(playerController); _waitingArenaPlayers.Enqueue(arenaPlayer); + // If all players are in the waiting queue, end the round + if (Helper.GetValidPlayers().Count == _waitingArenaPlayers.Count) + { + Helper.EndRound(); + } + + _logger?.LogInformation($"Player {arenaPlayer.PlayerController.PlayerName} added to waiting queue."); arenaPlayer.PrintToChat($"{ChatColors.Gold}You have been added to the waiting queue."); arenaPlayer.PrintToChat($"{ChatColors.Gold}Type {ChatColors.LightRed}!help{ChatColors.Gold} in chat to see info."); @@ -111,8 +120,8 @@ public HookResult OnPlayerConnect(EventPlayerConnect @event, GameEventInfo info) public HookResult OnRoundPrestart(EventRoundPrestart @event, GameEventInfo info) { - Queue arenaWinners = new Queue(); - Queue arenaLosers = new Queue(); + Queue arenaWinners = new(); + Queue arenaLosers = new(); _logger?.LogInformation("Prestart triggered"); diff --git a/Helper.cs b/Helper.cs index 21aae06..11f13c3 100644 --- a/Helper.cs +++ b/Helper.cs @@ -15,5 +15,10 @@ public static void EndRound() gameRules.TerminateRound(3.0f, RoundEndReason.CTsWin); } + public static List GetValidPlayers() + { + return Utilities.GetPlayers().FindAll(p => p != null && p.IsValid && p.SteamID.ToString().Length == 17 && !string.IsNullOrEmpty(p.IpAddress) && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsBot && !p.IsHLTV); + } } + } \ No newline at end of file