Code:foreach (BasePlayer player in BasePlayer.sleepingPlayerList) { PrintToChat(player.xp.CurrentLevel.ToString()); }What I am doing wrong?Code:NullReferenceException: Object reference not set to an instance of an object
Getting XP level from all sleepers?
Discussion in 'Rust Development' started by Reynostrum, Jul 17, 2016.
-
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.
-
Works for me.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); } -
Wulf Community Admin
I guess that'd work, unless they are sleeping and offline. So that wouldn't handle ALL sleepers.
-
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.
