Adding null check to player FindByID?Solved
I need to add a null check to this code, incase it doesn't find a player but don't know how to do it. plz help.

var player = BasePlayer.FindByID(cupboard.OwnerID);​
I haven't tested the code, but I assume this would work:
if (BasePlayer.FindByID(cupboard.OwnerID) == null)
    return;

As you'd probably want to check to see if the player exists before setting the var player.

5ef8090955d35.jpg JamieGB
I haven't tested the code, but I assume this would work:
if (BasePlayer.FindByID(cupboard.OwnerID) == null)
    return;

As you'd probably want to check to see if the player exists before setting the var player.

It would make more sense to set that in a variable, and then check that variable for null before use otherwise you are performing the lookup multiple times.
var player = BasePlayer.FindByID(cupboard.OwnerID);
if (player == null)
    return;​
Locked automatically