[Release][OneSync] Enc0ded Persistent Vehicles

@Hatchett - also for me, seems realy to be 50/50 ^^

my file looking like this, i format it just for the pic to show the different coords. I left them all in Sandy Shores at the bigger Airfield.

coords about {“z”:39.9794921875,“h”:283.86138916015627,“x”:1619.85498046875,“y”:3214.15380859375}
are the one at SandyAirfield

using:
FXServer 2949
onesync legacy

Since 2900 build, cars are saved by FiveM itself

Also for Game Build 2060? My cars just disapear after reconnect, without server restart. Is there a hint for the function in 2900 builds?

I have build 2060 and latest artifact, cars are no more despawning! :smiley:

I did use this resource, but not needed anymore!

i update artifact and try again, thank u :slight_smile:

@ dutchplayers Have tried latest artifact and issue persists, have you tried with more than one player? WIth one player the vehicles don’t seem to disappear when you go away, I tested with 3 players we parked a car outside pinkcage then went inside, after 3 seconds we exited and the car was gone.

Hello all, how this script work ? i have onesync_enabled 1, the script is start in config.lua but when i restart the server all vehicles i bought at vehicleshop are not spawned.

i tested to do “pv-save-to-file” in RCON console, but he say : “print Persistent Vehicles: 0 vehicles saved to file”

Anyone can explain me how to setup this script ?

Thank you,

Zastax#4257 (discord)

@Zastaax As this is a standalone resource, you’ll have to follow the instructions in the readme.md file in the repository to get it set up properly.

Essentially, you’ll want to call the persistent vehicle events from the corresponding events in other resources. For example, if you’re using ESX then inside of the ESX.Game.SpawnVehicle function, you’d pass its entity to the register-vehicle event and as long as this resource is started, it will make any vehicle spawned by the ESX.Game.SpawnVehicle function persistent.

If you’re not using ESX, then you’ll want to call these events from whatever function you’re using to spawn/remove/update vehicles.

@Braanflakes I put the function : “TriggerEvent(‘persistent-vehicles/register-vehicle’, entity)” in my es_extended/client/function.lua

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', entity)
		SetVehRadioStation(vehicle, 'OFF')

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

And after I don’t know what to do,

Thx for answer !

EDIT : i get a error now

[91mSCRIPT ERROR: @enc0ded-persistent-vehicles/server/main.lua:191: attempt to index a nil value (local ‘props’)e[0m

1 Like

@Zastaax

TriggerEvent(‘persistent-vehicles/register-vehicle’, entity)

‘entity’ in this context doesn’t exist, you need to pass that event the entity of the vehicle

@Braanflakes
Thx, but can you more explain it ?

OKay Thx work perfectly, but now i need to /dv the car but the car respawn :confused:

EDIT : Okay thx you all script work perfectly

Hi ! with + set sv_enforceGameBuild 2060 does it work? Because sometimes the vehicles disappear

not for us, tested with several artifacts … saving and spawning some well, but some cars changing cords and spawn random next to other in further locations …

Again the vehicles disappear without touching them :confused:

Hi, i have a problem with this script.

When i sell a vehicle to a player with esx_vehicleshop, the player have the car with the plate like EUG 572 and when we go far away from the car, and come back to it, the plate was changed to a random plate or sometimes, the car disapear…

Someone know why ?

Thanks !

@Braanflakes @Hatchett
Did you know why in the file ‘vehicle-data.json’ the number plate is not the same when i sell vehicle for someone at esx_vehicleshop ? because when the serveur restarting or when i go far away from my car the number plate become like befor :frowning:

Okay i have fixe all my problems, but now when i reboot my server, some vehicle no respawn to their position (if vehicle are far away where i’m)

Someone jave any idea ?
Thx @Hatchett

Are you stopping correctly?

Help me Please…

SCRIPT ERROR: @enc0ded-persistent-vehicles/server/main.lua:191: attempt to index a nil value (local ‘props’)

handler (@enc0ded-persistent-vehicles/server/main.lua:14)

1 Like