Chaos Posted August 11, 2014 Share Posted August 11, 2014 hey, i have a problem on vehicle shop when i try to buy many cars it will saves but when i restart the resource and buy new car all saved cars will be gone any help ? Server: carsTable = {} addEvent ("onBuyVehicle", true) addEventHandler ("onBuyVehicle", getRootElement(), function(id, cost, name) if (getPlayerMoney (source) >= tonumber(cost)) then table.insert ( carsTable, id ) setAccountData (getPlayerAccount(source), "saveCVehicle",toJSON (carsTable)) outputChatBox ("Press F3 To Spawn your Vehicle.", source, 0, 255, 0, true) takePlayerMoney (source, tonumber (cost)) else outputChatBox ("You don't have enough money!", source, 255, 0, 0, false) end end) Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 You have to add such an event like onPlayerJoin And call the vehicles Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 when i restart resource table will get nil ? Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 I see here that the table gets saved on the account data. As soon as someone logs in, receive that data so it's usable again. ('onPlayerLogin', not 'onPlayerJoin' since then she/he isn't logged it.) Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 ok i did it function onJoin() local data = getAccountData (getPlayerAccount(source), "saveCVehicle") if data then table.insert ( carsTable, data ) end end addEventHandler ("onPlayerLogin", getRootElement(),onJoin) but i got un sorted table like that [ [ "[ [ 471, 471, 534, 582, 543 ] ]", 462 ] ] function test (player) local data = getAccountData (getPlayerAccount(player), "saveCVehicle") if data then outputChatBox (data, player) end end addCommandHandler("getinfo",test) Link to comment
Moderators IIYAMA Posted August 11, 2014 Moderators Share Posted August 11, 2014 fromJSON ...... Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 One question if i bought car and another player also bought car it will save same table that i used it to save my vehicles? Link to comment
Moderators IIYAMA Posted August 11, 2014 Moderators Share Posted August 11, 2014 no it won't. Vehicles are elements and they will be gone after the resource has restarted. You need to get all the vehicle data and save that. Not the vehicle it self. Example: getElementPosition getElementRotation getElementModel getElementHealth getVehicleWheelStates getVehicleColor etc. etc. You really think it was that easy? Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 Ok got it but now i need to make it step by step so take it easy with me Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 i get tired of sorting table Server : addEvent ("carShopCarBuy", true) addEventHandler ("carShopCarBuy", getRootElement(), function(id, cost, name) if (getPlayerMoney (source) >= tonumber(cost)) then table.insert ( carsTable, id ) setAccountData (getPlayerAccount(source), "cu",toJSON (carsTable)) outputChatBox ("Press F3 To Spawn your Vehicle.", source, 0, 255, 0, true) takePlayerMoney (source, tonumber (cost)) else outputChatBox ("You don't have enough money!", source, 255, 0, 0, false) end end) function onJoin(player) local data = getAccountData (getPlayerAccount(player), "cu") if data then local info = fromJSON ( data ) table.insert ( carsTable, info ) triggerClientEvent(player,"movetable",player,info ) end end addCommandHandler("getinfo",onJoin) Client: addEvent ("movetable", true) function shownamesss (info ) for i,v in ipairs (info ) do local carName1 = getVehicleNameFromModel (v) -- local row = guiGridListAddRow (carGridList1) -- guiGridListSetItemText (carGridList1, row, 1, carName1, false, true) outputChatBox(carName1) end end addEventHandler ("movetable", getRootElement(), shownamesss) --------------------------------------------- the problem is when i restart resource and buy new car all saved cars will gone how to save table and load it after resource restarted ? Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 function onJoin() local data = getAccountData (getPlayerAccount(source), "saveCVehicle") if data then table.insert ( carsTable, data ) end end addEventHandler ("onPlayerLogin", getRootElement(),onJoin) function onJoin(lastAccount, currentAccount) local data = getAccountData(currentAccount, "cu") if data then data = fromJSON(data) --[[THIS IS YOUR VEHICLE TABLE]] vehicleTable = data end end addEventHandler ("onPlayerLogin", getRootElement(),onJoin) Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 server: function onLogin(lastAccount, currentAccount) local data = getAccountData(currentAccount, "cu") if data then data = fromJSON(data) --[[THIS IS YOUR VEHICLE TABLE]] carsTable = data triggerClientEvent(source,"movetable",source,data) end end addEventHandler ("onPlayerLogin", getRootElement(),onLogin) client: ------------------------------------------- addEvent ("movetable", true) function shownamesss (data) for i,v in ipairs (data) do local carName1 = getVehicleNameFromModel (v) -- local row = guiGridListAddRow (carGridList1) -- guiGridListSetItemText (carGridList1, row, 1, carName1, false, true) outputChatBox(carName1) end end addEventHandler ("movetable", getRootElement(), shownamesss) --------------------------------------------- vehicles again gone Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 Post your recently script, because you are constantly using another string to save the data under. Link to comment
Max+ Posted August 11, 2014 Share Posted August 11, 2014 - try this , ---Server addEventHandler ("onPlayerLogin",root, function ( ) local Account = getPlayerAccount(source) if (Account) then local nData = getAccountData ( Account, 'cu' ) if ( nData ) then nData = fromJSON(nData ) carsTabel = nData triggerClientEvent ( source, 'movetabel', source, nData ) end end end ) --Client addEvent ('movetable', true) addEventHandler ( 'movetable', root, function ( nData ) for _,v in ipairs (nData) do local carName1 = getVehicleNameFromModel ( v ) local row = guiGridListAddRow (carGridList1) guiGridListSetItemText (carGridList1, row, 1, carName1, false, true) outputChatBox(tostring(carName1)) end end ) Link to comment
Chaos Posted August 11, 2014 Author Share Posted August 11, 2014 carsTable = {} addEvent ("carShopCarBuy", true) addEventHandler ("carShopCarBuy", getRootElement(), function(id, cost, name) if (getPlayerMoney (source) >= tonumber(cost)) then table.insert ( carsTable, id ) setAccountData (getPlayerAccount(source), "cu",toJSON (carsTable)) outputChatBox ("Press F3 To Spawn your Vehicle.", source, 0, 255, 0, true) takePlayerMoney (source, tonumber (cost)) else outputChatBox ("You don't have enough money!", source, 255, 0, 0, false) end end) addEventHandler ("onPlayerLogin",root, function ( ) local Account = getPlayerAccount(source) if (Account) then local nData = getAccountData ( Account, 'cu' ) if ( nData ) then nData = fromJSON(nData ) carsTable = nData triggerClientEvent ( source, 'movetable', source, nData ) end end end ) same and this is the save script and you can see here when i restart the resource and buy vehicle logout and login Link to comment
Anubhav Posted August 12, 2014 Share Posted August 12, 2014 carsTable = {} addEvent ("carShopCarBuy", true) addEventHandler ("carShopCarBuy", getRootElement(), function(id, cost, name) if (getPlayerMoney (source) >= tonumber(cost)) then table.insert ( carsTable[source], id ) setAccountData (getPlayerAccount(source), "cu",toJSON (carsTable[source])) outputChatBox ("Press F3 To Spawn your Vehicle.", source, 0, 255, 0, true) takePlayerMoney (source, tonumber (cost)) else outputChatBox ("You don't have enough money!", source, 255, 0, 0, false) end end) addEventHandler ("onPlayerLogin",root, function ( ) local Account = getPlayerAccount(source) if (Account) then local nData = getAccountData ( Account, 'cu' ) if ( nData ) then nData = fromJSON(nData ) carsTable = nData triggerClientEvent ( source, 'movetable', source, nData ) end end end ) addEvent ('movetable', true) addEventHandler ( 'movetable', root, function ( nData ) for _,v in ipairs (nData) do local carName1 = getVehicleNameFromModel ( v ) local row = guiGridListAddRow (carGridList1) guiGridListSetItemText (carGridList1, row, 1, tostring(carName1), false, true) outputChatBox(tostring(carName1)) end end ) You've to save it for source too. Link to comment
Moderators IIYAMA Posted August 12, 2014 Moderators Share Posted August 12, 2014 Line 10: Check the table data before proceed. local vehicle = carsTable[source] if vehicle then --... end Link to comment
Chaos Posted August 12, 2014 Author Share Posted August 12, 2014 IIYAMA i beg you can you see my pm. Link to comment
Moderators IIYAMA Posted August 13, 2014 Moderators Share Posted August 13, 2014 I don't have time for paid scripting. 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