Jump to content

WHATS WRONG IN THIS SCRIPT? SAVING CARS/INTERIORS/DIMENSIONS


HeavyMetal

Recommended Posts

im making a garage system for my server and now im on the part where i have to save the cars, it upgrades, color, interiors, and dimension, and something is wrong with the code and i cant find out what is it, when it works it always spawn in dimension 0, the setElementInterior command is working but it cords dont, and i dont know why the server is saying im trying to concatenate dimension that is a "nill" value, and a lot of other errors, this is not my code, im only changing it because im not experienced enought to make a thing like this by myself, i marked the parts where i changed it. (original code by: Blakmorg)

function saveVehicles() 
    executeSQLDropTable ( "vehiclesaverb" ) 
    --i added the interior and dimension integer at the end 
    executeSQLQuery("vehiclesaverb (VehicleID INTEGER, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INTEGER, Color2 INTEGER, Health REAL, upgrades TEXT, paintjob INTEGER, Hood INTEGER, Trunk INTEGER, FrontLeft INTEGER, FrontRight INTEGER,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INTEGER, FrontRightPanel Integer, RearLeftPanel Integer, RearRightPanel Integer,Windscreen Integer,FrontBumper Integer, RearBumper Integer,FLL Integer,FRL Integer,RLL Integer, RRL Integer, VehOvL Integer, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL Integer, WRL Intger, WFR Integer, WRR Integer, VehSirena Integer, EngineState Integer, XTUR Real, YTUR Real, Interior Integer, Dimension Integer)" ) 
for i, vehicle in pairs (getElementsByType("vehicle")) do 
        local px, py, pz = getElementPosition(vehicle) 
        local rx, ry, rz = getElementRotation(vehicle) 
        local color1, color2, color3, color4 = getVehicleColor(vehicle) 
        local model = getElementModel(vehicle) 
        local health = getElementHealth (vehicle) 
        local tableUpgrades = getVehicleUpgrades(vehicle) 
        local upgrades = table.concat(tableUpgrades, ",") 
        local paintjob = getVehiclePaintjob(vehicle) 
        local hood = getVehicleDoorState(vehicle,0) 
        local trunk = getVehicleDoorState(vehicle,1) 
        local frontleft = getVehicleDoorState(vehicle,2) 
        local frontright = getVehicleDoorState(vehicle,3) 
        local rearleft = getVehicleDoorState(vehicle,4) 
        local rearright = getVehicleDoorState(vehicle,5) 
        local frontleftpanel = getVehiclePanelState(vehicle,0) 
        local frontrightpanel = getVehiclePanelState(vehicle,1) 
        local rearleftpanel = getVehiclePanelState(vehicle,2) 
        local rearrightpanel = getVehiclePanelState(vehicle,3) 
        local windscreen = getVehiclePanelState(vehicle,4) 
        local frontbumper = getVehiclePanelState(vehicle,5) 
        local rearbumper = getVehiclePanelState(vehicle,6) 
        
        local fll = tostring(getVehicleLightState(vehicle, 0)) 
        local frl = tostring(getVehicleLightState(vehicle, 1)) 
        local rll = tostring(getVehicleLightState(vehicle, 2)) 
        local rrl = tostring( getVehicleLightState(vehicle, 3)) 
        local VehOvL = getVehicleOverrideLights(vehicle) 
        local hr = getVehicleDoorOpenRatio(vehicle,0) 
        local tr = getVehicleDoorOpenRatio(vehicle,1) 
        local flr = getVehicleDoorOpenRatio(vehicle,2) 
        local frr = getVehicleDoorOpenRatio(vehicle,3) 
        local rlr = getVehicleDoorOpenRatio(vehicle,4) 
        local rrr = getVehicleDoorOpenRatio(vehicle,5) 
        local wfl, wrl, wfr, wrr = getVehicleWheelStates ( vehicle ) 
        if getVehicleSirensOn(vehicle)==true then getsirena=1 elseif getVehicleSirensOn(vehicle)==false then getsirena=0 else getsirena=2 end 
        local sirena = getsirena 
        if getVehicleEngineState ( vehicle )==true then estate=1 else estate=0 end 
        local tengine=estate 
        local xtur, ytur = getVehicleTurretPosition ( vehicle ) 
                local interior = getElementInterior(vehicle)      -- i added this line 
                local dimension = getElementDimension(vehicle)    -- and this one 
  
  
        --added the interior and dimension again 
              
        executeSQLInsert ( "vehiclesaverb","'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','"..hood.."','"..trunk.."','"..frontleft.."','"..frontright.."','"..rearleft.."','"..rearright.."','"..frontleftpanel.."','"..frontrightpanel.."','"..rearleftpanel.."','"..rearrightpanel.."','"..windscreen.."','"..frontbumper.."','"..rearbumper.."','"..fll.."','"..frl.."','"..rll.."','"..rrl.."','"..VehOvL.."','"..hr.."','"..tr.."','"..flr.."','"..frr.."','"..rlr.."','"..rrr.."','"..wfl.."','"..wrl.."','"..wfr.."','"..wrr.."','"..sirena.."','"..tengine.."','"..xtur.."','"..ytur.."','"..Interior.."',"'..Dimension..'"") 
           
       end 
