joao2235 Posted September 23, 2019 Share Posted September 23, 2019 When I quit from server my ElementData gived isn't saved. I tried to do this code to save, follow: function SalvarDadosLogout (source) local ObterGalao = getElementData(source, "galao") local conta = getPlayerAccount (source) setAccountData(conta, "galao", ObterGalao) end addEventHandler("onPlayerQuit", root, SalvarDadosLogout) function DarDadosLogin (source) local conta = getPlayerAccount (source) local TemGalao = getAccountData(conta, "galao") setElementData(source, TemGalao) end addEventHandler("onPlayerLogin", root, DarDadosLogin) Link to comment
Furzy Posted September 23, 2019 Share Posted September 23, 2019 function salvardados(conta) if conta then local source = getAccountPlayer(conta) local ObterGalao = getElementData ( source, "galao" ) or 0 setAccountData ( conta, "galao", ObterGalao ) end end function dardados(conta) if not (isGuestAccount (conta)) then if (conta) then local source = getAccountPlayer(conta) local ObterGalao = getAccountData ( conta, "galao" ) or 0 setElementData ( source, "galao", ObterGalao ) end end end addEventHandler("onPlayerLogin", root, function( _, acc ) setTimer(dardados,50,1,acc) end ) function startScript ( res ) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then dardados(acc) end end end end addEventHandler ( "onResourceStart", getRootElement(), startScript ) function stopScript( res ) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then salvardados(acc) end end end end addEventHandler ( "onResourceStop", getRootElement(), stopScript ) function sair ( quitType ) local acc = getPlayerAccount(source) if not (isGuestAccount (acc)) then if acc then salvardados(acc) end end end addEventHandler ( "onPlayerQuit", getRootElement(), sair ) 1 Link to comment
joao2235 Posted September 23, 2019 Author Share Posted September 23, 2019 Thanks, it works! Can you explain what u did ? If you want, can explain in portuguese in private chat. 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