Skip to content

Commit

Permalink
Do valid check before equality
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Nov 1, 2024
1 parent a031f51 commit c5370fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public bool TryRemoveWarden(bool isPass = false) {
var stats = API.Gangs?.Services.GetService<IPlayerStatManager>();
if (stats != null) {
var wrapper = new PlayerWrapper(Warden);
// Task.Run(async () => await updateWardenDeathStats(wrapper));
Task.Run(async () => await updateWardenDeathStats(wrapper));
}
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info) {
if (player == null || !player.IsValid) return HookResult.Continue;
var isWarden = ((IWardenService)this).IsWarden(ev.Userid);
if (API.Gangs != null) {
if (ev.Attacker != null && ev.Attacker != player && ev.Attacker.IsValid
if (ev.Attacker != null && ev.Attacker.IsValid && ev.Attacker != player
&& isWarden) {
var wrapper = new PlayerWrapper(ev.Attacker);
Task.Run(async () => await incrementWardenKills(wrapper));
Expand All @@ -311,8 +311,7 @@ public HookResult OnDeath(EventPlayerDeath ev, GameEventInfo info) {
// If the guard is the warden, update all guards' stats
// If the guard is not the warden, only update the warden's stats
if (guard.SteamID == player.SteamID != isWarden) continue;
Task.Run(
async () => { await updateGuardDeathStats(wrapper, isWarden); });
Task.Run(async () => await updateGuardDeathStats(wrapper, isWarden));
}
}

Expand Down Expand Up @@ -356,6 +355,8 @@ private async Task
// The guard let the warden die
stat.WardenDeathsAsGuard++;
}

await stats.SetForPlayer(player, WardenStat.STAT_ID, stat);
}

[GameEventHandler]
Expand Down

0 comments on commit c5370fb

Please sign in to comment.