Cars despawn when player gets far

Is this right, how I edited my garage script ? http://prntscr.com/utedwo

any fix?

4 Likes

Any fix?

2 Likes

Any repro? ._.

This is a ‘bug report’ topic and all you’re doing is spamming ‘any fix?’ without any info… if you want a ‘fix’ you should go to the support section.

1 Like

I wonder if you could show us how you spawn vehicles? Maybe we can compare our way to yours, see if we’re doing something wrong.

ESX.Game.SpawnVehicle = function(modelName, coords, heading, cb)
	local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName))

	CreateThread(function()
		ESX.Streaming.RequestModel(model)

		local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false)
		local id = NetworkGetNetworkIdFromEntity(vehicle)

		SetNetworkIdCanMigrate(id, true)
		SetEntityAsMissionEntity(vehicle, true, false)
		SetVehicleHasBeenOwnedByPlayer(vehicle, true)
		SetVehicleNeedsToBeHotwired(vehicle, false)
		SetVehicleIsStolen(vehicle, false) 
		SetVehicleIsWanted(vehicle, false) 
		SetModelAsNoLongerNeeded(model)
		SetVehRadioStation(vehicle, 'OFF')
		RequestCollisionAtCoord(coords.x, coords.y, coords.z)

		while not HasCollisionLoadedAroundEntity(vehicle) do
			Wait(0)
		end

		if cb then
			cb(vehicle)
		end
	end)
end

I didn’t reply to your message… I specifically asked Bubble. No offence but no one wants your ESX code.

plain vmenu, but code used to spawn is entirely irrelevant to this issue; likely has to do with some other factor

2 Likes

The way i have seen this happening is by leaving a car in the street and then going into an MLO and when back out the car is gone. Clothe store is most mayor offender in my server.

Im also having this issue on my server which has the latest stable artifacts… When I park my vehicle at Legion Square Parking Garage and left (Went to enter areas like Principal Bank also tried clothing) then return to Parking Garage the vehicle is gone…

1 Like

Solution?

Entitlement?

2 Likes

I am using the following to create the vehicles from the server side, but the problem is that sometimes they come out without the properties and sometimes they turn out fine, I don’t know what is the correct way to make this work and stop denying cars:

Client:

function SpawnVehicle(vehicle, plate, fuelLevel)
	--[[
	ESX.TriggerServerCallback('esx_advancedgarage:Crear_Auto', function(spawned_car)
			local auto = NetworkGetEntityFromNetworkId(spawned_car)
			SetVehicleNumberPlateText(auto, plate)
			ESX.Game.SetVehicleProperties(auto, vehicle)
			SetVehRadioStation(auto, "OFF")
			exports["LegacyFuel"]:SetFuel(auto, fuelLevel)
			SetPedIntoVehicle(GetPlayerPed(-1), auto, -1)
			table.insert(autos, { model = vehicle.model, plate = plate, vehicle = auto})
	end, vehicle.model, this_Garage.Spawner, this_Garage.Heading)
	
	TriggerServerEvent('esx_advancedgarage:setVehicleState', plate, false)
end

server.lua

ESX.RegisterServerCallback('esx_advancedgarage:Crear_Auto', function(source, cb, car, coords, Heading)
    local spawned_car = CreateVehicle(car, coords, Heading, true, true)
    while not DoesEntityExist(spawned_car) do Wait(0) end -- or Wait(500)
	local netId = NetworkGetNetworkIdFromEntity(spawned_car)
	while not netId do Wait(0) end -- or Wait(500)
    cb(netId)
end)
1 Like

uh, what

netId will never be nil/false, and even if it would, it would just get it once so you’d loop forever in that case

2 Likes

I don’t understand if you know so much why you don’t help me, I mean I need the solution.

Topic derailed too far again, if anyone has additional info please do provide it in a new topic.