From dcd48cc31b0cb6ba3322770f2f7243204a18d78c Mon Sep 17 00:00:00 2001 From: audiomaster99 <116572799+audiomaster99@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:44:58 +0100 Subject: [PATCH] FixCounter Fixed player counter to work in realtime and display only alive players --- BombsiteAnnouncer.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BombsiteAnnouncer.cs b/BombsiteAnnouncer.cs index feca0c7..bc16661 100644 --- a/BombsiteAnnouncer.cs +++ b/BombsiteAnnouncer.cs @@ -2,6 +2,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Utils; using Microsoft.Extensions.Logging; @@ -57,6 +58,8 @@ public void OnConfigParsed(Config config) } private void OnTick(CCSPlayerController player) { + ctNum = GetCurrentNumPlayers(CsTeam.CounterTerrorist); + ttNum = GetCurrentNumPlayers(CsTeam.Terrorist); if (player.Team == CsTeam.CounterTerrorist) { color = "green"; @@ -77,8 +80,8 @@ private void OnTick(CCSPlayerController player) [GameEventHandler] public HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo info) { - ctNum = GetCurrentNumPlayers(CsTeam.CounterTerrorist); - ttNum = GetCurrentNumPlayers(CsTeam.Terrorist); + var c4list = Utilities.FindAllEntitiesByDesignerName("weapon_c4"); + var c4 = c4list.FirstOrDefault(); var site = new CBombTarget(NativeAPI.GetEntityFromIndex(@event.Site)); _site = ""; bombsite = ""; @@ -114,7 +117,6 @@ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) bombsiteAnnouncer = false; return HookResult.Continue; } - //---- P L U G I N - H E L P E R S ---- static bool IsValid(CCSPlayerController? player) { @@ -124,6 +126,10 @@ static bool IsConnected(CCSPlayerController? player) { return player?.Connected == PlayerConnectedState.PlayerConnected; } + static bool IsAlive(CCSPlayerController player) + { + return player.PawnIsAlive; + } public void ShowAnnouncer() { AddTimer(Config.ShowAnnouncerDelay, () => @@ -138,7 +144,7 @@ public static int GetCurrentNumPlayers(CsTeam? csTeam = null) var players = 0; foreach (var player in Utilities.GetPlayers() - .Where(player => IsValid(player) && IsConnected(player))) + .Where(player => IsAlive(player) && IsValid(player) && IsConnected(player))) { if (csTeam == null || player.Team == csTeam) {