Sync Network ID between players


I am very new to this community. I started developing a server for a while, but right now i have a problem with network ids.
I created a resource that can spawn cars with network id for every car. I created too a command that every player can teleport to a car using network id. All is good and work perfectly between all players but… if the player who spwned the car has disconnected, no one can teleport to the car. I used SetNetworkIdCanMigrate but no luck.

Thank you and sorry for my bad english.

local checked_current_vehicle = false

    while true do
        -- Enter Vehicle
        if IsPedInAnyVehicle(GetPlayerPed(PlayerId()), false) and not checked_current_vehicle then
            local vehicle = GetVehiclePedIsIn(GetPlayerPed(PlayerId()), false)
            if IsPedInSeat(vehicle, -1, GetPlayerPed(PlayerId())) then

                -- Sets as mission entity
                if not IsEntityAMissionEntity(vehicle) then
                    Citizen.Trace("Set As Mission Entity")
                    SetEntityAsMissionEntity(vehicle, 1, 1)

                local veh_net = VehToNet(vehicle)
                SetNetworkIdExistsOnAllMachines(veh_net, true)
                NetworkSetNetworkIdDynamic(veh_net, false)

                checked_current_vehicle = true
                TriggerServerEvent("Fuel:CheckVehicle", veh_net)

        -- Exit Vehicle
        if not IsPedInAnyVehicle(GetPlayerPed(PlayerId()), false) and checked_current_vehicle then
            local vehicle = GetVehiclePedIsIn(GetPlayerPed(PlayerId()), true)
            local net_id = VehToNet(vehicle)
            local current_fuel = GetVehicleFuelLevel(vehicle)
            TriggerServerEvent("Fuel:UpdateVehicle", net_id, current_fuel)
            checked_current_vehicle = false
            start_using_fuel = false

I use this for now but for some reason it doesn’t work on Lambda spawned cars… Still working on that.


Sorry for this late.
I tested your script, i removed triggersever and function IsPedInSeat because i don’t need. I entered with one friend in a vehicle and no luck… After the player who spawned the car has disconnected, the vehicle will become without control(no network id control)… I tried all resource_manifest_version , nothing…
Does anyone know how i can keep a vehicle always in network?


How are you spawning the vehicle?

	local coordA = GetEntityCoords(GetPlayerPed(-1), 1)
	local mhash = GetHashKey("gtr")
		while not HasModelLoaded(mhash) do
		local nveh = CreateVehicle(mhash, coordA, 0.0, true, true)

		SetEntityAsMissionEntity(nveh, true, true)
		local netid = NetworkGetNetworkIdFromEntity(nveh)
		SetNetworkIdExistsOnAllMachines(netid, true)
		SetNetworkIdCanMigrate(netid, true)



SetEntityAsMissionEntity(nveh, true, true)


I tried:

SetEntityAsMissionEntity(nveh, true, true)
SetEntityAsMissionEntity(nveh, true, false)
SetEntityAsMissionEntity(nveh, false, true)
SetEntityAsMissionEntity(nveh, false, false)

Also i removed the line as you said, and still nothing.
i tried so:

SetNetworkIdCanMigrate(netid, true)
SetNetworkIdCanMigrate(netid, false)
local nveh = CreateVehicle(mhash, coordA, 0.0, true, true)
local nveh = CreateVehicle(mhash, coordA, 0.0, true, false)

No change…


Hmm. No idea then. Networking in fivem ids probably one of the hardest things to do.


the 1290 update will fix some oddity in behavior of network object IDs by reverting to GTA IV’s behavior


WOW, this is a good news. Do you have a ETA for Update? Will become with the ZeroSync Project?
Also thank you @xander1998 for tying to help me and thank you @caesium for this announcement