ertlflorian1 Posted March 27, 2013 Share Posted March 27, 2013 How i can get the count of alive players? Thats is my attempt players = 0 function checkPlayers () players = 0 for index, veh in ipairs( getElementsByType("player") ) do players = players+1 if getElementHealth(veh) <= 0 then players = players-1 end return players end end setTimer (function () local intplayers = checkPlayers() --if (intplayers == 2) then --destroyElement (obj1) --destroyElement (obj1) outputChatBox (intplayers, root) end, 500,0) Link to comment
codeluaeveryday Posted March 27, 2013 Share Posted March 27, 2013 function getAliveRacers() local count = 0 for v in pairs(getElementsByType('player')) do if getElementData(v, 'state') == 'alive' then local count = count + 1 end end return count end setTimer (function () local intplayers = getAliveRacers() outputChatBox (intplayers, root) end, 500,0) Link to comment
Castillo Posted March 27, 2013 Share Posted March 27, 2013 function getRaceAlivePlayers ( ) local players = 0 for _, player in ipairs ( getElementsByType ( "player" ) ) do if ( getElementData ( player, "state" ) == "alive" ) then players = ( players + 1 ) end end return players end 1 Link to comment
codeluaeveryday Posted March 27, 2013 Share Posted March 27, 2013 Honest mistake: function getAliveRacers() local count = 0 for i, v in ipairs(getElementsByType('player')) do if getElementData(v, 'state') == 'alive' then count = count + 1 end end return count end setTimer (function () local intplayers = getAliveRacers() outputChatBox (intplayers, root) end, 500,0) Edit: Me and castillo pressed it practically at the same time. 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