Jump to content

[Help] setElementData


Citryon25

Recommended Posts

First of all, sorry for bad English. I am creating a script and I used the getElementData function to get data stored in the user account and then the setElementData function to get the information through the getElementData on the client but the script has the following error in debugging:

 

Bad argument @ setElementData [Expect element at argument 1, got nil]

 

SCRIPT:  [SERVER-SIDE]

 
function setarDados_Entrar(source)
local acc = getPlayerAccount(source)
local habl = getAccountData(acc, "hablt")
local ficha = getAccountData(acc, "fichacriminal") 
setElementData(source, "hblt", habl)--In that error line
setElementData(source, "fich", ficha) -- In that error line
end

function setarDados_Iniciar()
local acc = getPlayerAccount(player)
local habl = getAccountData(acc, "hablt")
local ficha = getAccountData(acc, "fichacriminal") 
setElementData(player, "hblt", habl)--In that error line
setElementData(player, "fich", ficha)--In that error line
end


function setarDados_Mudar(player)
local acc = getPlayerAccount(player)
local habl = getAccountData(acc, "hablt")
local ficha = getAccountData(acc, "fichacriminal")
setElementData(player, "hblt", habl)--In that error line
setElementData(player, "fich", ficha)--In that error line
end
addEventHandler("onPlayerLogin", getRootElement(), setarDados_Entrar)
addEventHandler("onResourceStart", root, setarDados_Iniciar)
addEventHandler("onAccountDataChange", root, setarDados_Mudar)

 

Link to comment
  • Moderators

Try this:


function setarDados_Entrar( _,acc )
	local habl = getAccountData(acc, "hablt")
	local ficha = getAccountData(acc, "fichacriminal") 
	setElementData(source, "hblt", habl)
	setElementData(source, "fich", ficha)
end

function setarDados_Iniciar()
	for i,p in pairs( getElementsByType("player") ) do
		local acc = getPlayerAccount(p)
		if not isGuestAccount(acc) then
			local habl = getAccountData(acc, "hablt")
			local ficha = getAccountData(acc, "fichacriminal") 
			setElementData(p, "hblt", habl)
			setElementData(p, "fich", ficha)
		end
	end
end


function setarDados_Mudar( acc )
	local p = getAccountPlayer( acc )
	if p then
		local habl = getAccountData(acc, "hablt")
		local ficha = getAccountData(acc, "fichacriminal")
		setElementData(p, "hblt", habl)
		setElementData(p, "fich", ficha)
	end
end

addEventHandler("onPlayerLogin", root, setarDados_Entrar)
addEventHandler("onResourceStart", resourceRoot, setarDados_Iniciar)
addEventHandler("onAccountDataChange", root, setarDados_Mudar)

Update the element-data always (and not the account data). Just update the account data when the player exits the server, the account and when the resource stops. So by doing this, you will no longer need the event "onAccountDataChange".

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