[DEV] Entity Network IDs

Hi,

I’m making a script that spawns PEDs, and want to keep control of them ( to know where are they, if they are alive, etc.)

Steps:

  1. Server select random player and make him check / spawn PEDs
  2. Client spawns the NPCs and send to server the NETWORK ID
  3. Again server select random player, and sending the NETWORK ID too, to handle the PEDs.

Result:

It seems to work when close to the spawn point.

The problem:

If the client tries to find the PED by NETWORK ID when it’s too far from it, it seems imposible to get it.

Things tried:

  • CREATE_PED ( the last two parameters set to true true and true false)
  • NETWORK_GET_ENTITY_FROM_NETWORK_ID and NETWORK_GET_NETWORK_ID_FROM_ENTITY
  • NET_TO_PED and PED_TO_NET
  • DECOR_REGISTER and DECOR_SET_INT and DECOR_GET_INT and ESX.GetAllPeds ( I don’t remember the name exactly)
  • NETWORK_REGISTER_ENTITY_AS_NETWORKED
  • SET_NETWORK_ID_CAN_MIGRATE (to false or true )
  • SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES ( to true)
  • _NETWORK_SET_NETWORK_ID_DYNAMIC (to false)

The strange thing is that it seems posible to spawn a ped from distance, but not to get it ( even by network ID, ESX enumerate, etc…). I’ve spent lot of hours before posting here so please I need help xD

Any tip to control PED from the distance, selecting it by NETWORK ID or something similar???

Thanks a lot!!!

2 Likes

Perhaps you need to gain control of the entity first?

(NetworkId)
https://runtime.fivem.net/doc/natives/#_0x4D36070FE0215186
https://runtime.fivem.net/doc/natives/#_0xA670B3662FAFFBD0

(Entity)
https://runtime.fivem.net/doc/natives/#_0x01BF60A500E28887
https://runtime.fivem.net/doc/natives/#_0xB69317BF5E782347

5 Likes

hmmm interesting!

I’m going to try it and tell the results, thanks!

Use the network manifest.

R* code uses
SetEntitySomething
and
SetNetworkIdExistsOnAllMachines

the spawned entities are almost immediately available on every machine connected (no matter which distance).

But in some recent network test I was in, entities were culled for at least the host (when he spawned them) and just disappeared for both of us, while the ones I spawned were persistant for me and him.

1 Like

Doesn’t seem to work…

Spawn:

local newPed = CreatePed(5, config.hash, config.spawnX, config.spawnY, config.spawnZ, config.spawnHeading, true, false)
SetEntityAsMissionEntity(newPed, true, true)
NetworkRegisterEntityAsNetworked(newPed)

local netID = PedToNet(newPed)
NetworkSetNetworkIdDynamic(netID), false) 
SetNetworkIdCanMigrate(netID, true)
SetNetworkIdExistsOnAllMachines(netID, true)

Later check:

local exists = false
local ped = nil
if config.NetId ~= nil then
	NetworkRequestControlOfNetworkId(config.NetId)
	NetworkRequestControlOfEntity(NetToPed(config.NetId))

	if NetworkDoesNetworkIdExist(config.NetId) or DoesEntityExist(NetToPed(config.NetId)) then
		local EntityCheck = NetToPed(config.NetId)
		if DoesEntityExist(EntityCheck) then
			ped = EntityCheck
		end
		exists = true
	else 
		print( "Couldn't find NETWORK ID: " .. config.NetId) 
	end
end
2 Likes

are you sure your resource lua contains this manifest version:

1 Like

Wow!! It seems to work perfect now.

I didn’t understand your first message, sorry!

Thanks a lot for your help :smiley: :smiley:

1 Like