Jump to content

Curently Members - Help


Annas

Recommended Posts

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 
); 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...