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.
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?
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)
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.
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.
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.