Looktovask Posted June 12, 2021 Share Posted June 12, 2021 Boa tarde, estou com um problema com sqlite, ele salva os veículos quando é comprado e a posição atualiza assim que desligo o resouce, porem se nessa partida eu comprar um carro ele não salva a posição só nas vezes que não compro nenhum carro, só mexo os que já existem. segue o código server --[[ __ __ __ __ /\ \ /\ \ /\ \__ /\ \ \ \ \ ___ ___\ \ \/'\\ \ ,_\ ___ __ __ __ ____\ \ \/'\ \ \ \ __ / __`\ / __`\ \ , < \ \ \/ / __`\/\ \/\ \ /'__`\ /',__\\ \ , < \ \ \L\ \/\ \L\ \/\ \L\ \ \ \\`\\ \ \_/\ \L\ \ \ \_/ |/\ \L\.\_/\__, `\\ \ \\`\ \ \____/\ \____/\ \____/\ \_\ \_\ \__\ \____/\ \___/ \ \__/.\_\/\____/ \ \_\ \_\ \/___/ \/___/ \/___/ \/_/\/_/\/__/\/___/ \/__/ \/__/\/_/\/___/ \/_/\/_/ --]] local db function CarregarCarros( queryHandle ) local carrospawnar = dbPoll( queryHandle, 0 ) for i, v in pairs(carrospawnar) do CarroRespawn = createVehicle( v["ModeloC"], v["PosX"], v["PosY"], v["PosZ"] , v["RotX"], v["RotY"], v["RotZ"]) setVehicleColor( CarroRespawn, v["Cor1"], v["Cor2"], v["Cor3"], v["Cor4"]) setElementHealth ( CarroRespawn, v["Dano"] ) setVehicleVariant( CarroRespawn , v["V1"], v["V2"] ) setVehiclePaintjob( CarroRespawn, v["Paintjob"] ) setVehiclePanelState( CarroRespawn, 5, v["ParachoqueD"] ) setVehiclePanelState( CarroRespawn, 6, v["ParachoqueT"] ) setVehiclePanelState( CarroRespawn, 4, v["Parabrisa"] ) setElementData(CarroRespawn, "ownercar", v["NomeDono"]) setElementData(CarroRespawn, "Owner", v["IDdono"]) end end addEventHandler( "onResourceStart", resourceRoot, function (startedResource) db = dbConnect( "sqlite", "carros.db" ) dbExec(db, "CREATE TABLE IF NOT EXISTS carros (IDdono, NomeDono, ModeloC, Cor1, Cor2, Cor3, Cor4, Paintjob, PosX, PosY, PosZ, RotX, RotY, RotZ, Dano, ParachoqueD, ParachoqueT, Parabrisa, V1, V2 )") dbQuery( CarregarCarros , db , "SELECT * FROM carros" ) for i,v in ipairs (VagasMotos) do local Vehmotos =createVehicle( ModeloMoto[math.random(1, #ModeloMoto)], v[1], v[2], v[3], v[4], v[5], v[6] ) setElementHealth ( Vehmotos, math.random(600,950) ) setElementData( Vehmotos, "MotoRevenda", true ) setVehicleDamageProof ( Vehmotos, true ) setTimer(function() setElementFrozen( Vehmotos, true ) end,2000,1) end for i,v in ipairs (VagasCarrosRuins) do local Veh:~box = createVehicle( ModeloCarroRuins[math.random(1, #ModeloCarroRuins)], v[1], v[2], v[3], v[4], v[5], v[6] ) setElementHealth ( Veh:~box, math.random(600,950) ) setVehiclePanelState ( Veh:~box, 4, math.random(0,2) ) setVehiclePanelState ( Veh:~box, math.random(5,6), math.random(0,2) ) setElementData( Veh:~box, "CarroRevenda", true ) setVehicleDamageProof ( Veh:~box, true ) setTimer(function() setElementFrozen( Veh:~box, true ) end,2000,1) end for i,v in ipairs (VagasCaminhao) do local VehTruck = createVehicle( ModeloCaminhao[math.random(1, #ModeloCaminhao)], v[1], v[2], v[3], v[4], v[5], v[6] ) setElementHealth ( VehTruck, math.random(600,950) ) setVehiclePanelState ( VehTruck, 4, math.random(0,2) ) setVehiclePanelState ( VehTruck, math.random(5,6), math.random(0,2) ) setElementData( VehTruck, "CaminhaoRevenda", true ) setVehicleDamageProof ( VehTruck, true ) setTimer(function() setElementFrozen( VehTruck, true ) end,2000,1) end end) addEventHandler( "onPlayerVehicleEnter", root, function (theVehicle, seat, jacked) if getElementData( theVehicle, "MotoRevenda") == true then local IDCarro = getElementID( theVehicle ) triggerClientEvent ( "Mostrarhud", resourceRoot ) setElementFrozen( theVehicle, true ) end if getElementData( theVehicle, "CarroRevenda") == true then local IDCarro = getElementID( theVehicle ) triggerClientEvent ( "Mostrarhud", resourceRoot ) setElementFrozen( theVehicle, true ) end if getElementData( theVehicle, "CaminhaoRevenda") == true then local IDCarro = getElementID( theVehicle ) triggerClientEvent ( "Mostrarhud", resourceRoot ) setElementFrozen( theVehicle, true ) end end) addEventHandler( "onVehicleExit", root, function (thePlayer, seat, jacker, forcedByScript) if getElementData( source, "MotoRevenda") == true then local MotoOFF = (source) triggerClientEvent ( "Esconderhud", resourceRoot ) setTimer(function() setVehicleEngineState( MotoOFF, false ) end,10000,1) end if getElementData( source, "CarroRevenda") == true then local CarroOFF = (source) triggerClientEvent ( "Esconderhud", resourceRoot ) setTimer(function() setVehicleEngineState( CarroOFF, false ) end,10000,1) end if getElementData( source, "CaminhaoRevenda") == true then local CaminOFF = (source) triggerClientEvent ( "Esconderhud", resourceRoot ) setTimer(function() setVehicleEngineState( CaminOFF, false ) end,10000,1) end if getElementData( source, "TestDriving") == true then local veiculoarmazenado = (source) setTimer(function() destroyElement( veiculoarmazenado ) outputChatBox( "A Revenda pegou o carrro" ) end,3000,1) end end) function TestarVeiculo() local CarroAcopiar = getPedOccupiedVehicle( client ) local IDcarroCopiar = getElementModel( CarroAcopiar ) local C1, C2, C3, C4 = getVehicleColor( CarroAcopiar , false) local Vidacarro = getElementHealth( CarroAcopiar ) local ParachoqueD = getVehiclePanelState( CarroAcopiar, 5 ) local ParachoqueT = getVehiclePanelState( CarroAcopiar, 6 ) local Parabrisa = getVehiclePanelState( CarroAcopiar, 4 ) local Paintjob = getVehiclePaintjob( CarroAcopiar ) local V1, V2 = getVehicleVariant ( CarroAcopiar ) local CopiaCarroTesteDriver = createVehicle( IDcarroCopiar, 2124.699, -1130.406, 26.56 , 0, 0, 358.863 ) setVehiclePaintjob( CopiaCarroTesteDriver, Paintjob ) setVehicleVariant( CopiaCarroTesteDriver , V1, V2 ) setVehicleColor(CopiaCarroTesteDriver , C1, C2, C3, C4 ) setVehiclePanelState( CopiaCarroTesteDriver, 5, ParachoqueD ) setVehiclePanelState( CopiaCarroTesteDriver, 6, ParachoqueT ) setVehiclePanelState( CopiaCarroTesteDriver, 4, Parabrisa ) setElementHealth( CopiaCarroTesteDriver, Vidacarro ) triggerClientEvent ( "Esconderhud", resourceRoot ) warpPedIntoVehicle( client, CopiaCarroTesteDriver ) setVehicleEngineState( CarroAcopiar, false ) setVehicleOverrideLights ( CarroAcopiar, 1 ) outputChatBox( "Test Drive 1 Minuto de duração" ) setElementData( CopiaCarroTesteDriver, "TestDriving", true ) setVehicleDamageProof ( CopiaCarroTesteDriver, true ) setTimer(function() if isElement ( CopiaCarroTesteDriver ) then destroyElement( CopiaCarroTesteDriver ) outputChatBox( "A Revenda pegou o carrro" ) end end,60000,1) end addEvent( "TestDrive", true ) addEventHandler( "TestDrive", resourceRoot, TestarVeiculo ) function ComprarVeiculoUsado() local CarroAcopiar = getPedOccupiedVehicle( client ) local IDcarroCopiar = getElementModel( CarroAcopiar ) local C1, C2, C3, C4 = getVehicleColor( CarroAcopiar , false) local Vidacarro = getElementHealth( CarroAcopiar ) local ParachoqueD = getVehiclePanelState( CarroAcopiar, 5 ) local ParachoqueT = getVehiclePanelState( CarroAcopiar, 6 ) local Parabrisa = getVehiclePanelState( CarroAcopiar, 4 ) local Paintjob = getVehiclePaintjob( CarroAcopiar ) local V1, V2 = getVehicleVariant ( CarroAcopiar ) local CarroComprado = createVehicle( IDcarroCopiar, 2124.699, -1130.406, 26.56 , 0, 0, 358.863 ) local X1, Y1, Z1 = getElementPosition( CarroComprado ) local RX1, RY1, RZ1 = getElementRotation( CarroComprado ) setVehicleVariant( CarroComprado , V1, V2 ) setVehiclePaintjob( CarroComprado, Paintjob ) setVehicleColor(CarroComprado , C1, C2, C3, C4 ) setVehiclePanelState( CarroComprado, 5, ParachoqueD ) setVehiclePanelState( CarroComprado, 6, ParachoqueT ) setVehiclePanelState( CarroComprado, 4, Parabrisa ) setElementHealth( CarroComprado, Vidacarro ) triggerClientEvent ( "Esconderhud", resourceRoot ) warpPedIntoVehicle( client, CarroComprado ) setVehicleEngineState( CarroAcopiar, false ) setVehicleOverrideLights ( CarroAcopiar, 1 ) setElementData(CarroComprado, "ownercar", getAccountName(getPlayerAccount(client))) setElementData(CarroComprado, "Owner", client) setElementData(client, "IDValido", IDcarroCopiar) dbExec(db, "INSERT INTO carros VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )", getAccountID( getPlayerAccount(client) ), getAccountName(getPlayerAccount(client)), IDcarroCopiar, C1, C2, C3, C4, Paintjob, X1, Y1, Z1, RX1, RY1, RZ1, Vidacarro, ParachoqueD, ParachoqueT, Parabrisa, V1, V2 ) local x, y, z = getElementPosition( CarroAcopiar ) local rx, ry, rz = getElementRotation( CarroAcopiar ) if getElementData( CarroAcopiar, "MotoRevenda") then destroyElement( CarroAcopiar ) local RespawnarMoto = createVehicle( ModeloMoto[math.random(1, #ModeloMoto)], x, y, z, rx, ry, rz ) setElementHealth ( RespawnarMoto, math.random(600,950) ) setElementData( RespawnarMoto, "MotoRevenda", true ) setVehicleDamageProof ( RespawnarMoto, true ) setTimer(function() if isElement(RespawnarMoto) then setElementFrozen( RespawnarMoto, true ) end end,2000,1) elseif getElementData( CarroAcopiar, "CarroRevenda") then destroyElement( CarroAcopiar ) local RespawnarCarro = createVehicle( ModeloCarroRuins[math.random(1, #ModeloCarroRuins)], x, y, z, rx, ry, rz ) setElementHealth ( RespawnarCarro, math.random(600,950) ) setVehiclePanelState ( RespawnarCarro, 4, math.random(0,2) ) setVehiclePanelState ( RespawnarCarro, math.random(5,6), math.random(0,2) ) setElementData( RespawnarCarro, "CarroRevenda", true ) setVehicleDamageProof ( RespawnarCarro, true ) setTimer(function() if isElement(RespawnarCarro) then setElementFrozen( RespawnarCarro, true ) end end,2000,1) elseif getElementData( CarroAcopiar, "CaminhaoRevenda") then destroyElement( CarroAcopiar ) local RespawnarCaminhao = createVehicle( ModeloCaminhao[math.random(1, #ModeloCaminhao)], x, y, z, rx, ry, rz ) setElementHealth ( RespawnarCaminhao, math.random(600,950) ) setVehiclePanelState ( RespawnarCaminhao, 4, math.random(0,2) ) setVehiclePanelState ( RespawnarCaminhao, math.random(5,6), math.random(0,2) ) setElementData( RespawnarCaminhao, "CaminhaoRevenda", true ) setVehicleDamageProof ( RespawnarCaminhao, true ) setTimer(function() if isElement(RespawnarCaminhao) then setElementFrozen( RespawnarCaminhao, true ) end end,2000,1) end end addEvent( "ComprarCarro", true ) addEventHandler( "ComprarCarro", resourceRoot, ComprarVeiculoUsado ) addEventHandler( "onResourceStop", resourceRoot, function (stoppedResource, resourceRoot) for i, v in ipairs (getElementsByType("vehicle")) do local X, Y, Z = getElementPosition( v ) local ROTX, ROTY, ROTZ = getElementRotation( v ) local C11, C22, C33, C44 = getVehicleColor( v , false) local Vvidacarro = getElementHealth( v ) local PParachoqued = getVehiclePanelState( v, 5 ) local PParachoquet = getVehiclePanelState( v, 6 ) local pparabrisa = getVehiclePanelState( v, 4 ) local ppaintjob = getVehiclePaintjob( v ) local Va1, Va2 = getVehicleVariant ( v ) dbExec(db, "UPDATE carros SET PosX = ?, PosY = ?, PosZ = ?, RotX = ?, RotY = ?, RotZ = ?, Cor1 = ?, Cor2 = ?, Cor3 = ?, Cor4 = ?, Dano = ?, ParachoqueD = ?, ParachoqueT = ?, Parabrisa = ?, Paintjob = ?, V1 = ?, V2 = ? WHERE IDdono = ? AND NomeDono = ? AND ModeloC = ? ", X, Y, Z, ROTX, ROTY, ROTZ, C11, C22, C33, C44, Vvidacarro, PParachoqued, PParachoquet, pparabrisa, ppaintjob, Va1, Va2, (getElementData( v, "Owner" )), (getElementData( v, "ownercar" )), (getElementModel( v )) ) end end) 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