end 
addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), saveVehicles) 
period=get("garage_projeto.Period") 
if (period > 0) then 
setTimer(saveVehicles,period,0) 
end 
function createDatabase() 
        -- added the same interior and dimension integers here too 
        executeSQLCreateTable ( "vehiclesaverb", "VehicleID INTEGER, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INTEGER, Color2 INTEGER, Health REAL, upgrades TEXT, paintjob INTEGER, Hood INTEGER, Trunk INTEGER, FrontLeft INTEGER, FrontRight INTEGER,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INTEGER, FrontRightPanel Integer, RearLeftPanel Integer, RearRightPanel Integer,Windscreen Integer,FrontBumper Integer, RearBumper Integer,FLL Integer,FRL Integer,RLL Integer, RRL Integer, VehOvL Integer, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL Integer, WRL Intger, WFR Integer, WRR Integer,VehSirena Integer,EngineState Integer, XTUR Real, YTUR Real,Interior Integer,Dimension Integer" ) 
    
    --Getting datas 
    local vehicles = executeSQLQuery("SELECT * FROM vehiclesaverb") 
    
    --Spawning the vehicles 
    for i, v in pairs (vehicles) do 
                            
               --i changed the spawn to a specific cord to avoid having the car falling before it interior is set 
               --because the interior i pretend to use is z = 1000 
               local vehicle = createVehicle( v.VehicleID, -2102, 411, 94, v.rx, v.ry, v.rz ) 
        setElementHealth ( vehicle, v.Health ) 
          
        setVehicleColor ( vehicle, v.Color1, v.Color2, 0, 0 ) 
        if ( v.paintjob ) then 
            setVehiclePaintjob( vehicle, v.paintjob ) 
        end 
        local upgrades = split( v.upgrades, 44 ) 
        for index, upgrade in pairs (upgrades) do 
            addVehicleUpgrade( vehicle, upgrade ) 
        end 
        setVehicleDoorState ( vehicle, 0, v.Hood ) 
        setVehicleDoorState ( vehicle, 1, v.Trunk ) 
        setVehicleDoorState ( vehicle, 2, v.FrontLeft ) 
        setVehicleDoorState ( vehicle, 3, v.FrontRight ) 
        setVehicleDoorState ( vehicle, 4, v.RearLeft ) 
        setVehicleDoorState ( vehicle, 5, v.RearRight ) 
        
        setVehiclePanelState (vehicle,0,v.FrontLeftPanel) 
        setVehiclePanelState (vehicle,1,v.FrontRightPanel) 
        setVehiclePanelState (vehicle,2,v.RearLeftPanel) 
        setVehiclePanelState (vehicle,3,v.RearRightPanel) 
        setVehiclePanelState (vehicle,4,v.Windscreen) 
        setVehiclePanelState (vehicle,5,v.FrontBumper) 
        setVehiclePanelState (vehicle,6,v.RearBumper) 
        
        setVehicleLightState (vehicle,0,v.FLL) 
        setVehicleLightState (vehicle,1,v.FRL) 
        setVehicleLightState (vehicle,2,v.RLL) 
        setVehicleLightState (vehicle,3,v.RRL) 
        setVehicleOverrideLights(vehicle, v.VehOvL) 
        setVehicleDoorOpenRatio (vehicle,0,v.HR,0) 
        setVehicleDoorOpenRatio (vehicle,1,v.TR,0) 
        setVehicleDoorOpenRatio (vehicle,2,v.FLR,0) 
        setVehicleDoorOpenRatio (vehicle,3,v.FRR,0) 
        setVehicleDoorOpenRatio (vehicle,4,v.RLR,0) 
        setVehicleDoorOpenRatio (vehicle,5,v.RRR,0) 
        setVehicleWheelStates ( vehicle, v.WFL, v.WRL, v.WFR, v.WRR ) 
                -- added this too 
                setElementDimension(vehicle, v.Dimension) 
                setElementInterior(vehicle, 1 ,v.px, v.py, v.pz) -- i added the saved cords here, so it go to the right place after spawned, but this is not happening too 
                --. 
        if v.VehSirena==1 then vsirena=true elseif v.VehSirena==0 then  vsirena=false end 
  
        if (v.VehSirena~=2) then 
        setVehicleSirensOn(vehicle,vsirena) 
        end 
        if v.EngineState==1 then setVehicleEngineState(vehicle,true) else setVehicleEngineState(vehicle,false) end 
        setVehicleTurretPosition ( vehicle, v.XTUR, v.YTUR ) 
                
  
    end 
    outputChatBox( #vehicles.." vehicles were created by Garage Master", getRootElement(), 0, 255, 0 ) 
    outputDebugString ( #vehicles.." vehicles were created by Garage Master" ) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), createDatabase) 
  
addCommandHandler("cleargarages", function() 
        destroyElement(getResourceRootElement()) 
        executeSQLDropTable ( "vehiclesaverb" ) 
        end ) 
  

Link to comment

You had many problems, first is that you aren't creating the table, you are executing a query which has no "CREATE TABLE" inside it, also, you had a problem on dimension/interior saving.

function saveVehicles() 
    executeSQLDropTable ( "vehiclesaverb" ) 
    --i added the interior and dimension INT at the end 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS vehiclesaverb (VehicleID INT, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INT, Color2 INT, Health REAL, upgrades TEXT, paintjob INT, Hood INT, Trunk INT, FrontLeft INT, FrontRight INT,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INT, FrontRightPanel INT, RearLeftPanel INT, RearRightPanel INT,Windscreen INT,FrontBumper INT, RearBumper INT,FLL INT,FRL INT,RLL INT, RRL INT, VehOvL INT, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL INT, WRL Intger, WFR INT, WRR INT, VehSirena INT, EngineState INT, XTUR Real, YTUR Real, Interior INT, Dimension INT)" ) 
for i, vehicle in pairs (getElementsByType("vehicle")) do 
        local px, py, pz = getElementPosition(vehicle) 
        local rx, ry, rz = getElementRotation(vehicle) 
        local color1, color2, color3, color4 = getVehicleColor(vehicle) 
        local model = getElementModel(vehicle) 
        local health = getElementHealth (vehicle) 
        local tableUpgrades = getVehicleUpgrades(vehicle) 
        local upgrades = table.concat(tableUpgrades, ",") 
        local paintjob = getVehiclePaintjob(vehicle) 
        local hood = getVehicleDoorState(vehicle,0) 
        local trunk = getVehicleDoorState(vehicle,1) 
        local frontleft = getVehicleDoorState(vehicle,2) 
        local frontright = getVehicleDoorState(vehicle,3) 
        local rearleft = getVehicleDoorState(vehicle,4) 
        local rearright = getVehicleDoorState(vehicle,5) 
        local frontleftpanel = getVehiclePanelState(vehicle,0) 
        local frontrightpanel = getVehiclePanelState(vehicle,1) 
        local rearleftpanel = getVehiclePanelState(vehicle,2) 
        local rearrightpanel = getVehiclePanelState(vehicle,3) 
        local windscreen = getVehiclePanelState(vehicle,4) 
        local frontbumper = getVehiclePanelState(vehicle,5) 
        local rearbumper = getVehiclePanelState(vehicle,6) 
        
        local fll = tostring(getVehicleLightState(vehicle, 0)) 
        local frl = tostring(getVehicleLightState(vehicle, 1)) 
        local rll = tostring(getVehicleLightState(vehicle, 2)) 
        local rrl = tostring( getVehicleLightState(vehicle, 3)) 
        local VehOvL = getVehicleOverrideLights(vehicle) 
        local hr = getVehicleDoorOpenRatio(vehicle,0) 
        local tr = getVehicleDoorOpenRatio(vehicle,1) 
        local flr = getVehicleDoorOpenRatio(vehicle,2) 
        local frr = getVehicleDoorOpenRatio(vehicle,3) 
        local rlr = getVehicleDoorOpenRatio(vehicle,4) 
        local rrr = getVehicleDoorOpenRatio(vehicle,5) 
        local wfl, wrl, wfr, wrr = getVehicleWheelStates ( vehicle ) 
        if getVehicleSirensOn(vehicle)==true then getsirena=1 elseif getVehicleSirensOn(vehicle)==false then getsirena=0 else getsirena=2 end 
        local sirena = getsirena 
        if getVehicleEngineState ( vehicle )==true then estate=1 else estate=0 end 
        local tengine=estate 
        local xtur, ytur = getVehicleTurretPosition ( vehicle ) 
                local interior = getElementInterior(vehicle)      -- i added this line 
                local dimension = getElementDimension(vehicle)    -- and this one 
  
  
        --added the interior and dimension again 
              
        executeSQLInsert ( "vehiclesaverb","'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','"..hood.."','"..trunk.."','"..frontleft.."','"..frontright.."','"..rearleft.."','"..rearright.."','"..frontleftpanel.."','"..frontrightpanel.."','"..rearleftpanel.."','"..rearrightpanel.."','"..windscreen.."','"..frontbumper.."','"..rearbumper.."','"..fll.."','"..frl.."','"..rll.."','"..rrl.."','"..VehOvL.."','"..hr.."','"..tr.."','"..flr.."','"..frr.."','"..rlr.."','"..rrr.."','"..wfl.."','"..wrl.."','"..wfr.."','"..wrr.."','"..sirena.."','"..tengine.."','"..xtur.."','"..ytur.."','"..interior.."','"..dimension.."'") 
          
       end 
end 
addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), saveVehicles) 
period=get("Period") 
if (period > 0) then 
setTimer(saveVehicles,period,0) 
end 
function createDatabase() 
        -- added the same interior and dimension INTs here too 
        executeSQLCreateTable ( "vehiclesaverb", "VehicleID INT, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INT, Color2 INT, Health REAL, upgrades TEXT, paintjob INT, Hood INT, Trunk INT, FrontLeft INT, FrontRight INT,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INT, FrontRightPanel INT, RearLeftPanel INT, RearRightPanel INT,Windscreen INT,FrontBumper INT, RearBumper INT,FLL INT,FRL INT,RLL INT, RRL INT, VehOvL INT, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL INT, WRL Intger, WFR INT, WRR INT,VehSirena INT,EngineState INT, XTUR Real, YTUR Real,Interior INT,Dimension INT" ) 
    
    --Getting datas 
    local vehicles = executeSQLQuery("SELECT * FROM vehiclesaverb") 
    
    --Spawning the vehicles 
    for i, v in pairs (vehicles) do 
                            
               --i changed the spawn to a specific cord to avoid having the car falling before it interior is set 
               --because the interior i pretend to use is z = 1000 
               local vehicle = createVehicle( v.VehicleID, -2102, 411, 94, v.rx, v.ry, v.rz ) 
        setElementHealth ( vehicle, v.Health ) 
          
        setVehicleColor ( vehicle, v.Color1, v.Color2, 0, 0 ) 
        if ( v.paintjob ) then 
            setVehiclePaintjob( vehicle, v.paintjob ) 
        end 
        local upgrades = split( v.upgrades, 44 ) 
        for index, upgrade in pairs (upgrades) do 
            addVehicleUpgrade( vehicle, upgrade ) 
        end 
        setVehicleDoorState ( vehicle, 0, v.Hood ) 
        setVehicleDoorState ( vehicle, 1, v.Trunk ) 
        setVehicleDoorState ( vehicle, 2, v.FrontLeft ) 
        setVehicleDoorState ( vehicle, 3, v.FrontRight ) 
        setVehicleDoorState ( vehicle, 4, v.RearLeft ) 
        setVehicleDoorState ( vehicle, 5, v.RearRight ) 
        
        setVehiclePanelState (vehicle,0,v.FrontLeftPanel) 
        setVehiclePanelState (vehicle,1,v.FrontRightPanel) 
        setVehiclePanelState (vehicle,2,v.RearLeftPanel) 
        setVehiclePanelState (vehicle,3,v.RearRightPanel) 
        setVehiclePanelState (vehicle,4,v.Windscreen) 
        setVehiclePanelState (vehicle,5,v.FrontBumper) 
        setVehiclePanelState (vehicle,6,v.RearBumper) 
        
        setVehicleLightState (vehicle,0,v.FLL) 
        setVehicleLightState (vehicle,1,v.FRL) 
        setVehicleLightState (vehicle,2,v.RLL) 
        setVehicleLightState (vehicle,3,v.RRL) 
        setVehicleOverrideLights(vehicle, v.VehOvL) 
        setVehicleDoorOpenRatio (vehicle,0,v.HR,0) 
        setVehicleDoorOpenRatio (vehicle,1,v.TR,0) 
        setVehicleDoorOpenRatio (vehicle,2,v.FLR,0) 
        setVehicleDoorOpenRatio (vehicle,3,v.FRR,0) 
        setVehicleDoorOpenRatio (vehicle,4,v.RLR,0) 
        setVehicleDoorOpenRatio (vehicle,5,v.RRR,0) 
        setVehicleWheelStates ( vehicle, v.WFL, v.WRL, v.WFR, v.WRR ) 
                -- added this too 
                setElementDimension(vehicle, v.Dimension) 
                setElementInterior(vehicle, 1 ,v.px, v.py, v.pz) -- i added the saved cords here, so it go to the right place after spawned, but this is not happening too 
                --. 
        if v.VehSirena==1 then vsirena=true elseif v.VehSirena==0 then  vsirena=false end 
  
        if (v.VehSirena~=2) then 
        setVehicleSirensOn(vehicle,vsirena) 
        end 
        if v.EngineState==1 then setVehicleEngineState(vehicle,true) else setVehicleEngineState(vehicle,false) end 
        setVehicleTurretPosition ( vehicle, v.XTUR, v.YTUR ) 
                
  
    end 
    outputChatBox( #vehicles.." vehicles were created by Garage Master", getRootElement(), 0, 255, 0 ) 
    outputDebugString ( #vehicles.." vehicles were created by Garage Master" ) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), createDatabase) 
  
addCommandHandler("cleargarages", function() 
        destroyElement(getResourceRootElement()) 
        executeSQLDropTable ( "vehiclesaverb" ) 
        end ) 

Link to comment

I changed the following lines:

executeSQLQuery ( "CREATE TABLE IF NOT EXISTS vehiclesaverb (VehicleID INT, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INT, Color2 INT, Health REAL, upgrades TEXT, paintjob INT, Hood INT, Trunk INT, FrontLeft INT, FrontRight INT,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INT, FrontRightPanel INT, RearLeftPanel INT, RearRightPanel INT,Windscreen INT,FrontBumper INT, RearBumper INT,FLL INT,FRL INT,RLL INT, RRL INT, VehOvL INT, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL INT, WRL Intger, WFR INT, WRR INT, VehSirena INT, EngineState INT, XTUR Real, YTUR Real, Interior INT, Dimension INT)" ) 

executeSQLInsert ( "vehiclesaverb","'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','"..hood.."','"..trunk.."','"..frontleft.."','"..frontright.."','"..rearleft.."','"..rearright.."','"..frontleftpanel.."','"..frontrightpanel.."','"..rearleftpanel.."','"..rearrightpanel.."','"..windscreen.."','"..frontbumper.."','"..rearbumper.."','"..fll.."','"..frl.."','"..rll.."','"..rrl.."','"..VehOvL.."','"..hr.."','"..tr.."','"..flr.."','"..frr.."','"..rlr.."','"..rrr.."','"..wfl.."','"..wrl.."','"..wfr.."','"..wrr.."','"..sirena.."','"..tengine.."','"..xtur.."','"..ytur.."','"..interior.."','"..dimension.."'") 

Link to comment
function saveVehicles() 
    executeSQLDropTable ( "vehiclesaverb" ) 
    --i added the interior and dimension INT at the end 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS vehiclesaverb (VehicleID INT, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INT, Color2 INT, Health REAL, upgrades TEXT, paintjob INT, Hood INT, Trunk INT, FrontLeft INT, FrontRight INT,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INT, FrontRightPanel INT, RearLeftPanel INT, RearRightPanel INT,Windscreen INT,FrontBumper INT, RearBumper INT,FLL INT,FRL INT,RLL INT, RRL INT, VehOvL INT, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL INT, WRL Intger, WFR INT, WRR INT, VehSirena INT, EngineState INT, XTUR Real, YTUR Real, Interior INT, Dimension INT)" ) 
    for i, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
        local px, py, pz = getElementPosition(vehicle) 
        local rx, ry, rz = getElementRotation(vehicle) 
        local color1, color2, color3, color4 = getVehicleColor(vehicle) 
        local model = getElementModel(vehicle) 
        local health = getElementHealth (vehicle) 
        local tableUpgrades = getVehicleUpgrades(vehicle) 
        local upgrades = table.concat(tableUpgrades, ",") 
        local paintjob = getVehiclePaintjob(vehicle) 
        local hood = getVehicleDoorState(vehicle,0) 
        local trunk = getVehicleDoorState(vehicle,1) 
        local frontleft = getVehicleDoorState(vehicle,2) 
        local frontright = getVehicleDoorState(vehicle,3) 
        local rearleft = getVehicleDoorState(vehicle,4) 
        local rearright = getVehicleDoorState(vehicle,5) 
        local frontleftpanel = getVehiclePanelState(vehicle,0) 
        local frontrightpanel = getVehiclePanelState(vehicle,1) 
        local rearleftpanel = getVehiclePanelState(vehicle,2) 
        local rearrightpanel = getVehiclePanelState(vehicle,3) 
        local windscreen = getVehiclePanelState(vehicle,4) 
        local frontbumper = getVehiclePanelState(vehicle,5) 
        local rearbumper = getVehiclePanelState(vehicle,6) 
        local fll = tostring(getVehicleLightState(vehicle, 0)) 
        local frl = tostring(getVehicleLightState(vehicle, 1)) 
        local rll = tostring(getVehicleLightState(vehicle, 2)) 
        local rrl = tostring( getVehicleLightState(vehicle, 3)) 
        local VehOvL = getVehicleOverrideLights(vehicle) 
        local hr = getVehicleDoorOpenRatio(vehicle,0) 
        local tr = getVehicleDoorOpenRatio(vehicle,1) 
        local flr = getVehicleDoorOpenRatio(vehicle,2) 
        local frr = getVehicleDoorOpenRatio(vehicle,3) 
        local rlr = getVehicleDoorOpenRatio(vehicle,4) 
        local rrr = getVehicleDoorOpenRatio(vehicle,5) 
        local wfl, wrl, wfr, wrr = getVehicleWheelStates ( vehicle ) 
        if getVehicleSirensOn(vehicle)==true then getsirena=1 elseif getVehicleSirensOn(vehicle)==false then getsirena=0 else getsirena=2 end 
        local sirena = getsirena 
        if getVehicleEngineState ( vehicle )==true then estate=1 else estate=0 end 
        local tengine=estate 
        local xtur, ytur = getVehicleTurretPosition ( vehicle ) 
        local interior = getElementInterior(vehicle) 
        local dimension = getElementDimension(vehicle) 
        executeSQLInsert ( "vehiclesaverb","'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','"..hood.."','"..trunk.."','"..frontleft.."','"..frontright.."','"..rearleft.."','"..rearright.."','"..frontleftpanel.."','"..frontrightpanel.."','"..rearleftpanel.."','"..rearrightpanel.."','"..windscreen.."','"..frontbumper.."','"..rearbumper.."','"..fll.."','"..frl.."','"..rll.."','"..rrl.."','"..VehOvL.."','"..hr.."','"..tr.."','"..flr.."','"..frr.."','"..rlr.."','"..rrr.."','"..wfl.."','"..wrl.."','"..wfr.."','"..wrr.."','"..sirena.."','"..tengine.."','"..xtur.."','"..ytur.."','"..interior.."','"..dimension.."'") 
    end 
end 
addEventHandler ( "onResourceStop", resourceRoot, saveVehicles ) 
  
period = get ( "Period" ) 
if ( period > 0 ) then 
    setTimer ( saveVehicles, period, 0 ) 
end 
  
function createDatabase() 
    -- added the same interior and dimension INTs here too 
    executeSQLCreateTable ( "vehiclesaverb", "VehicleID INT, px REAL, py REAL, pz REAL, rx REAL, ry REAL, rz REAL, Color1 INT, Color2 INT, Health REAL, upgrades TEXT, paintjob INT, Hood INT, Trunk INT, FrontLeft INT, FrontRight INT,RearLeft INEGER, RearRight INEGER, FrontLeftPanel INT, FrontRightPanel INT, RearLeftPanel INT, RearRightPanel INT,Windscreen INT,FrontBumper INT, RearBumper INT,FLL INT,FRL INT,RLL INT, RRL INT, VehOvL INT, HR Real,TR Real,FLR Real,FRR Real, RLR Real, RRR Real,WFL INT, WRL Intger, WFR INT, WRR INT,VehSirena INT,EngineState INT, XTUR Real, YTUR Real,Interior INT,Dimension INT" ) 
    --Getting datas 
    local vehicles = executeSQLQuery("SELECT * FROM vehiclesaverb") 
  
    --Spawning the vehicles 
    for i, v in ipairs (vehicles) do 
        --i changed the spawn to a specific cord to avoid having the car falling before it interior is set 
        --because the interior i pretend to use is z = 1000 
        local vehicle = createVehicle( v.VehicleID, v.px, v.py, v.pz, v.rx, v.ry, v.rz ) 
        setElementHealth ( vehicle, v.Health ) 
  
        setVehicleColor ( vehicle, v.Color1, v.Color2, 0, 0 ) 
        if ( v.paintjob ) then 
            setVehiclePaintjob( vehicle, v.paintjob ) 
        end 
        local upgrades = split( v.upgrades, 44 ) 
        for index, upgrade in pairs (upgrades) do 
            addVehicleUpgrade( vehicle, upgrade ) 
        end 
        setVehicleDoorState ( vehicle, 0, v.Hood ) 
        setVehicleDoorState ( vehicle, 1, v.Trunk ) 
        setVehicleDoorState ( vehicle, 2, v.FrontLeft ) 
        setVehicleDoorState ( vehicle, 3, v.FrontRight ) 
        setVehicleDoorState ( vehicle, 4, v.RearLeft ) 
        setVehicleDoorState ( vehicle, 5, v.RearRight ) 
        
        setVehiclePanelState (vehicle,0,v.FrontLeftPanel) 
        setVehiclePanelState (vehicle,1,v.FrontRightPanel) 
        setVehiclePanelState (vehicle,2,v.RearLeftPanel) 
        setVehiclePanelState (vehicle,3,v.RearRightPanel) 
        setVehiclePanelState (vehicle,4,v.Windscreen) 
        setVehiclePanelState (vehicle,5,v.FrontBumper) 
        setVehiclePanelState (vehicle,6,v.RearBumper) 
        
        setVehicleLightState (vehicle,0,v.FLL) 
        setVehicleLightState (vehicle,1,v.FRL) 
        setVehicleLightState (vehicle,2,v.RLL) 
        setVehicleLightState (vehicle,3,v.RRL) 
        setVehicleOverrideLights(vehicle, v.VehOvL) 
        setVehicleDoorOpenRatio (vehicle,0,v.HR,0) 
        setVehicleDoorOpenRatio (vehicle,1,v.TR,0) 
        setVehicleDoorOpenRatio (vehicle,2,v.FLR,0) 
        setVehicleDoorOpenRatio (vehicle,3,v.FRR,0) 
        setVehicleDoorOpenRatio (vehicle,4,v.RLR,0) 
        setVehicleDoorOpenRatio (vehicle,5,v.RRR,0) 
        setVehicleWheelStates ( vehicle, v.WFL, v.WRL, v.WFR, v.WRR ) 
        -- added this too 
        setElementDimension(vehicle, v.Dimension) 
        setElementInterior(vehicle, v.Interior, v.px, v.py, v.pz) -- i added the saved cords here, so it go to the right place after spawned, but this is not happening too 
        if v.VehSirena==1 then vsirena=true elseif v.VehSirena==0 then  vsirena=false end 
        if (v.VehSirena~=2) then 
        setVehicleSirensOn(vehicle,vsirena) 
        end 
        if v.EngineState==1 then setVehicleEngineState(vehicle,true) else setVehicleEngineState(vehicle,false) end 
        setVehicleTurretPosition ( vehicle, v.XTUR, v.YTUR ) 
    end 
    outputChatBox( #vehicles.." vehicles were created by Garage Master", getRootElement(), 0, 255, 0 ) 
    outputDebugString ( #vehicles.." vehicles were created by Garage Master" ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, createDatabase ) 
  
addCommandHandler ( "cleargarages", 
    function ( ) 
        destroyElement ( getResourceRootElement ( ) ) 
        executeSQLDropTable ( "vehiclesaverb" ) 
    end 
) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...