Drakath Posted February 2, 2014 Author Share Posted February 2, 2014 It worked, but when I upgraded again, I lose the old upgrades. I tried this: addEvent( "modShop_playerLeaveModShop", true ) addEventHandler( "modShop_playerLeaveModShop", getRootElement( ), function( vehicle, itemsCost, upgrades, colors, paintjob, shopName ) local pMoney = getPlayerMoney( source ) local account = getPlayerAccount(source) if pMoney >= itemsCost and account then modTheVehicle( vehicle, upgrades, colors, paintjob, shopName ) takePlayerMoney( source, itemsCost ) triggerClientEvent( source, "modShop_moddingConfirmed", source ) local data = getAccountData (getPlayerAccount(source), "cu") local calculatedData = fromJSON ( data ) local myTable = {} for i, ups in ipairs (upgrades) do table.insert ( myTable, ups ) table.insert ( myTable, calculatedData ) end setAccountData (account, "cu",toJSON (myTable)) else outputChatBox( "#FF0000Inufficient founds! #00FF00Your pocket shows $"..tostring( getPlayerMoney( source ) )..".#FFFFFF Uninstall some upgrades.", source, 0,0,0,true) end end ) But it didn't work. Between, what does 'ups' stand for? Link to comment
Moderators IIYAMA Posted February 2, 2014 Moderators Share Posted February 2, 2014 ups The data inside the table upgrades. Try something like this: (not tested) local mergeUpgrades = function (myTable,upgrades) if type(upgrades)== "table" and #upgrades > 0 then for i=1,#upgrades do local result = true local upgrade = upgrades[i] for j=1,#myTable do if myTable[j]== upgrade then result = false break end end if result then myTable[#myTable+1]= upgrade end end end return myTable end addEvent( "modShop_playerLeaveModShop", true ) addEventHandler( "modShop_playerLeaveModShop", getRootElement( ), function( vehicle, itemsCost, upgrades, colors, paintjob, shopName ) local pMoney = getPlayerMoney( source ) local account = getPlayerAccount(source) if pMoney >= itemsCost and account then modTheVehicle( vehicle, upgrades, colors, paintjob, shopName ) takePlayerMoney( source, itemsCost ) triggerClientEvent( source, "modShop_moddingConfirmed", source ) local data = getAccountData (getPlayerAccount(source), "cu") local myTable = mergeUpgrades(data and fromJSON ( data ) or {},upgrades) setAccountData (account, "cu",toJSON (myTable)) else outputChatBox( "#FF0000Inufficient founds! #00FF00Your pocket shows $"..tostring( getPlayerMoney( source ) )..".#FFFFFF Uninstall some upgrades.", source, 0,0,0,true) end end) Link to comment
Drakath Posted February 2, 2014 Author Share Posted February 2, 2014 Seems like it worked. Thank you all for helping Link to comment
Moderators IIYAMA Posted February 2, 2014 Moderators Share Posted February 2, 2014 np. 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