Sync Network ID between players


#1

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.


#2
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.


#3

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?


#4

How are you spawning the vehicle?


#5
	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)

#6

remove

SetEntityAsMissionEntity(nveh, true, true)

#7

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…


#8

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


#9

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


#10

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