From fb875dea67ceb23f5f64cc9b48511a39b9ccaf87 Mon Sep 17 00:00:00 2001 From: Mesharsky Date: Sun, 27 Oct 2024 01:30:12 +0200 Subject: [PATCH] Version release: 3.0 Feat: Added incorrect spawn check, to teleport players into right spawn if detected. Feat: Added new method to check for both HalfTime and Overtime --- Events/Events.cs | 34 +++++++++++++++++++++++++++------- Helpers/Helpers.cs | 22 +--------------------- Mesharsky_TeamBalance.cs | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Events/Events.cs b/Events/Events.cs index dfea380..ea6e930 100644 --- a/Events/Events.cs +++ b/Events/Events.cs @@ -10,14 +10,39 @@ namespace Mesharsky_TeamBalance; public partial class Mesharsky_TeamBalance { - private ConVar mp_warmuptime = ConVar.Find("mp_warmuptime")!; - private ConVar mp_round_restart_delay = ConVar.Find("mp_round_restart_delay")!; + private readonly ConVar mp_warmuptime = ConVar.Find("mp_warmuptime")!; + private readonly ConVar mp_round_restart_delay = ConVar.Find("mp_round_restart_delay")!; public void Initialize_Events() { Event_PlayerDisconnect(); } + [GameEventHandler] + public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) + { + if (IsWarmup()) + return HookResult.Continue; + + var player = @event.Userid; + + if (player == null || !player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected) + return HookResult.Continue; + + if (!player.PawnIsAlive) + return HookResult.Continue; + + AddTimer(0.5f, () => + { + if (IsInWrongSpawn(player)) + { + TeleportPlayerToSpawn(player); + } + }); + + return HookResult.Continue; + } + [GameEventHandler] public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { @@ -45,11 +70,6 @@ public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) PrintToChatAllMsg("teams.balance.not.needed"); } - AddTimer(5.0f, () => - { - CorrectPlayerSpawns(); - }); - if (!IsWarmup()) return HookResult.Continue; diff --git a/Helpers/Helpers.cs b/Helpers/Helpers.cs index f08f0d3..f91e679 100644 --- a/Helpers/Helpers.cs +++ b/Helpers/Helpers.cs @@ -26,28 +26,8 @@ public void FindAndSetSpawns() { ctSpawns = Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist").ToList(); ttSpawns = Utilities.FindAllEntitiesByDesignerName("info_player_terrorist").ToList(); - } - - private void CorrectPlayerSpawns() - { - var allPlayers = Utilities.GetPlayers(); - - if (allPlayers.Count == 0) - { - PrintDebugMessage("No players found for spawn correction."); - return; - } - foreach (var player in allPlayers) - { - if (player.IsBot || !player.PawnIsAlive) - continue; - - if (IsInWrongSpawn(player)) - { - TeleportPlayerToSpawn(player); - } - } + PrintDebugMessage($"[TeamBalance] CT Spawns: {ctSpawns.Count} -- Terrorist Spawns: {ttSpawns.Count}"); } private bool IsInWrongSpawn(CCSPlayerController player) diff --git a/Mesharsky_TeamBalance.cs b/Mesharsky_TeamBalance.cs index 8ed56fd..82808ce 100644 --- a/Mesharsky_TeamBalance.cs +++ b/Mesharsky_TeamBalance.cs @@ -6,7 +6,7 @@ namespace Mesharsky_TeamBalance; public partial class Mesharsky_TeamBalance : BasePlugin { public override string ModuleName => "Mesharsky Team Balance"; - public override string ModuleVersion => "2.2.0"; + public override string ModuleVersion => "3.0.0"; public override string ModuleAuthor => "Mesharsky"; public override void Load(bool hotReload)