WolfPire Posted April 27, 2013 Share Posted April 27, 2013 Hi there, guys! I'm now creating a personal garage where the players will be able to save their vehicles, with upgrades, paintjobs, health, etc... But i'm having problems with the "fromJSON" function which delivers me a "nil" value when i use it. Here's some part of the code... Thanks for the help in advance! Client -- This will load the vehicles that are sent from server, here's the problem --| --| --| --v addEvent("addToGrid", true) addEventHandler("addToGrid", root, function(vehs) outputDebugString(vehs) removeEventHandler("onClientGUIDoubleClick", GarageGL, onDClick, false) destroyElement(GarageGL) GarageGL = false GarageGL = guiCreateGridList(10, 45, 290, 140, false, GarageW) local GarageC = guiGridListAddColumn( GarageGL, "Vehicle Name", 0.45 ) local GarageCTwo = guiGridListAddColumn( GarageGL, "Model", 0.35 ) vehsta = fromJSON(vehs) for name, array in pairs(vehsta) do if not (name == "1") then local row = guiGridListAddRow ( GarageGL ) guiGridListSetItemText ( GarageGL, row, GarageC, name, false, false ) guiGridListSetItemText ( GarageGL, row, GarageCTwo, array[2].." ("..getVehicleNameFromModel(array[2])..")", false, false ) end end addEventHandler("onClientGUIDoubleClick", GarageGL, onDClick, false) end ) Server -- Triggered event to add vehicles, "vname" fromes from an edit-box text "guiGetText(GarageED)" --| --| --| --v addEvent("sendVehicle", true) addEventHandler("sendVehicle",root, function(vname) acc = getPlayerAccount(source) if acc then veh = getPedOccupiedVehicle(source) if getAccountData(acc, "player.garage") == false then local vehs = {} local vmodel = getElementModel(veh) local vu = getVehicleUpgrades(veh) local vhp = getElementHealth(veh) local vpj = getVehiclePaintjob(veh) local r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 = getVehicleColor ( veh, true ) vehs[vname] = {vu, vmodel, vhp, vpj, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4} local vehst = toJSON ( vehs ) setAccountData(acc, "player.garage", vehst) outputChatBox("* There wasn't any data of garage, so we created one. Still, Vehicle Saved!", source, 0, 255, 0) local vehs = getAccountData(acc, "player.garage") triggerClientEvent(source, "addToGrid", source, vehs) else local vehs = getAccountData(acc, "player.garage") local vehs = fromJSON( vehs ) local vmodel = getElementModel(veh) local vu = getVehicleUpgrades(veh) local vhp = getElementHealth(veh) local vpj = getVehiclePaintjob(veh) local r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 = getVehicleColor ( veh, true ) vehs[vname] = {vu, vmodel, vhp, vpj, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4} local vehst = toJSON ( vehs ) setAccountData(acc, "player.garage", vehst) outputChatBox("* Vehicle '"..vname.."' Saved!", source, 0, 255, 0) triggerClientEvent(source, "addToGrid", source, vehst) end else outputChatBox("*ERROR: Player's not logged in.", source, 255, 0, 0) end end ) -- Problem starts from here... As you can see this event will be triggered when the player presses "F3" --| --| --| --v addEvent("getVehicles", true) addEventHandler("getVehicles", root, function() acc = getPlayerAccount(source) if acc then local vehs = getAccountData(acc, "player.garage") if vehs then outputDebugString("Passed send", 0) triggerClientEvent(source, "addToGrid", source, vehs) end end end ) ERRORS - White: "outputDebugString("Passed send", 0)", not a]n error. - Green: "vehs" without using fromJSON (string obviously) - Red: "vehs" after using fromJSON ("nil" value? .___.) Link to comment
Castillo Posted April 28, 2013 Share Posted April 28, 2013 Account data has a limit, so if your JSON string is too long, it'll cut part of it, which will break it and won't be recognized as a JSON string by fromJSON. Link to comment
WolfPire Posted April 28, 2013 Author Share Posted April 28, 2013 Account data has a limit, so if your JSON string is too long, it'll cut part of it, which will break it and won't be recognized as a JSON string by fromJSON. My strings will be longer and longer, more sub-tables will be added on each vehicle add. Is there any way to by-pass this or make a way through it?? >w< EDIT: Please tell me i wont have to fragment it ._. *braces for impact* Actually not the case... It will keep getting bigger and bigger... Geez... This might get real big actually. EDIT 2: Found this: https://forum.multitheftauto.com/viewtop ... 91&t=51152 EDIT 3: AAAAAND... Doesn't work. 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