Jump to content

[HELP] getOnlinePlayers


ViRuZGamiing

Recommended Posts

So you want more names in a line?

local charLimit = 50 -- maximum charachters in a line 
  
addCommandHandler ( "online",  
    function () 
        local line = {} 
        local currLength = 0 
        for i, v in ipairs ( getElementsByType ( "player" ) ) do 
            local name = getPlayerName ( v ) 
            if currLength + #name > charLimit then 
                outputChatBox ( table.concat ( line, ", " ) ) 
                line = {} 
                currLength = 0 
            end 
            table.insert ( line, name ) 
            currLength = currLength + #name 
        end 
    end ) 

Link to comment
  
function getOnlinePlayers() 
  return getElementsByType("player") 
end 
  
function listOnlinePlayers(player) 
  local players = getOnlinePlayers() 
  local playerNames = { } 
  for i=1,#players do 
    table.insert(playerNames,getPlayerName(players[i])) 
  end 
  local text = table.concat(playerNames,", ") -- Separate each player with comma 
  outputChatBox(text,getRootElement()) 
end 

Edited by Guest
Link to comment

I've tested

addCommandHandler ( "online", 
    function () 
        for i, v in ipairs ( getElementsByType ( "player" ) ) do 
            outputChatBox ( getPlayerName ( v ) ) 
        end 
    end ) 

but i'm currently alone on a LAN Server what if i'm with 2 or more how would it be displayed?

1 Name a line? All behind eachother with just a space in between?

greetz viruz

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...