AlexMiller Posted August 2, 2010 Share Posted August 2, 2010 Hi there. I have a variable containing all upgrades that the modshop is going to put in my car ( "upgrades" ) and I wanted them to be saved in another DB, in only 1 row (like "1001,1002,1003). Is it possible to? Link to comment
50p Posted August 2, 2010 Share Posted August 2, 2010 What type of variable is it? A table? Are you trying to modify my resource or make your own? Because there is a custom event that is triggered by modshop to let you do whatever you want when vehicle is upgraded... It is possible to store the upgrades in 1 line as a string. Link to comment
AlexMiller Posted August 2, 2010 Author Share Posted August 2, 2010 Alright, thanks 50p for answering me. I'm trying to modify your resource a little, just to save the upgrades made by the shop on another DB, where my char datas are saved. Then, to save everything as a string, I just have to do to following?: stringupgrades = tostring( upgrades ) setAccountData(getPlayerAccount(source, "carupgrs",stringupgrades)) EDIT: I tried to, and I got no error during the server run, but by having a look in the char table I can see this where there should be upgrade IDs: table: 03DF45B8 Link to comment
50p Posted August 3, 2010 Share Posted August 3, 2010 If you open "server.lua" and scroll down to line 220, you should find a new event "onVehicleMod". This is triggered when you exit mod shop and your vehicle get modded. So, you can make your own resource and use this event to save upgrades. To get all the upgrades into 1 string, you have to iterate upgrades table and add the id to the string.. Something like: addEventHandler( "onVehicleMod", getRootElement(), function( upgrades ) local str = ""; for i, id in pairs( upgrades ) do str = str .. tostring( id ) .. ","; end str = str:sub( 1, -2 ); -- remove the last comma (,) local player = getVehicleOccupant( source ); setAccountData( getPlayerAccount( player ), "carupgrs", str ); end ) NOTE: You should make a check if player's account is guest account before you set its data. Link to comment
AlexMiller Posted August 3, 2010 Author Share Posted August 3, 2010 Thanks again for the answer. After putting that I finally receive a correct result! Now the problem is, how do you think that I can retrieve only the ID number without comma, and then adding it singularly to a car? Link to comment
AlexMiller Posted August 3, 2010 Author Share Posted August 3, 2010 Yes but... How to add a loop that looks first at the first terms before the comma and adds the upgrade, second at the second one, etc... ? By splitting I still don't know how to continue... EDIT: I managed to, thanks! Link to comment
AlexMiller Posted August 3, 2010 Author Share Posted August 3, 2010 Mmm, i have another problem. If the player has a vehicle tuned with exhausts ( f.e. ID: 1020) and roof ( 1027 ), and goes to the modhsop to get a spoiler ( 1040 ). The table that was 1020,1027 will became 1040 and not 1020,1027 and 1040. What shall I do? Link to comment
50p Posted August 3, 2010 Share Posted August 3, 2010 You can use https://wiki.multitheftauto.com/wiki/GetVehicleUpgrades instead of the upgrades table. Link to comment
AlexMiller Posted August 3, 2010 Author Share Posted August 3, 2010 Alright, it works, but I did this: function( upgrades, colors, paintjob ) local player = getVehicleOccupant( source ) local actupgrds = getAccountData( getPlayerAccount( player ), "carupg") local str = ""; for i, id in pairs( upgrades ) do str = str .. tostring( id ) .. ","; end str = str:sub( 1, -2 ) local str = actupgrds.. "," .. tostring(str) setAccountData( getPlayerAccount( player ), "carupg", str ) setAccountData( getPlayerAccount( player ), "paintjob", paintjob ) end) Thanks 50p 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