Sync Network ID between players

Hello,
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

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        -- 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)
                end

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

                checked_current_vehicle = true
                Citizen.Trace(veh_net)
                TriggerServerEvent("Fuel:CheckVehicle", veh_net)
            end
        end

        -- 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
        end
    end
end)

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?

1 Like

How are you spawning the vehicle?

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

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

remove

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.

1 Like

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

3 Likes

Hello,
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

Was there any update to how to properly set a network entity that exists on all clients with the same id in the end? If so can someone please enlighten me to how? Im trying to do such a thing on the new prototype server system.

I have been using this process in my scripts since the update caesium mentioned above and have had no problems with other clients taking control of vehicles originating from the client that executes the code.

	local vehicleNetId = NetworkGetNetworkIdFromEntity(vehicle)
	SetNetworkIdCanMigrate(vehicleNetId, true)
	SetNetworkIdExistsOnAllMachines(vehicleNetId, true)
	NetworkRegisterEntityAsNetworked(VehToNet(vehicle))

    TriggerServerEvent('someServerEventThatPassesIdToOtherClients', vehicleNetId)

Some natives do not network to other clients so I use this process to have all clients execute those natives on a vehicle which mimics the networked intention. Use a native or existing function to get ‘vehicle’ variable on the originating client and on the clients that server sends the vehicleNetId to you can use the native NetToVeh(vehicleNetId) to get the local vehicle variable to use further in scripts.

1 Like

Hmm unfortunately either i miss understand what your saying or it isn’t working for me. Any other suggestions?

1 Like

Anyone ever figured this out? I am having the same issues. Network ID’s don’t exist on clients who get far away from entities, even if you call functions like those mentioned above.