Sign in to follow this  
joao2235

[HELP] How to save the ElementData ?

Recommended Posts

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)

 

Share this post


Link to post
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 )

 

  • Thanks 1

Share this post


Link to post

Thanks, it works! Can you explain what u did ? If you want, can explain in portuguese in private chat.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.