Jump to content

Clearing Data (Element Data)


DarkLink

Recommended Posts

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
  
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 by Guest
Link to comment

Try

addEventHandler( 'onResourceStop', resourceRoot, 
    function( ) 
        for sData, _ in pairs( getAllElementData( root ) ) do 
            removeElementData( root, sData ) 
         end 
    end 
) 

Edited by Guest
Link to comment
Guest Guest4401
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
Should be pairs because it has a key & a value

And the key is supposed to be removed, not value

oO lol? getAllElementData return table with ( key( number ) value (string) )

Edited by Guest
Link to comment

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

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

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