Jump to content

Alive players


Blinker.

Recommended Posts

Posted

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.

Posted

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 
  

Posted

thank you both :)

also i have a question is there a way to save a table's data after restarting the resource ? without using toJSON and SQL .. these things.

Posted

JSON is the best method to save data. It doesn't lagg at all. XML will lagg. MTA JSON functions don't work that good. You should download jeffery's json module for lua.

Posted
thank you both :)

also i have a question is there a way to save a table's data after restarting the resource ? without using toJSON and SQL .. these things.

I'm pretty sure you can simply get all the players again when the resource starts.

Posted

@Saml1er i dont know anything about db , JSON ... i tried even to use them, but i found it's so hard to understand + errors

@Gallardo nono the question was for another script. i wanted to save a table with nicknames of players.

Posted
local t = { 
5, 
6, 
ja = "4" , 
ya= "8" 
} 
local str = toJSON ( t ) -- Now we have a json string 
local t2 = fromJSON ( t ) -- Now we convert it back to table 
  
for _, v in pairs ( t2 ) do 
outputChatBox (v ) -- output the values 
end 

Posted

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 ?

Posted

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 

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