Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
fix: better controller checking
Browse files Browse the repository at this point in the history
  • Loading branch information
dollannn committed Apr 10, 2024
1 parent 96b48eb commit d0e0781
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public static float DistanceTo(Vector a, Vector b)
{
return (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2) + Math.Pow(a.Z - b.Z, 2));
}
public static bool IsPlayerValid(CCSPlayerController? p)
{
return p != null && p.IsValid && (p.SteamID.ToString().Length == 17 || (p.SteamID == 0 && p.IsBot)) && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsHLTV;
}
}

}
9 changes: 5 additions & 4 deletions Models/Arena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ public ArenaResult GetArenaResult()
return new ArenaResult(ArenaResultType.Empty, null, null);
}

private bool isPValid(ArenaPlayer? player)
{
return player != null && player.PlayerController.IsValid && player.PlayerController.Connected == PlayerConnectedState.PlayerConnected && player.PlayerController.Pawn.IsValid;
}

private bool anyPValid()
{
return isPValid(_player1) || isPValid(_player2);
}

private bool isPValid(ArenaPlayer? p)
{
return Helper.IsPlayerValid(p?.PlayerController);
}
}
3 changes: 2 additions & 1 deletion Models/ArenaPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;

Expand All @@ -21,7 +22,7 @@ public void ResetPlayerWeapons(RoundType roundType)
{
string knifeName = EnumUtils.GetEnumMemberAttributeValue(CsItem.Knife) ?? "";

if (PlayerController?.Pawn?.Value?.IsValid == null || PlayerController.Pawn!.Value!.IsValid == false) return;
if (!Helper.IsPlayerValid(PlayerController)) return;

// Remove default (spawn) weapons
foreach (CHandle<CBasePlayerWeapon> weapon in PlayerController!.Pawn!.Value!.WeaponServices!.MyWeapons)
Expand Down

0 comments on commit d0e0781

Please sign in to comment.