Annas Posted February 13, 2016 Posted February 13, 2016 Hello, i wanna something like (Get Currently Online members in my server by a command.) /players, then it will be output : Online Members: NUMBERofONLINEmembers Help me and thx.
Captain Cody Posted February 13, 2016 Posted February 13, 2016 What do you mean by members? Admins, moderators, other, all of the above?
tosfera Posted February 13, 2016 Posted February 13, 2016 first of all, create a command with addCommandHandler like so; addCommandHandler ( "players", function ( thePlayer ) -- logic here end ); After that, initialize a new variable called; onlinePlayers or something like that. addCommandHandler ( "players", function ( thePlayer ) local onlinePlayers = 0; -- more logic here end ); After that, use a loop ( ipairs ) and getElementsByType to get all the players and increase the count of the users; addCommandHandler ( "players", function ( thePlayer ) local onlinePlayers = 0; for i, p in ipairs ( getElementsByType ( "player" ) ) do onlinePlayers = onlinePlayers + 1; end end ); Last but not least, output it to the player; addCommandHandler ( "players", function ( thePlayer ) local onlinePlayers = 0; for i, p in ipairs ( getElementsByType ( "player" ) ) do onlinePlayers = onlinePlayers + 1; end outputChatBox ( "Online members: ".. onlinePlayers, thePlayer ); end );
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now