[Release][OneSync] Enc0ded Persistent Vehicles

I’m not familiar with ZAP Hosting, does it allow you to run any commands before it restarts. Or does it call a resource event?

Where does this part go in ESX? not seem to be able to find shutdown event
TriggerEvent(‘persistent-vehicles/save-vehicles-to-file’)

I don’t think there is one. I have it in my server reboot script but I realise some people are using Zap hosting’s in house tooling.

You could run it every couple of minutes or so but that doesn’t seem ideal. Whatever it is that is telling your server to reboot needs to call it essentially.

can you share your server reboot script?

Sure, give me a min.

Edit: @Back_Office It’s not great. You’ll need to match restartTime with whatever is restarting your server. This doesn’t actually restart the server you’ll need a batch file for that.

I think you should try to talk to @tabarra about integrating restart part with txAdmin.

Don’t worry, txAdmin is already (very well) integrated with FiveM… with even more integrations to come actually very soon.

1 Like

Yes i know, and you are doing a great job with it, case is that this resource requires hook on restart procedure to be able to function properly that’s why i advised @Hatchett to talk to you, as far as i know you are working on API so maybe he can use it to integrate whenever its ready .

Any idea why im having this issue? i followed all the steps.
This is where i putted the code:

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

	Citizen.CreateThread(function()
		RequestModel(model)

		while not HasModelLoaded(model) do
			Citizen.Wait(0)
		end

		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)
		SetModelAsNoLongerNeeded(model)

		RequestCollisionAtCoord(coords.x, coords.y, coords.z)

		while not HasCollisionLoadedAroundEntity(vehicle) do
			RequestCollisionAtCoord(coords.x, coords.y, coords.z)
			Citizen.Wait(0)
		end
		TriggerEvent('persistent-vehicles/register-vehicle', vehicle )
		SetVehRadioStation(vehicle, 'OFF')

		if cb ~= nil then
			cb(vehicle)
		end
	end)
end

After server was running for 9 hours or so. I started having alot of users crash with this error.

image

1 Like

Ahhhh i thought we were in a different thread… my bad :smile:

1 Like

New Update: Fixes Pool Size issue above and adds in new entity management.

@RealAceStriker you need to use fivem artifact version 2443 or greater

Sorry im new but what is fivem artifict version 2443?
How to download it
also if i upgrade mine, Does it gonan effect my server scripts?

Update your FiveM server to the latest version

https://runtime.fivem.net/artifacts/fivem/build_server_windows/master/

Thankyou and it’s now working!!

Anyways, do you know how to fix animal bug when using onesync? because they get disappear or do weird things when come closer

Thank you @Hatchett !! I’ll give it some more testing with the new update with my player base! <3

1 Like

having an issue when i dv the vehicle it just instantly reappears

ESX.Game.DeleteVehicle = function(vehicle)
	SetEntityAsMissionEntity(vehicle, false, true)
	DeleteVehicle(vehicle)
	TriggerEvent('persistent-vehicles/forget-vehicle', entity)
	print('Del Test1')
end

thats es-extended/client/functions

then even added this to es-extended/client/main

RegisterNetEvent('esx:deleteVehicle')
AddEventHandler('esx:deleteVehicle', function(radius)
	local playerPed = PlayerPedId()

	if radius and tonumber(radius) then
		radius = tonumber(radius) + 0.01
		local vehicles = ESX.Game.GetVehiclesInArea(GetEntityCoords(playerPed), radius)

		for k,entity in ipairs(vehicles) do
			local attempt = 0

			while not NetworkHasControlOfEntity(entity) and attempt < 100 and DoesEntityExist(entity) do
				Citizen.Wait(100)
				NetworkRequestControlOfEntity(entity)
				attempt = attempt + 1
			end

			if DoesEntityExist(entity) and NetworkHasControlOfEntity(entity) then
				ESX.Game.DeleteVehicle(entity)
				TriggerEvent('persistent-vehicles/forget-vehicle', entity)
				print('Del Test2')
			end
		end
	else
		local vehicle, attempt = ESX.Game.GetVehicleInDirection(), 0

		if IsPedInAnyVehicle(playerPed, true) then
			vehicle = GetVehiclePedIsIn(playerPed, false)
		end

		while not NetworkHasControlOfEntity(vehicle) and attempt < 100 and DoesEntityExist(vehicle) do
			Citizen.Wait(100)
			NetworkRequestControlOfEntity(vehicle)
			attempt = attempt + 1
		end

		if DoesEntityExist(vehicle) and NetworkHasControlOfEntity(vehicle) then
			ESX.Game.DeleteVehicle(vehicle)
			TriggerEvent('persistent-vehicles/forget-vehicle', entity)
			print('Del Test3')
		end
	end
end)

this is on /dv or /cardel the vehicle

1 Like

You’re deleting the entity before you try to unregister it. Plus you’re not passing the vehicle entity.

ESX.Game.DeleteVehicle = function(vehicle)
    TriggerEvent('persistent-vehicles/forget-vehicle', vehicle)
	SetEntityAsMissionEntity(vehicle, false, true)
	DeleteVehicle(vehicle)
	
	print('Del Test1')
end

appreciate it this worked a treat, do we know how this affects civ cars?

1 Like