DarkLink Posted June 27, 2012 Share Posted June 27, 2012 Hi there, I am trying to get a easy and best way to clear all the data, I mean the data I saved using setElementData (on players, teams, objects..) This is for starting a new round on my gamemode, I was using "stopResource" and "startResource" again.. but I think its not a good way to do it. Thanks alot in advance Link to comment
Guest Guest4401 Posted June 27, 2012 Share Posted June 27, 2012 for k,v in pairs(getAllElementData(player)) do removeElementData(player,k) end --"player" should be an element Link to comment
Kenix Posted June 27, 2012 Share Posted June 27, 2012 (edited) addEventHandler( 'onResourceStop', resourceRoot, function( ) for _, pPlayer in ipairs( getElementsByType 'player' ) do for sData, _ in pairs( getAllElementData( pPlayer ) ) do removeElementData( pPlayer, sData ) end end end ) Edited June 27, 2012 by Guest Link to comment
DarkLink Posted June 27, 2012 Author Share Posted June 27, 2012 Thanks guys karthik can I use instead of player something to index everything ? maybe getAllElementData(getRootElement()) ? Thanks. Link to comment
Kenix Posted June 27, 2012 Share Posted June 27, 2012 (edited) Try addEventHandler( 'onResourceStop', resourceRoot, function( ) for sData, _ in pairs( getAllElementData( root ) ) do removeElementData( root, sData ) end end ) Edited June 27, 2012 by Guest Link to comment
Guest Guest4401 Posted June 27, 2012 Share Posted June 27, 2012 for _, sData in ipairs( getAllElementData( pPlayer ) ) do removeElementData( pPlayer, sData ) end Should be pairs because it has a key & a value And the key is supposed to be removed, not value Link to comment
Kenix Posted June 27, 2012 Share Posted June 27, 2012 (edited) Should be pairs because it has a key & a valueAnd the key is supposed to be removed, not value oO lol? getAllElementData return table with ( key( number ) value (string) ) Edited June 27, 2012 by Guest Link to comment
Guest Guest4401 Posted June 27, 2012 Share Posted June 27, 2012 key is number no oO lol? getAllElementData return table with ( key( number ) value (string) ) no, key is string Link to comment
Kenix Posted June 27, 2012 Share Posted June 27, 2012 Ah damn. My bad. Didn't see in first time about key is string on the wiki Link to comment
DarkLink Posted June 27, 2012 Author Share Posted June 27, 2012 Hm I see, and to clear everything.. ? instead of use "player" ? is there something that refers to every type of element? Link to comment
qaisjp Posted June 27, 2012 Share Posted June 27, 2012 code at first file and first line of the resource: local _eKeys = {} local _setElementData = setElementData function setElementData(p,k,...) _setElementData(p,k,...) _eKeys[k] = true end function clearElementData() for _,v in pairs(getElementsByType"player") do for k in pairs(_eKeys) do removeElementData(v,k) end end end must be server side. Link to comment
50p Posted June 27, 2012 Share Posted June 27, 2012 code at first file and first line of the resource: local _eKeys = {} local _setElementData = setElementData function setElementData(p,k,...) _setElementData(p,k,...) _eKeys[k] = true end function clearElementData() for _,v in pairs(getElementsByType"player") do for k in pairs(_eKeys) do removeElementData(v,k) end end end must be server side. This will only remove data that was set by the resource this code is in. Also, author keeps asking about root element. @DarkLink, you can use getElementChildren to get all the elements and then remove their data with removeElementData Link to comment
DarkLink Posted June 27, 2012 Author Share Posted June 27, 2012 code at first file and first line of the resource: local _eKeys = {} local _setElementData = setElementData function setElementData(p,k,...) _setElementData(p,k,...) _eKeys[k] = true end function clearElementData() for _,v in pairs(getElementsByType"player") do for k in pairs(_eKeys) do removeElementData(v,k) end end end must be server side. This will only remove data that was set by the resource this code is in. Also, author keeps asking about root element. @DarkLink, you can use getElementChildren to get all the elements and then remove their data with removeElementData Okay thanks alot mate Link to comment
qaisjp Posted June 27, 2012 Share Posted June 27, 2012 which mate me or 50p or both. Yes 50p, he is doing this for his borderpatrol gamemode which is one resource, if you remove all element data, servers with other resources that use element data alongside BP GM will have problems Link to comment
DarkLink Posted June 27, 2012 Author Share Posted June 27, 2012 both ofc, yes I only want to clear the data of my resource, not others. if I use as root element my resource, its fine right? Link to comment
50p Posted June 27, 2012 Share Posted June 27, 2012 both ofc, yes I only want to clear the data of my resource, not others. if I use as root element my resource, its fine right? In that case, you can get children of your resource and then remove their data, will work if you're changing data of your resource's children (vehicles, objects, markers, etc. created with your resource). If you're changing player's data then you can set player's parent to your resource when they join your server. There are many options. It's up to you which one you pick. Link to comment
DarkLink Posted June 27, 2012 Author Share Posted June 27, 2012 Okay thanks alot again, btw how can I set player's parent resource ? is there some function native ? Link to comment
qaisjp Posted June 28, 2012 Share Posted June 28, 2012 You don't need to set the players parent resource. What kind of crazy idea do you have for that ? Link to comment
qaisjp Posted June 28, 2012 Share Posted June 28, 2012 You don't need to set the players parent resource. What kind of crazy idea do you have for that ? 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