Jump to content

Vehicles disappear on disconnect


Recommended Posts

I've currently made it so my vehicles spawn from my database, which works fine. But as soon as I disconnect, all vehicles are no longer spawned and I have to restart the resource to respawn them.

function resourceStart()
    local allVehicles = sql:query("SELECT * FROM vehicles")
    for i,v in ipairs(allVehicles)do
        local theVeh = createVehicle(v["model"],v["posx"],v["posy"],v["posz"],v["posrx"],v["posry"],v["posrz"],v["tag"])
        if not theVeh then
            return
        end
        setElementDimension(theVeh,0)
        setElementData(theVeh,"id",v["id"])
        setVehicleColor(theVeh,v["color1"],v["color2"],v["color3"],v["color4"],v["color5"],v["color6"])
        setElementData(theVeh,"ownerID",v["ownerid"])
        setElementData(theVeh,"faction",v["faction"])
        setElementData(theVeh,"isLocked",v["isLocked"])
        if(v["isLocked"] == 0)then
            setVehicleLocked(theVeh,false)
        else
            setVehicleLocked(theVeh,true)
        end
        setVehicleOverrideLights(theVeh,v["lightState"])
        setElementData(theVeh,"lightState",v["lightState"])
        setElementData(theVeh,"engineState",v["engineState"])
        if(v["engineState"] == "true")then
            setVehicleEngineState(theVeh,true)
        elseif(v["engineState"] == "false")then
            setVehicleEngineState(theVeh,false)
        end
        if (v["hasSirens"] == 1) then
            addVehicleSirens(theVeh,1,2)
            setElementData(theVeh,"sirens",true)
        else
            setElementData(theVeh,"sirens",false)
        end
    end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),resourceStart)

I don't have any calls anywhere to destroy the vehicles on disconnect, only a /destroyvehicle command which only deletes vehicles that match the owner.

Link to comment
1 minute ago, Investor said:

MTA doesn't destroy vehicles on disconnect, so it must be a script, and if you didn't write that in this resource than it's some other resource causing this.

Yeah, so I've gone through all resources and I have nothing telling the vehicles to destroy on disconnect, connect, or anything like that. For safety measures I've even commented out my /destroyvehicle command, and even commented out all instances of "onPlayerQuit", yet the vehicles still disappear when you disconnect.

Link to comment
17 hours ago, Gordon_G said:

That's not possible if this script is on server side 

Take a look at dimensions maybe

I still don't know what caused it, but I took your suggestion and commented out all dimensions, just to keep everything in the main dimension. (Initially the setElementDimension in my vehicle script was to bugcheck dimensions from my character system)

It still didn't work, they kept disappearing so I called it for the night. I shut my server down, turned off my VPS, and let it be.

Woke up today expecting to fix it again, booted up the VPS and the server, and no issues whatsoever. I'm beginning to think that my server hates me haha

  • Haha 1
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...