[HELP] NetworkGetNetworkIdFromEntity

local ped = CreatePed(pedData[2], modelHash, 0.0 + newX, 0.0 + newY, z, 0.0, true, false)
local netID = NetworkGetNetworkIdFromEntity(ped)

I have a problem and its that i’m getting like 90% of times i’m creating the ped the networkID has 0
Is there any problem with that code or something?

you should maybe put a delay btw this 2 line , the time the ped get create by the game. otherwise you will have no network id cause the time you request it , it wasnt create yet, sometime it can be the problem.

This is only happening if you use the create ped in a thread but when you run it inside a sync function everything is running in sync mode so when the createdPed returnining something then it will continue with the next line if i’m not wrong

@Arsilex that’s in theory , but from what i experience , many fonction from the engine will return while the model is loading and if make action on the ped or object or car in the meantime wihout delay it will not working in the better case or crash the game in the worst

1 Like

Tried already what you said to be exact…

local ped = CreatePed(pedData[2], modelHash, 0.0 + newX, 0.0 + newY, z, 0.0, true, false)
while true do
	Wait(5000)
	print("Ped network ID "..NetworkGetNetworkIdFromEntity(ped))

	if NetworkGetNetworkIdFromEntity(ped) == 0 then
		DeleteEntity(ped)
		print("Generated not synced ped ( Deleting )")
	else
		TriggerServerEvent("Peds:pedGenerated", player, tonumber(NetworkGetNetworkIdFromEntity(ped)))
	end
	return
end

And with that sometimes i still getting peds with networkID as 0
and i noticed that when i use

NetworkGetEntityFromNetworkId(tonumber(ped))

Because im sending the ID to the server and after the server to all clients to make sometype of synced peds ( not laggy )
creating it by the host of the session

so… almost 20% of times the host still getting 0 when getting the entity from network in other clients case almost 99% of times they are getting 0 as ID when getting the client-entity ID

I dont think there sooo much de-sync in this to need wait 10 - 20 seconds to sync the clients with the ID of the network

Is there something i’m missing?

i never experience that, (maybe cause i never get the network id directly after create it , only when i need it)

anyway you maybe can try another method, you have these native who convert your object/ped/ect to netwok id, i never had trouble with this native so i hope it will be good for you :

for getting the id :
int OBJ_TO_NET(Object object);
int PED_TO_NET(Ped ped);
int VEH_TO_NET(Vehicle vehicle);

for getting back the obj by the id :

Vehicle NET_TO_VEH(int netHandle);
Ped NET_TO_PED(int netHandle);
Entity NET_TO_ENT(int netHandle);

if with that you still have trouble , i can’t do anymore for you , i use all my native on the subject ^^

but i curious why you trying to that , normaly if you create a ped with the bool at true as you did , that mean your ped will be networked (so it will be already sync with other player)

4 Likes

Just tested it looks like i’m getting fine the netID but when i try to convert it again to the entityID i’m getting 0

I’m duing this because i will apply a decal and more things on the ped after it creating… yea i can just create and apply but its a zombies system and yes i know i can create the zombie client-side without sending it to the server and things like that but i need to it like this creating it by the host of the session as in that way i’m preventing the zombies of lag for some reason the zombies are so laggy if different players create them

Anyway i still have th issue but this time when i’m trying to get the entityID ( ON other client not the host ) i’m getting 0

yes i understand why you need that,

some people on some forum say it’s important to set both boolean at true for getting it network properly otherwise it will only get network id register on client.

1 Like

Well not its working a bit better for the host-client in the session working perfectly but still for the rest of the clients sometimes i get 0 when getting but like 90% of times only.

Other thing i want to ask why sometimes the peds just dissapear i mean i’m killing the zombies everything good and for some reason they just dissapear and its not the scripts which is making them dissapear they just disspear in front of me for no reason, and yes i set the entity as mission entity

maybe cause you make spawn to much zombi , even as entity mission i think you have a limit ( i guess you reach the limit if the ped front of you vanish)

I dont think, i’m just spawning 5 - 10 peds, btw this is only happend with other players on the server when i’m alone in the server i can spawn litteraly 150 - 175 zombies and everything is fine

1 Like

oh yea 10 ped is nothing , i already read something similar on another post where he complain about vehicule or stuff vanish when other people connecting (from what i remenber it was like the network id were use by someone else and that would cause the probleme) i hope someone with more knowledge here could help on this subject.

(i have use all my cards on this sry bro)

1 Like

after digging farer in the native list i found few who could help you to resolve you problem (if all of them are working of course . i didn’t got the time to try them so if you do just let me know)

after creating your ped you can check directly for the creator of the ped if he got an id network if not so you can use this one : NETWORK_REGISTER_ENTITY_AS_NETWORKED

after that you can try to use this native : SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(int netId, BOOL toggle)
if this one work , it should solve this.

other interesting native : _NETWORK_SET_NETWORK_ID_DYNAMIC(int netID, BOOL toggle)
if the name is correct you should be able to say to the game to not change this networkId if you set this bool to false.

and i think about your project and it could maybe help if you have many mission entity :
RESERVE_NETWORK_MISSION_PEDS(int amount)
you set the amount of mission ped you want to save (kind of buffer), don’t forget to save them as entity mission depending of your project, if you do that don’t forget to delete them when you don’t need or when they are too far.

hope you will find you solution with that

Well i will try this aswell thanks you, but for now i think i found the good way…

local ped = CreatePed(pedData[2], modelHash, 0.0 + newX, 0.0 + newY, z, 0.0, true, false)

Yes the last is false if i set it to true they just dissapear… in false they dont

and after that i just did this on the other clients

repeat
		Wait(500)
	until NetToPed(zombie) > 0

Didnt tested it propertly yet but looks like its working fine for now

1 Like

NETWORK_REGISTER_ENTITY_AS_NETWORKED is a Client-side native, so it wouldn’t be useful to the OP, who’s trying not to spawn zombies from individual clients, but rather from the server, if I understood correctly (I skimmed through the convo, sorry about that)