Miika Posted December 30, 2016 Share Posted December 30, 2016 (edited) 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 December 30, 2016 by Miika822 Link to comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 (edited) It means you are trying to save something in JSON that is userdata (elements, usually in this case). Edited December 30, 2016 by myonlake Link to comment
Miika Posted December 30, 2016 Author Share Posted December 30, 2016 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 comment
myonlake Posted December 30, 2016 Share Posted December 30, 2016 (edited) 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 December 30, 2016 by myonlake 1 Link to comment
Miika Posted December 30, 2016 Author Share Posted December 30, 2016 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 comment
Captain Cody Posted December 30, 2016 Share Posted December 30, 2016 (edited) Yes that might be what is causing the issue; if you have a element defined in the table fromJSON will not be able to convert the string back to an element. Edited December 30, 2016 by CodyL 1 Link to comment
Miika Posted December 30, 2016 Author Share Posted December 30, 2016 Yeah, it's the only element, that table contains Have to check it out next time I go to PC again. 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