I am trying to get a list of all players currently on the server. I have had a look through the reference manual but I couldn’t see anything that did what I needed it to do. Basically, I am trying to do a similar thing to what the Lambda menu does in its ‘Online Players’ section.
This is what I have:
function GetPlayers()
local players = {}
for i = 0, 31 do
if NetworkIsPlayerActive(i) then
table.insert(players, i)
end
end
return players
end
This is where I am calling the function:
local players = GetPlayers()
for i = 0, 31 do
--If any player was selected:
if WarMenu.Button(players[i]) then
--Do Something here:
end
end
When I join the server and look at this section of the menu, it generates 32 empty slots with no player names, also I am the only person joining meaning that it should only create 1 slot.
local players = GetPlayers()
for _, i in ipairs(players) do
--If any player was selected:
if WarMenu.Button(players[i]) then
--Do Something here:
end
end
Thanks for the response. That worked in the way that it only detected the one player which was me. The question now is, how to get it to display the player’s name?
Also, on another note, could you explain the difference in the for loop that I had and the one you provided?
local players = GetPlayers()
for _, i in ipairs(players) do
local pnames = GetPlayerName(i)
--If any player was selected:
if WarMenu.Button(pnames) then
--Do Something here:
end
end