Jump to content

Get alive player count in race


Recommended Posts

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

  • Like 1
Link to comment

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

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