Bean666 Posted April 28, 2015 Share Posted April 28, 2015 guys is there anyway that if u restart a vehicle system that has some cars in it and the cars have colors. is it possible that the car colors save? Link to comment
WhoAmI Posted April 28, 2015 Share Posted April 28, 2015 Of course it is. Just use database (MySQL/SQLite), before resource stops, get all vehicles and save it. After resource starts, load them. Link to comment
yazan Posted April 29, 2015 Share Posted April 29, 2015 Just an example server function o(player) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) if ( vehicle ) then r1,r2,r3,r4 = getVehicleColor ( vehicle ) local accounta = getPlayerAccount ( player ) setAccountData ( accounta, "cl1", r1 ) setAccountData ( accounta, "cl2", r2 ) setAccountData ( accounta, "cl3", r3 ) setAccountData ( accounta, "cl4", r4 ) end end end function f(player) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) if ( vehicle ) then local accounta = getPlayerAccount ( player ) local b1 = (getAccountData ( accounta, "cl1" ) or "N/A") local b2 = (getAccountData ( accounta, "cl2" ) or "N/A") local b3 = (getAccountData ( accounta, "cl3" ) or "N/A") local b4 = (getAccountData ( accounta, "cl4" ) or "N/A") setVehicleColor( vehicle, b1, b2, b3, b4) end end end addEventHandler ("onResourceStart", resourceRoot, function () for _,v in ipairs (getElementsByType ("player")) do bindKey (v, "9", "down", o) bindKey (v, "9", "up", f) end end) Link to comment
Walid Posted April 29, 2015 Share Posted April 29, 2015 Just an exampleserver function o(player) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) if ( vehicle ) then r1,r2,r3,r4 = getVehicleColor ( vehicle ) local accounta = getPlayerAccount ( player ) setAccountData ( accounta, "cl1", r1 ) setAccountData ( accounta, "cl2", r2 ) setAccountData ( accounta, "cl3", r3 ) setAccountData ( accounta, "cl4", r4 ) end end end function f(player) if isPedInVehicle(player) then local vehicle = getPedOccupiedVehicle(player) if ( vehicle ) then local accounta = getPlayerAccount ( player ) local b1 = (getAccountData ( accounta, "cl1" ) or "N/A") local b2 = (getAccountData ( accounta, "cl2" ) or "N/A") local b3 = (getAccountData ( accounta, "cl3" ) or "N/A") local b4 = (getAccountData ( accounta, "cl4" ) or "N/A") setVehicleColor( vehicle, b1, b2, b3, b4) end end end addEventHandler ("onResourceStart", resourceRoot, function () for _,v in ipairs (getElementsByType ("player")) do bindKey (v, "9", "down", o) bindKey (v, "9", "up", f) end end) it's not correct , what can he do if the player have more than two cars they will have the same color because you stored the vehicle color in an account. simply in this case try to use Sqilte and As @WhoAmI said before resource stops, get all vehicles and save it. After resource starts, load them. Example: -- Save -- You can use something like this local r1, g1, b1, r2, g2, b2 = getVehicleColor(theVehicle, true) local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2 -- Sqlite part here -- Load local colorTable = -- From Sqlite local color = split(colorTable, ',') r1 = color[1] g1 = color[2] b1 = color[3] r2 = color[4] g2 = color[5] b2 = color[6] Link to comment
Walid Posted April 29, 2015 Share Posted April 29, 2015 Or use toJSON and fromJSON. Yeh i just gave him something very simple : * Save local r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4 = getVehicleColor( veh, true ) local color = toJSON({r1,g1,b1, r2,g2,b2, r3,g3,b3, r4,g4,b4}) *load local r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4 = unpack( fromJSON( color )) setVehicleColor( veh, r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4 ) 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