Skip to content

Commit

Permalink
For now commented GetDefuser logic because it's not working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Jan 28, 2024
1 parent 9701a92 commit f968011
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions InstadefusePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace InstadefusePlugin;
[MinimumApiVersion(147)]
public class InstadefusePlugin : BasePlugin
{
private const string Version = "1.4.1";
private const string Version = "1.4.2";

public override string ModuleName => "Instadefuse Plugin";
public override string ModuleVersion => Version;
Expand Down Expand Up @@ -47,7 +47,9 @@ public override void Load(bool hotReload)
[GameEventHandler]
public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
AttemptInstadefuse();
// TODO: Re-implement once GetDefuser works as expected.
// AttemptInstadefuse();

return HookResult.Continue;
}

Expand Down Expand Up @@ -120,7 +122,8 @@ public HookResult OnInfernoExtinguish(EventInfernoExtinguish @event, GameEventIn

_infernoThreat.Remove(@event.Entityid);

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

return HookResult.Continue;
}
Expand All @@ -132,7 +135,8 @@ public HookResult OnInfernoExpire(EventInfernoExpire @event, GameEventInfo info)

_infernoThreat.Remove(@event.Entityid);

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

return HookResult.Continue;
}
Expand All @@ -147,7 +151,8 @@ public HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventIn
_heThreat--;
}

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

return HookResult.Continue;
}
Expand All @@ -161,8 +166,9 @@ public HookResult OnMolotovDetonate(EventMolotovDetonate @event, GameEventInfo i
{
_molotovThreat--;
}

AttemptInstadefuse();

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

return HookResult.Continue;
}
Expand Down Expand Up @@ -197,13 +203,18 @@ public HookResult OnBombPlanted(EventBombPlanted @event, GameEventInfo info)
public HookResult OnBombBeginDefuse(EventBombBegindefuse @event, GameEventInfo info)
{
Console.WriteLine($"{LogPrefix}OnBombBeginDefuse");

AttemptInstadefuse();

var player = @event.Userid;

if (player != null && player.IsValid && player.PawnIsAlive)
{
AttemptInstadefuse(player);
}

return HookResult.Continue;
}

private void AttemptInstadefuse()
private void AttemptInstadefuse(CCSPlayerController defuser)
{
Console.WriteLine($"{LogPrefix}Attempting instadefuse...");

Expand All @@ -226,6 +237,15 @@ private void AttemptInstadefuse()
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 All @@ -241,14 +261,6 @@ private void AttemptInstadefuse()
return;
}

var defuser = GetDefuser();

if (defuser == null)
{
Console.WriteLine($"{LogPrefix}No defusing player found.");
return;
}

var bombTimeUntilDetonation = plantedBomb.TimerLength - (Server.CurrentTime - _bombPlantedTime);

var defuseLength = plantedBomb.DefuseLength;
Expand Down Expand Up @@ -306,13 +318,16 @@ private static bool TeamHasAlivePlayers(CsTeam team)
{
var players = Utilities.GetPlayers();

if (players.Any())
foreach (var player in players)
{
return players.Any(player => player.IsValid && player.Team == team && player.PawnIsAlive);
if (!player.IsValid) continue;
if (player.Team != team) continue;
if (!player.PawnIsAlive) continue;

return true;
}

Console.WriteLine($"{LogPrefix}No players found!");
throw new Exception("No players found!");
return false;
}

private static CPlantedC4? FindPlantedBomb()
Expand Down

0 comments on commit f968011

Please sign in to comment.