diff --git a/mod/TTT.Detective/DetectiveManager.cs b/mod/TTT.Detective/DetectiveManager.cs index ed2662f..92bdeda 100644 --- a/mod/TTT.Detective/DetectiveManager.cs +++ b/mod/TTT.Detective/DetectiveManager.cs @@ -18,7 +18,7 @@ public class DetectiveManager(IPlayerService roleService) public void Start(BasePlugin parent) { parent.RegisterListener(() => { foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsValid && player.IsReal()) + .Where(player => player is { IsValid: true, IsBot: false }) .Where(player => (player.Buttons & PlayerButtons.Use) != 0)) OnPlayerUse(player); }); diff --git a/mod/TTT.Logs/LogBehavior.cs b/mod/TTT.Logs/LogBehavior.cs index 248acd1..b3bfa85 100644 --- a/mod/TTT.Logs/LogBehavior.cs +++ b/mod/TTT.Logs/LogBehavior.cs @@ -18,8 +18,7 @@ public class LogBehavior : ILogService, IPluginBehavior { public bool PrintLogs(int round) { if (_logs.ContainsKey(round)) return false; - foreach (var player in Utilities.GetPlayers().Where(plr => plr.IsReal())) - PrintToPlayer(player, round); + foreach (var player in Utilities.GetPlayers()) PrintToPlayer(player, round); PrintToConsole(round); return true; diff --git a/mod/TTT.Logs/LogsListener.cs b/mod/TTT.Logs/LogsListener.cs index 787e454..16ae271 100644 --- a/mod/TTT.Logs/LogsListener.cs +++ b/mod/TTT.Logs/LogsListener.cs @@ -17,8 +17,7 @@ public void Start(BasePlugin plugin) { } public HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info) { var attackedPlayer = @event.Userid; - if (attackedPlayer == null || !attackedPlayer.IsReal()) - return HookResult.Continue; + if (attackedPlayer == null) return HookResult.Continue; var attackedRole = playerService.GetPlayer(attackedPlayer).PlayerRole(); @@ -39,12 +38,11 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { var killedPlayer = @event.Userid; var killer = @event.Attacker; - if (killedPlayer == null || !killedPlayer.IsReal()) - return HookResult.Continue; + if (killedPlayer == null) return HookResult.Continue; var killedRole = playerService.GetPlayer(killedPlayer).PlayerRole(); - if (killer == null || !killer.IsReal()) { + if (killer == null) { logService.AddLog(new DeathAction( new Tuple(killedPlayer, killedRole))); return HookResult.Continue; diff --git a/mod/TTT.Manager/InfoManager.cs b/mod/TTT.Manager/InfoManager.cs index 2afe21e..8a8f849 100644 --- a/mod/TTT.Manager/InfoManager.cs +++ b/mod/TTT.Manager/InfoManager.cs @@ -134,7 +134,8 @@ private HookResult OnPlayerSpectateChange(EventSpecTargetUpdated @event, var player = @event.Userid; var target = new CCSPlayerController(@event.Target); - if (!player.IsReal() || !target.IsReal()) return HookResult.Continue; + if (player == null || !player.IsReal() || !target.IsReal()) + return HookResult.Continue; _spectatorLookAtRole.TryAdd(player, new Tuple(target.PlayerName, diff --git a/mod/TTT.Player/AntiBlockManager.cs b/mod/TTT.Player/AntiBlockManager.cs index c582a36..9cf2f9c 100644 --- a/mod/TTT.Player/AntiBlockManager.cs +++ b/mod/TTT.Player/AntiBlockManager.cs @@ -23,8 +23,6 @@ private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, var player = @event.Userid; - if (!player.IsReal()) return HookResult.Continue; - if (!player.PlayerPawn.IsValid) return HookResult.Continue; var pawn = player.PlayerPawn; diff --git a/mod/TTT.Roles/RoleBehavior.cs b/mod/TTT.Roles/RoleBehavior.cs index 0f5ae4b..3e3d45a 100644 --- a/mod/TTT.Roles/RoleBehavior.cs +++ b/mod/TTT.Roles/RoleBehavior.cs @@ -44,7 +44,6 @@ public void Start(BasePlugin parent) { public void AddRoles() { var eligible = Utilities.GetPlayers() - .Where(player => player.IsReal()) .Where(player => player.Team is not (CsTeam.Spectator or CsTeam.None)) .ToList(); @@ -149,15 +148,10 @@ public HookResult OnRoundStart(EventRoundFreezeEnd @event, GameEventInfo info) { _roundService.SetRoundStatus(RoundStatus.Waiting); foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal() && player.Team != CsTeam.None - || player.Team != CsTeam.Spectator)) { + .Where(player + => player.Team != CsTeam.None && player.Team != CsTeam.Spectator)) { player.RemoveWeapons(); - if (!string.IsNullOrEmpty("weapon_glock")) - player.GiveNamedItem("weapon_glock"); - - if (!string.IsNullOrEmpty(string.Empty)) - player.GiveNamedItem(string.Empty); - + player.GiveNamedItem("weapon_glock"); player.GiveNamedItem("weapon_knife"); service.GetPlayer(player).ModifyKarma(); } @@ -169,8 +163,8 @@ public HookResult public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info) { if (Utilities.GetPlayers() - .Count(player => player.IsReal() && player.Team != CsTeam.None - || player.Team == CsTeam.Spectator) < 3) + .Count(player => player.Team != CsTeam.None + && player.Team != CsTeam.Spectator) < 3) _roundService.ForceEnd(); return HookResult.Continue; @@ -219,10 +213,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { [GameEventHandler] public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { - var players = Utilities.GetPlayers() - .Where(player => player.IsValid) - .Where(player => player.IsReal()) - .ToList(); + var players = Utilities.GetPlayers().ToList(); foreach (var player in players) player.PrintToCenter(GetWinner().FormatStringFullAfter("s has won!")); @@ -250,12 +241,10 @@ public bool IsInnocent(CCSPlayerController player) { } private Role GetWinner() { - return _traitorsLeft == 0 ? Role.Traitor : Role.Innocent; + return _traitorsLeft > 0 ? Role.Traitor : Role.Innocent; } public void SetColor(CCSPlayerController player) { - if (!player.IsReal()) return; - var pawn = player.PlayerPawn.Value; if (pawn == null || !pawn.IsValid) return; @@ -267,8 +256,6 @@ public void SetColor(CCSPlayerController player) { } public void RemoveColor(CCSPlayerController player) { - if (!player.IsReal()) return; - var pawn = player.PlayerPawn.Value; if (pawn == null || !pawn.IsValid) return; @@ -276,7 +263,6 @@ public void RemoveColor(CCSPlayerController player) { pawn.RenderMode = RenderMode_t.kRenderTransColor; pawn.Render = Color.FromArgb(254, 255, 255, 255); - Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender"); } } \ No newline at end of file diff --git a/mod/TTT.Round/Round.cs b/mod/TTT.Round/Round.cs index d577c37..397724d 100644 --- a/mod/TTT.Round/Round.cs +++ b/mod/TTT.Round/Round.cs @@ -23,10 +23,7 @@ public Round(IRoleService roleService, RoundConfig? config, int roundId) { public void Tick() { _graceTime--; - var players = Utilities.GetPlayers() - .Where(player => player.IsValid) - .Where(player => player.IsReal()) - .ToList(); + var players = Utilities.GetPlayers().ToList(); var formattedColor = $""; @@ -42,7 +39,6 @@ public void Tick() { public void Start() { foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal()) .Where(player => !player.PawnIsAlive) .Where(player => player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist)) diff --git a/mod/TTT.Round/RoundBehavior.cs b/mod/TTT.Round/RoundBehavior.cs index 594819e..2a45306 100644 --- a/mod/TTT.Round/RoundBehavior.cs +++ b/mod/TTT.Round/RoundBehavior.cs @@ -75,10 +75,7 @@ public void TickWaiting() { } public void ForceStart() { - foreach (var player in Utilities.GetPlayers() - .Where(player => player.IsReal()) - .Where(player => player.IsReal()) - .ToList()) + foreach (var player in Utilities.GetPlayers().ToList()) player.VoiceFlags = VoiceFlags.Normal; _round!.Start(); ServerExtensions.GetGameRules().RoundTime = 360; @@ -123,7 +120,6 @@ private HookResult OnTeamJoin(CCSPlayerController? executor, CommandInfo info) { if (_roundStatus != RoundStatus.Started) return HookResult.Continue; if (executor == null) return HookResult.Continue; - if (!executor.IsReal()) return HookResult.Continue; if (_roleService.GetRole(executor) != Role.Unassigned) return HookResult.Continue; Server.NextFrame(() => executor.CommitSuicide(false, true)); diff --git a/public/TTT.Formatting/Extensions/ViewExtensions.cs b/public/TTT.Formatting/Extensions/ViewExtensions.cs index 8d17538..b29d970 100644 --- a/public/TTT.Formatting/Extensions/ViewExtensions.cs +++ b/public/TTT.Formatting/Extensions/ViewExtensions.cs @@ -45,7 +45,7 @@ public static IView ToAllCenter(this IView view) { public static IView ToPlayerConsole(this IView view, CCSPlayerController player) { - if (!player.IsReal() || player.IsBot) return view; + if (!player.IsReal(false)) return view; var writer = view.ToWriter(); @@ -56,7 +56,7 @@ public static IView ToPlayerConsole(this IView view, public static IView ToPlayerChat(this IView view, CCSPlayerController player) { - if (!player.IsReal() || player.IsBot) return view; + if (!player.IsReal(false)) return view; var writer = view.ToWriter(); @@ -67,7 +67,7 @@ public static IView public static IView ToPlayerCenter(this IView view, CCSPlayerController player) { - if (!player.IsReal() || player.IsBot) return view; + if (!player.IsReal(false)) return view; var writer = view.ToWriter(); var merged = string.Join('\n', writer.Plain); @@ -79,7 +79,7 @@ public static IView ToPlayerCenter(this IView view, public static IView ToPlayerCenterHtml(this IView view, CCSPlayerController player) { - if (!player.IsReal() || player.IsBot) return view; + if (!player.IsReal(false)) return view; var writer = view.ToWriter(); var merged = string.Join('\n', writer.Panorama); diff --git a/public/TTT.Public/Extensions/PlayerExtensions.cs b/public/TTT.Public/Extensions/PlayerExtensions.cs index 22480b0..f914c31 100644 --- a/public/TTT.Public/Extensions/PlayerExtensions.cs +++ b/public/TTT.Public/Extensions/PlayerExtensions.cs @@ -77,14 +77,15 @@ public static string GetActiveWeaponName(this CCSPlayerController player) { } - public static bool IsReal(this CCSPlayerController player) { + public static bool IsReal(this CCSPlayerController player, bool bot = true) { // Do nothing else before this: // Verifies the handle points to an entity within the global entity list. if (!player.IsValid) return false; if (player.Connected != PlayerConnectedState.PlayerConnected) return false; - if (player.IsBot || player.IsHLTV) return false; + if (player.IsBot) return bot; + if (player.IsHLTV) return false; return true; } diff --git a/public/TTT.Public/Extensions/ScoreboardExtension.cs b/public/TTT.Public/Extensions/ScoreboardExtension.cs index fc85647..ff85fc2 100644 --- a/public/TTT.Public/Extensions/ScoreboardExtension.cs +++ b/public/TTT.Public/Extensions/ScoreboardExtension.cs @@ -8,7 +8,6 @@ namespace TTT.Round; public static class ScoreboardExtension { public static void ModifyScoreBoard(this CCSPlayerController? player) { if (player == null) return; - if (!player.IsReal()) return; var actionService = player.ActionTrackingServices; if (actionService == null) return;