1. Code:
    foreach (BasePlayer player in BasePlayer.sleepingPlayerList)
                {
                        PrintToChat(player.xp.CurrentLevel.ToString());
                }
    Code:
    NullReferenceException: Object reference not set to an instance of an object
    What I am doing wrong?
     
  2. Wulf

    Wulf Community Admin

    They're not really a player when they are offline, they're just a sleeper entity as far as I know. You'd likely have to lookup the "Agent" for their XP and get it via that.
     
  3. Code:
         for(int i = 0; i < BasePlayer.sleepingPlayerList.Count; i++)
                {
                    var player = BasePlayer.sleepingPlayerList[i];
                    if (player == null || player.IsConnected()) continue;
                    var xp = player?.xp?.CurrentLevel ?? 0f;
                    Puts(player.displayName + " is level: " + xp);
                }
    Works for me.
     
  4. Wulf

    Wulf Community Admin

    I guess that'd work, unless they are sleeping and offline. So that wouldn't handle ALL sleepers. ;)
     
  5. No, it works for offline players. That's the reason I pasted it, I'm sure of it because I've been using it to see who the highest level is. The only way you can't get XP as far as I know is if the player is dead and disconnected. The sleeper still seems to contain the info, and is in fact a BasePlayer, at least asf ar as I've been able to tell.

    EDIT: If you were referring to the continue, it checks if the player IS connected and skips them, as that was handled in the activeplayerlist, which I did not paste.