diff --git a/InstadefusePlugin.cs b/InstadefusePlugin.cs index b59f6ca..57790f2 100644 --- a/InstadefusePlugin.cs +++ b/InstadefusePlugin.cs @@ -44,15 +44,6 @@ public override void Load(bool hotReload) MessagePrefix = _translator["instadefuse.prefix"]; } - [GameEventHandler] - public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) - { - // TODO: Re-implement once GetDefuser works as expected. - // AttemptInstadefuse(); - - return HookResult.Continue; - } - [GameEventHandler] public HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) { @@ -122,9 +113,6 @@ public HookResult OnInfernoExtinguish(EventInfernoExtinguish @event, GameEventIn _infernoThreat.Remove(@event.Entityid); - // TODO: Re-implement once GetDefuser works as expected. - // AttemptInstadefuse(); - return HookResult.Continue; } @@ -135,9 +123,6 @@ public HookResult OnInfernoExpire(EventInfernoExpire @event, GameEventInfo info) _infernoThreat.Remove(@event.Entityid); - // TODO: Re-implement once GetDefuser works as expected. - // AttemptInstadefuse(); - return HookResult.Continue; } @@ -151,9 +136,6 @@ public HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventIn _heThreat--; } - // TODO: Re-implement once GetDefuser works as expected. - // AttemptInstadefuse(); - return HookResult.Continue; } @@ -167,9 +149,6 @@ public HookResult OnMolotovDetonate(EventMolotovDetonate @event, GameEventInfo i _molotovThreat--; } - // TODO: Re-implement once GetDefuser works as expected. - // AttemptInstadefuse(); - return HookResult.Continue; } @@ -237,15 +216,6 @@ private void AttemptInstadefuse(CCSPlayerController defuser) return; } - // TODO: Implement this once the PlayerPawn values are actually changing. - // var defuser = GetDefuser(); - // - // if (defuser == null) - // { - // Console.WriteLine($"{LogPrefix}No defusing player found."); - // return; - // } - if (TeamHasAlivePlayers(CsTeam.Terrorist)) { Console.WriteLine($"{LogPrefix}Terrorists are still alive"); @@ -279,8 +249,13 @@ private void AttemptInstadefuse(CCSPlayerController defuser) Server.NextFrame(() => { - // We get the planted bomb again as it was sometimes crashing. - var plantedBomb = FindPlantedBomb(); + plantedBomb = FindPlantedBomb(); + + if (plantedBomb == null) + { + Console.WriteLine($"{LogPrefix}Planted bomb is null!"); + return; + } plantedBomb.C4Blow = 1.0f; }); @@ -291,7 +266,13 @@ private void AttemptInstadefuse(CCSPlayerController defuser) Server.NextFrame(() => { // We get the planted bomb again as it was sometimes crashing. - var plantedBomb = FindPlantedBomb(); + plantedBomb = FindPlantedBomb(); + + if (plantedBomb == null) + { + Console.WriteLine($"{LogPrefix}Planted bomb is null!"); + return; + } plantedBomb.DefuseCountDown = 0; @@ -299,27 +280,6 @@ private void AttemptInstadefuse(CCSPlayerController defuser) }); } - private static CCSPlayerController? GetDefuser() - { - var players = Utilities.GetPlayers(); - - foreach (var player in players) - { - if (!player.IsValid) continue; - if (!player.PawnIsAlive) continue; - if (player.Team != CsTeam.CounterTerrorist) continue; - - var playerPawn = player.PlayerPawn.Value; - if (playerPawn == null) continue; - if (!playerPawn.IsValid) continue; - if (!playerPawn.IsDefusing) continue; - - return player; - } - - return null; - } - private static bool TeamHasAlivePlayers(CsTeam team) { var players = Utilities.GetPlayers();