Jump to content

Count Players with elementData


FuriouZ

Recommended Posts

Hey!

My question is how i can count players like countPlayersInTeam , but i want count all players who have same data

Hard to explain this :/

for example

How i can count all players who's data is this ?

  
setElementData(source, "Arena", "Freeroam") 
  

Link to comment
function countInTeam() 
    count = 0 
    for _, player in ipairs(getElementsByType("player")) do 
        if (getElementData(player, "Arena") == "Freeroam") then 
            count = count + 1 
        end 
    end 
    return count 
end 

EDIT Cheez was first

Edited by Guest
Link to comment

Thanks both of you ! :)

edit:

But how i can count in another too widhout creating new function ?

tried something, but it is worng

function countPlayers() 
    countFreeroamPlayers = 0 
    countStuntagePlayers = 0 
    for _, player in ipairs(getElementsByType("player")) do 
        if (getElementData(player, "Arena") == "Freeroam") then 
            countFreeroamPlayers = countFreeroamPlayers + 1 
        elseif (getElementData(player, "Arena") == "Stuntage") then 
            countStuntagePlayers = countStuntagePlayers + 1 
        end 
    end 
    return countFreeroamPlayers, countStuntagePlayers 
end 

Link to comment
  
contPlayersInArena(arenaName) 
local pCount = 0 
for _,player in ipairs (getElementsByType("player")) do 
    if getElementData(player,"Arena") == arenaName then 
        pCount = pCount+1 
    end 
    return pCount 
end 
local freeroamCount = countPlayersInArena("Freeroam") 
outputChatBox(tostring(freeroamCount),root) 
  

Link to comment
  
contPlayersInArena(arenaName) 
local pCount = 0 
for _,player in ipairs (getElementsByType("player")) do 
    if getElementData(player,"Arena") == arenaName then 
        pCount = pCount+1 
    end 
    return pCount 
end 
local freeroamCount = countPlayersInArena("Freeroam") 
outputChatBox(tostring(freeroamCount),root) 
  

countPlayersInArena a nil value

guiSetText(label_freeroamPlayers, "Online: "..countPlayersInArena("Freeroam")) 
--Another way still 
guiSetText(label_freeroamPlayers, "Online: "..freeroamCount) 
  

Edited by Guest
Link to comment
setTimer( 
    function() 
        guiSetText(label_totalPlayers, #getElementsByType("player").." players online") 
        guiSetText(label_freeroamPlayers, "Online: "..countPlayersInArena("Freeroam")) 
        guiSetText(label_currentArena, ""..getElementData(localPlayer, "Arena"))     
        guiSetText(label_playerName, getPlayerName(localPlayer))             
        guiSetText(label_playerMoney, convertNumber(getPlayerMoney (localPlayer)).." $")             
    end 
    , 100, 0 
) 
-- 
-- 
-- 
contPlayersInArena(arenaName) 
local playerCount = 0 
for _,player in ipairs (getElementsByType("player")) do 
    if getElementData(player,"Arena") == arenaName then 
        playerCount = playerCount+1 
    end 
    return playerCount 
end 
local freeroamCount = countPlayersInArena("Freeroam") 
outputChatBox(tostring(freeroamCount),root) 
  
  

 

tryed many ways but still says nil value freeroamCount or countPlayersInArena

guiSetText(label_freeroamPlayers, "Online: "..countPlayersInArena("Freeroam")) 
--Another way still 
guiSetText(label_freeroamPlayers, "Online: "..freeroamCount) 
  

Link to comment

You're updating the labels too much. Every 5-10 seconds should be fine.

  
contPlayersInArena = function(arenaName) 
local playerCount = 0 
for _,player in ipairs (getElementsByType("player")) do 
    if getElementData(player,"Arena") == arenaName then 
        playerCount = playerCount+1 
    end 
end 
    return playerCount 
end 
setTimer(function() 
    guiSetText(label_totalPlayers,#getElementsByType("player").." players online") 
    guiSetText(label_freeroamPlayers,"Online: "..tostring(countPlayersInArena("Freeroam"))) 
    guiSetText(label_currentArena,getElementData(localPlayer,"Arena")) 
    guiSetText(label_playerName,getPlayerName(localPlayer)) 
    guiSetText(label_playerMoney,"$"..convertNumber(getPlayerMoney(localPlayer))) 
end,5000,0) 
  

Edited by Guest
Link to comment
  
countPlayersInArena = function(arenaName) 
local playerCount = 0 
for _,player in ipairs (getElementsByType("player")) do 
    if getElementData(player,"Arena") == arenaName then 
        playerCount = playerCount+1 
    end 
end 
    return playerCount 
end 
setTimer(function() 
    guiSetText(label_totalPlayers,#getElementsByType("player").." players online") 
    guiSetText(label_freeroamPlayers,"Online: "..tostring(countPlayersInArena("Freeroam"))) 
    guiSetText(label_currentArena,getElementData(localPlayer,"Arena")) 
    guiSetText(label_playerName,getPlayerName(localPlayer)) 
    guiSetText(label_playerMoney,"$"..convertNumber(getPlayerMoney(localPlayer))) 
end,5000,0) 
  

There was a typo.

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