Skip to content

Commit

Permalink
Minor updates to InstadefusePlugin.cs, also removed some commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Sep 2, 2024
1 parent 32bdee7 commit 9495273
Showing 1 changed file with 14 additions and 54 deletions.
68 changes: 14 additions & 54 deletions InstadefusePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -151,9 +136,6 @@ public HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventIn
_heThreat--;
}

// TODO: Re-implement once GetDefuser works as expected.
// AttemptInstadefuse();

return HookResult.Continue;
}

Expand All @@ -167,9 +149,6 @@ public HookResult OnMolotovDetonate(EventMolotovDetonate @event, GameEventInfo i
_molotovThreat--;
}

// TODO: Re-implement once GetDefuser works as expected.
// AttemptInstadefuse();

return HookResult.Continue;
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
});
Expand All @@ -291,35 +266,20 @@ 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;

Server.PrintToChatAll(MessagePrefix + _translator["instadefuse.successful", defuser.PlayerName, $"{Math.Abs(bombTimeUntilDetonation):n3}"]);
});
}

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();
Expand Down

0 comments on commit 9495273

Please sign in to comment.