Blinker. Posted December 30, 2014 Share Posted December 30, 2014 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
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 I think; https://wiki.multitheftauto.com/wiki/Ge ... yersInTeam Link to comment
Saml1er Posted December 30, 2014 Share Posted December 30, 2014 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
Blinker. Posted December 30, 2014 Author Share Posted December 30, 2014 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. Link to comment
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 I suggest exporting to an XML then else you'll get to many element data's. Link to comment
Blinker. Posted December 30, 2014 Author Share Posted December 30, 2014 okay mate , thanks a lot Link to comment
Saml1er Posted December 31, 2014 Share Posted December 31, 2014 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. Link to comment
Gallardo9944 Posted January 1, 2015 Share Posted January 1, 2015 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. Link to comment
Blinker. Posted January 2, 2015 Author Share Posted January 2, 2015 @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. Link to comment
Saml1er Posted January 2, 2015 Share Posted January 2, 2015 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 Link to comment
Blinker. Posted January 2, 2015 Author Share Posted January 2, 2015 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
TAPL Posted January 2, 2015 Share Posted January 2, 2015 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
Blinker. Posted January 2, 2015 Author Share Posted January 2, 2015 It works Thanks a lot both of you 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