Jump to content

Recommended Posts

Hello there,

I've almost finished my vehicle shop / saving / control system but i got this error when i log out or reconnect:

ERROR: wangcars/shop_server.lua:16: Couldn't convert userdata argument to JSON, only valid resources can be included for this function.

I've tested and the result is table but toJSON says that it is userdata.

It still saves it to accountdata in toJSON and i can unpack it with fromJSON.

So is this mta bug or what?

Saving function:

addEventHandler("onPlayerLogout", root,
function(account)
	local data = getElementData(source, "wangcars.data")
	if data then
		if account and not isGuestAccount(account) then
			if isElement(wangvehicle[source]) then
				local id = getElementData(wangvehicle[source], "wangcars.id")
				local x, y, z = getElementPosition(wangvehicle[source])
				local rx, ry, rz = getElementRotation(wangvehicle[source])
				data[id][6] = x..", "..y..", "..z..", "..rx..", "..ry..", "..rz
				data[id][8] = getElementHealth(wangvehicle[source])
				setElementData(source, "wangcars.data", data)
				destroyElement(wangvehicle[source])
				wangvehicle[source] = nil
			end
			setAccountData(account, "wangcars.data", toJSON(getElementData(source, "wangcars.data"))) -- error there, but it still saves it
			setElementData(source, "wangcars.data", false)
			triggerClientEvent(source, "wangcars.refreshgrid", source)
		end
	end
end
)

I have almost same function when player quit but no need to post it.

 

I could just ignore this, but it's anoying because it always outputs error in debugscript when somebody disconnects and i'm trying to keep debug clean as possible.

Edited by Miika822
Link to post
1 minute ago, myonlake said:

It means you are trying to save something in JSON that is userdata (elements, usually in this case).

I'm trying to save the player's elementdata (which is table value) (tested). And it saves it. I can load the same account data and use fromJSON and it works fine. But it still gives me that error.

Link to post
1 minute ago, Miika822 said:

I'm trying to save the player's elementdata (which is table value) (tested). And it saves it. I can load the same account data and use fromJSON and it works fine. But it still gives me that error.

It still means there is something of userdata type in there. Give me a snapshot of the contents of the Lua table and I'll point out the problem.

Edited by myonlake
  • Like 1
Link to post
16 minutes ago, myonlake said:

It still means there is something of userdata type in there. Give me a snapshot of the contents of the Lua table and I'll point out the problem.

Oh now I understand what you mean. I have saved the vehicle (element) in table (what I don't even need to)

So can this be the thing causing error?:

table.insert(t, wangvehicle[client])

I am not currently in computer so I can't test.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...