Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
bug: does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
dollannn committed Apr 8, 2024
1 parent f096943 commit b2ef8af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CS2-Multi-1v1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.203">
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.205">
<PrivateAssets>none</PrivateAssets>
<ExcludeAssets>runtime</ExcludeAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
21 changes: 15 additions & 6 deletions CS2Multi1v1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -111,8 +120,8 @@ public HookResult OnPlayerConnect(EventPlayerConnect @event, GameEventInfo info)

public HookResult OnRoundPrestart(EventRoundPrestart @event, GameEventInfo info)
{
Queue<ArenaPlayer> arenaWinners = new Queue<ArenaPlayer>();
Queue<ArenaPlayer> arenaLosers = new Queue<ArenaPlayer>();
Queue<ArenaPlayer> arenaWinners = new();
Queue<ArenaPlayer> arenaLosers = new();

_logger?.LogInformation("Prestart triggered");

Expand Down
5 changes: 5 additions & 0 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public static void EndRound()
gameRules.TerminateRound(3.0f, RoundEndReason.CTsWin);

}
public static List<CCSPlayerController> 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);
}
}

}

0 comments on commit b2ef8af

Please sign in to comment.