Add safe check to PlayerStatFromPlayer
Opened this issue · 1 comments
Jettucis commented
Noticed that sometimes there's System.IndexOutOfRangeException: Index was outside the bounds of the array
error in this PlayerStat? PlayerStatFromPlayer(CCSPlayerController? player)
so I'd suggest to add a safe-check.
PlayerStat? PlayerStatFromPlayer(CCSPlayerController? player)
{
if(player == null || !player.IsLegal())
{
return null;
}
int slot = player.Slot;
if (slot < 0 || slot >= playerStats.Length)
{
Console.WriteLine($"Error: {player.PlayerName} slot {slot} is out of bounds. Array length is {playerStats.Length}.");
return null;
}
return playerStats[slot];
}
I would do a PR, but I did modify some other things, so that's a no option
destoer commented
Thanks ill take a look