Chlorek Posted November 7, 2011 Share Posted November 7, 2011 Hi people. I made userpanel script with saving car mods, and it (I don't know why) doesn't work I don't know does not work saving or loading mods list. My source: function savecar1() local car2s = getElementData(source, "car1D") local upgrades1 = getVehicleUpgrades(car2s) --maybe problem is here? local color1, color2, color3, color4 = getVehicleColor ( car2s ) ------------------------------------------------------------------------- setAccountData (getPlayerAccount (source), "clroleplay-upgr1", upgrades1) setAccountData (getPlayerAccount (source), "clroleplay-col1", color1) setAccountData (getPlayerAccount (source), "clroleplay-col2", color2) setAccountData (getPlayerAccount (source), "clroleplay-col3", color3) setAccountData (getPlayerAccount (source), "clroleplay-col4", color4) ------------------------------------------------------------------------- outputChatBox("Vehicle #1 Saved!", source, 255, 255, 0) end addEventHandler ("savecar1", getRootElement(), savecar1) And my loading function: function spawncar1() local car2destroy = getElementData(source, "car1D") destroyElement (car2destroy) local x,y,z = getElementPosition(source) x = x + 5 local carID1 = getAccountData (getPlayerAccount (source), "clroleplay-car1ID") if(tostring(carID1) == "false" or tostring(carID1) == "" or tostring(carID1) == nil)then outputChatBox("This slot is empty!", source, 255, 255, 0) else local car1 = createVehicle(tonumber(carID1),x,y,z) setElementData (source, "car1D", car1) local color1 = getAccountData (getPlayerAccount (source), "clroleplay-col1") local color2 = getAccountData (getPlayerAccount (source), "clroleplay-col2") local color3 = getAccountData (getPlayerAccount (source), "clroleplay-col3") local color4 = getAccountData (getPlayerAccount (source), "clroleplay-col4") local upgrades1 = nil local upgrades1 = {} local upgrades1 = getAccountData (getPlayerAccount (source), "clroleplay-upgr1") local car2save = getElementData(source, "car1D") setVehicleColor( car1, color1, color2, color3, color4 ) for i,v in ipairs (upgrades1) do addVehicleUpgrade (car1, v) end end end addEventHandler ("spawncar1", getRootElement(), spawncar1) I think it's simple error but I can't find a way to fix that. It's one of the oldest my scripts but I never found answer what's wrong Link to comment
Castillo Posted November 7, 2011 Share Posted November 7, 2011 getVehicleUpgrades returns a table, if I'm right, you can't save a table in account data. Link to comment
Charlie_Jefferson Posted November 7, 2011 Share Posted November 7, 2011 Returns Returns a table of all the upgrades on each slot of a vehicle, which may be empty, or false if a valid vehicle is not passed. That's what the wiki says. Link to comment
Chlorek Posted November 7, 2011 Author Share Posted November 7, 2011 So, what do you prefere to use instead of saving in account data? Link to comment
12p Posted November 7, 2011 Share Posted November 7, 2011 Prefer? Most of the advanced scripters prefer SQL to account data (not me). I use accounts because I always thought it's easier than SQL (and still think so). Link to comment
Chlorek Posted November 7, 2011 Author Share Posted November 7, 2011 Yea, I saw a lot of scripts with use SQL but it's not the easiest method. I'll use that but just I want to know is there any other, safe method. Link to comment
12p Posted November 7, 2011 Share Posted November 7, 2011 XML is another method, as far as I know. Link to comment
Chlorek Posted November 7, 2011 Author Share Posted November 7, 2011 Oh saving to XML files isn't (for me) too good method. I think the most usable is SQL. Right, thanx for help ;] Link to comment
Castillo Posted November 7, 2011 Share Posted November 7, 2011 You can save each upgrade in a different account data name. Link to comment
Chlorek Posted November 7, 2011 Author Share Posted November 7, 2011 Of course, it's method too but that is too much work. ;] Link to comment
12p Posted November 7, 2011 Share Posted November 7, 2011 It isn't, man. Just some more lines. Much work means about 4 hours working for one part of a whole gamemode, that's much work. This? Nope. Link to comment
Chlorek Posted November 7, 2011 Author Share Posted November 7, 2011 Some more lines... hmmm, if I want to save that in SQL db it's same work. I'll make both methods then I'll check what's simpler and how it works. Link to comment
SDK Posted November 7, 2011 Share Posted November 7, 2011 Try https://wiki.multitheftauto.com/wiki/ToJSON / fromJSON. You can use it to convert the table into a string and store it. Afterwards, load the string and use fromJSON to convert it back to a table. function savecar1() local car2s = getElementData(source, "car1D") local upgrades1 = toJSON(getVehicleUpgrades(car2s)) local color1, color2, color3, color4 = getVehicleColor ( car2s ) ------------------------------------------------------------------------- setAccountData (getPlayerAccount (source), "clroleplay-upgr1", upgrades1) setAccountData (getPlayerAccount (source), "clroleplay-col1", color1) setAccountData (getPlayerAccount (source), "clroleplay-col2", color2) setAccountData (getPlayerAccount (source), "clroleplay-col3", color3) setAccountData (getPlayerAccount (source), "clroleplay-col4", color4) ------------------------------------------------------------------------- outputChatBox("Vehicle #1 Saved!", source, 255, 255, 0) end addEventHandler ("savecar1", getRootElement(), savecar1) function spawncar1() local car2destroy = getElementData(source, "car1D") destroyElement (car2destroy) local x,y,z = getElementPosition(source) x = x + 5 local carID1 = getAccountData (getPlayerAccount (source), "clroleplay-car1ID") if(tostring(carID1) == "false" or tostring(carID1) == "" or tostring(carID1) == nil)then outputChatBox("This slot is empty!", source, 255, 255, 0) else local car1 = createVehicle(tonumber(carID1),x,y,z) setElementData (source, "car1D", car1) local color1 = getAccountData (getPlayerAccount (source), "clroleplay-col1") local color2 = getAccountData (getPlayerAccount (source), "clroleplay-col2") local color3 = getAccountData (getPlayerAccount (source), "clroleplay-col3") local color4 = getAccountData (getPlayerAccount (source), "clroleplay-col4") --local upgrades1 = nil -- these two lines aren't needed --local upgrades1 = {} local upgrades1 = fromJSON(getAccountData (getPlayerAccount (source), "clroleplay-upgr1")) local car2save = getElementData(source, "car1D") setVehicleColor( car1, color1, color2, color3, color4 ) for i,v in ipairs (upgrades1) do addVehicleUpgrade (car1, v) end end end addEventHandler ("spawncar1", getRootElement(), spawncar1) Link to comment
Chlorek Posted November 8, 2011 Author Share Posted November 8, 2011 Yeah SDK, really good idea, I didn't know about this function be4 :[ Tnx a lot, it's really usable! 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