FuriouZ Posted March 2, 2014 Share Posted March 2, 2014 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
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 local pCount = 0 for _,player in ipairs (getElementsByType("player")) do if getElementData(player,"Arena") == "Freeroam" then pCount = pCount+1 end end Just a basic example. Link to comment
Wei Posted March 2, 2014 Share Posted March 2, 2014 (edited) 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 March 2, 2014 by Guest Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 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
manawydan Posted March 2, 2014 Share Posted March 2, 2014 try function ContForData(data,value) local n = 0 for k,v in ipairs(getElementsByType("player")) do if getElementData(v,data) == value then n=n+1 end end return n end Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 try function ContForData(data,value) local n = 0 for k,v in ipairs(getElementsByType("player")) do if getElementData(v,data) == value then n=n+1 end end return n end What ? first codes working, but i want add more datas there Link to comment
manawydan Posted March 2, 2014 Share Posted March 2, 2014 you can use my function again Link to comment
manawydan Posted March 2, 2014 Share Posted March 2, 2014 or make one table for data's and use for loop again Link to comment
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 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
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 (edited) 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 March 2, 2014 by Guest Link to comment
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 Can you post the rest of the code and the errors that you receive? Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 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
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 (edited) 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 March 2, 2014 by Guest Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 It needs to close first function somevhere Link to comment
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 I edited the code above. It should work now. Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 Still countPlayersInArena a nil value Link to comment
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 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
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