SimpleNoob Posted February 17, 2016 Posted February 17, 2016 Hello, how i can save all the element data on the players to the account data when they quit and when they login put again all the element data's? i mean, for avoid the saving on every elementData and do it for all once.
bebo1king Posted February 17, 2016 Posted February 17, 2016 Try this Codes for save addEventHandler('onPlayerQuit',root, function() local vAcc = getPlayerAccount(source) if not vAcc or isGuestAccount(vAcc) then return end setAccountData(vAcc,'DataNameSave',getElementData (source,"Data")) -- Get data and save it end) addEventHandler('onPlayerLogin',root, function(_,acc) local v_Data = getAccountData(acc,'DataNameSave') -- Get the saved data if ( v_Data ) then setElementData (source,"Data",v_Data) -- Set Player Data end end )
SimpleNoob Posted February 17, 2016 Author Posted February 17, 2016 but this works to save only one element data for script, exist any method to save all at one time?
Bonus Posted February 17, 2016 Posted February 17, 2016 addEventHandler ( "onPlayerQuit", root, function ( ) local acc = getPlayerAccount ( source ) if acc and not isGuestAccount ( acc ) then local alldata = getAllElementData ( source ) if alldata then for key, value in pairs ( alldata ) do setAccountData ( acc, key, value ) end end end end ) addEventHandler ( "onPlayerLogin", root, function ( _, acc ) local alldata = getAllAccountData ( acc ) if alldata then for key, value in pairs ( alldata ) do setElementData ( source, key, value ) end end end )
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