Jump to content

Alive players


Blinker.

Recommended Posts

Hello ,

what's the easier and best way to get alive players in a team

well i'm using onRaceStateChanging to increase the number of players and onPlayerWasted to decrease the number of players

but i get many bugs ... when the player changes his nick and many others.

Thanks in advance.

Link to comment

Nono. isPedDead will also get waiting players so it's useless.

  
local function getRaceAlivePlayers () 
    local theTable = { } 
    local players =  getElementsByType("player") 
    for i=1, #players do 
  local v = players[i] 
      if  getElementData (v,"state") == "alive" then 
        theTable[#theTable+1]=v 
      end 
    end 
  
    return theTable 
end 
  

Link to comment

well and how will it save the data ?

i tried that :

  
 addCommandHandler("ins", 
 function (_,_,name) 
 t = {} 
 table.insert(t,name) 
  str = toJSON ( t ) 
  
 end) 
 function output() 
  
local t2 = fromJSON ( str )  -- Now we convert it back to table 
for _, v in pairs ( t2 ) do 
  
outputChatBox (v ) -- output the values 
end 
end 
addCommandHandler("out",output) 
  
  

when i do /ins Blinker , and then /out , it shows Blinker in chat box , but when i restart the resource and do out , i get nothing.

Thanks.

EDIT: i think i misunderstood , is this function used to save the data or ?

Link to comment

You need to use a save function such as account data or db or xml.

You can't save the table itself, for that you need to convert it to string so that you can save it.

toJSON -- convert the table to string 

fromJSON -- convert the string back to table 

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