Trying to understand how Network works for entities

Me only on spawned vehicles

But on Discord @chrobi also tried on both

Will this ever be fixed?

1 Like

Alright so I tried a lot of things, no result whatsoever.

So now I’m using a kind of workaround, using number plates of vehicles, since for my scripts I’m only using vehicles. I can now identify vehicles with the plate since it’s unique (I generate a unique plate and store it instead of storing the vehicle id).
The functions are explicit; GetVehicleNumberPlateText and GetVehicleNumberPlateText.

Good luck !

This probably relies on proper behavior for network script handlers (every player using the same instance of the script, or so), so it’s a long-term task given how this is a fairly finicky area of the game code.

1 Like

Nice! If two players spam creating does the 2nd still lose control when the game notices the same net ID and nukes one? Or does calling by the plate fix it? @Exorion

any fix for this? or any other way to proper avoid this?

and is there a way to getvehicleentityfromplatetext? i see none

If the address for the vehicle pool could be found maybe that could be used to return an array of vehicles.
hint

In my case I use the vehicle the player is in.

Have you try SET_NETWORK_ID_CAN_MIGRATE ?

Citizen.CreateThread(function()

   while true do  
     Wait(1000)
	dude5 = PlayerId()
	dude6 = IsPlayerFreeAiming(dude5)
	if dude6 ~=false then
	 dude10 = Citizen.InvokeNative(0x2975C866E6713290, dude5, Citizen.PointerValueInt(), Citizen.ResultAsString(dude10))
	 Citizen.Trace('**********************')
	 Citizen.Trace('what player is aiming at')
	 Citizen.Trace('**********************')
	 Citizen.Trace('entity ID = '..tostring(dude10))
	 Citizen.Trace('entity model hash = '..tostring(GetEntityModel(dude10)))
	 Citizen.Trace('entity coords = '..tostring(GetEntityCoords(dude10)))
	 Citizen.Trace('entity rotation = '..tostring(GetEntityRotation(dude10)))
	 Citizen.Trace('entity interior = '..tostring(GetInteriorFromEntity(dude10)))
	 Citizen.Trace('entity roomKey = '..tostring(GetRoomKeyFromEntity(dude10)))
	 Citizen.Trace('object_to_net = '..tostring(entityNetworkID))
	end
	 if dude6 ~=false and deleteGunToggle ==true then 
	 Wait(0) 
	 --BOOL GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(Player player, Entity *entity) // 2975C866E6713290 8866D9D0
	dude10 = Citizen.InvokeNative(0x2975C866E6713290, dude5, Citizen.PointerValueInt(), Citizen.ResultAsString(dude10))
	dude12 = GetEntityModel(dude10)
	dude16 = GetEntityCoords(dude10)
	Citizen.Trace('entity '..tostring(dude10))
	Citizen.Trace('entity model '..tostring(dude12))
	Citizen.Trace('entity coords '..tostring(dude16))
	  isMission = IsEntityAMissionEntity(dude10)
	  isPed = IsEntityAPed(dude10)
	  isAnObj = IsEntityAnObject(dude10)
	  isVeh = IsEntityAVehicle(dude10)
	  object_to_net = ObjToNet(dude10)
	  net_to_object = NetToObj(dude10)   
	    if isMission ~=0 then
            SetEntityAsMissionEntity(dude10, true, true)
			  if isPed ~=false then
			  --BOOL GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(Player player, Entity *entity) // 2975C866E6713290 8866D9D0
			  dude10 = Citizen.InvokeNative(0x2975C866E6713290, dude5, Citizen.PointerValueInt(), Citizen.ResultAsString(dude10))
			  isMission = IsEntityAMissionEntity(dude10)
			   SetEntityAsMissionEntity(dude10, true, true)
			    delPedCoords = GetEntityCoords(dude10)
				 delPedModel = GetEntityModel(dude10)
				 DeleteEntity(dude10)
				  TriggerServerEvent('deleteGunActivity', pedDeleted, tostring(delPedCoords), delPedModel)
				 SetModelAsNoLongerNeeded(dude12)
			  end
              if isVeh ~=false then
			  --BOOL GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(Player player, Entity *entity) // 2975C866E6713290 8866D9D0
			  dude10 = Citizen.InvokeNative(0x2975C866E6713290, dude5, Citizen.PointerValueInt(), Citizen.ResultAsString(dude10))
			  isMission = IsEntityAMissionEntity(dude10)
			   SetEntityAsMissionEntity(dude10, true, true)
			    delVehCoords = GetEntityCoords(dude10)
				 delVehModel = GetEntityModel(dude10)
			    DeleteVehicle(dude10)
				DeleteEntity(dude10)
				 SetModelAsNoLongerNeeded(dude12)
			  end
			  if isAnObj ~=false then
			  --BOOL GET_ENTITY_PLAYER_IS_FREE_AIMING_AT(Player player, Entity *entity) // 2975C866E6713290 8866D9D0
			  dude10 = Citizen.InvokeNative(0x2975C866E6713290, dude5, Citizen.PointerValueInt(), Citizen.ResultAsString(dude10))
			  isMission = IsEntityAMissionEntity(dude10)
			    SetEntityAsMissionEntity(object_to_net, true, true)
				 SetEntityAsMissionEntity(net_to_object, true, true)
				 object_to_net = ObjToNet(dude10)
				  net_to_object = NetToObj(object_to_net)
				   playerName = GetPlayerName(object_to_net, dude5, true)
			    objIndex = GetObjectIndexFromEntityIndex(dude10)
                    objCoords = GetEntityCoords(dude10)
                    objModel = 	GetEntityModel(dude10)
				DeleteEntity(object_to_net)
                 DeleteEntity(net_to_object)
				 SetModelAsNoLongerNeeded(dude12)				    
			  end		  
        end		
	 end
  	  --SetNetworkIdExistsOnAllMachines(dude10, true)
	  --NetworkRegisterEntityAsNetworked(dude10)
	  --NetworkSetEntityVisibleToNetwork(dude10, true)
	  requestControl = NetworkRequestControlOfEntity(dude10)
	local entityCoords = GetEntityCoords(dude10)
	local entityRot = GetEntityRotation(dude10, 2)

	local isEntityNetworked = NetworkHasControlOfEntity(dude10)
	 entityNetworkID = NetworkGetNetworkIdFromEntity(dude10)
     doesEntityExist = NetworkDoesNetworkIdExist(NetworkGetNetworkIdFromEntity(dude10))
      SetEntityAsMissionEntity(dude10, 1, 0)
     DrawSprite("shared","bggradient", 0.88, 0.31, 0.25, 0.50, 90.0, 0, 0, 0, 200)
     drawTxt('DEBUG INFO ', 6, 1, 0.88, 0.097 , 0.5, 255, 0, 0, 255)
     drawTxt('entity ID: ', 6, 1, 0.80, 0.125 , 0.6, 255, 255, 255, 255)
     drawTxt(tostring(dude10), 6, 1, 0.91, 0.125 , 0.6, 0, 255, 255, 255)
     drawTxt('entity model hash: ', 6, 1, 0.80, 0.150 , 0.6, 255, 255, 255, 255)
     drawTxt(tostring(GetEntityModel(dude10)), 6, 1, 0.91, 0.150 , 0.6, 0, 255, 255, 255)
     drawTxt('entity interior: ', 6, 1, 0.80, 0.180, 0.6, 255, 255, 255, 255)
     drawTxt(tostring(GetInteriorFromEntity(dude10)) , 6, 1, 0.91, 0.180, 0.6, 0, 255, 255, 255)
     drawTxt('entity X coords: ', 6, 1, 0.80, 0.210, 0.6 , 0, 255, 0, 255)
     drawTxt(tostring(entityCoords.x) , 6, 1, 0.91, 0.210, 0.6, 0, 255, 0, 255)
     drawTxt("entity Y coords: ", 6, 1, 0.80, 0.240, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(entityCoords.y) , 6, 1, 0.91, 0.240, 0.6, 0, 255, 0, 255)
     drawTxt("entity Z coords: ", 6, 1, 0.80, 0.270, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(entityCoords.z) , 6, 1, 0.91, 0.270, 0.6, 0, 255, 0, 255)
     drawTxt('entity X rotation: ', 6, 1, 0.80, 0.300, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(entityRot.x) , 6, 1, 0.91, 0.30, 0.6, 0, 255, 0, 255)
     drawTxt('entity Y rotation: ', 6, 1, 0.80, 0.330, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(entityRot.y) , 6, 1, 0.91, 0.330, 0.6, 0, 255, 0, 255)
     drawTxt('entity Z rotation: ', 6, 1, 0.80, 0.360, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(entityRot.z) , 6, 1, 0.91, 0.360, 0.6, 0, 255, 0, 255)
     drawTxt('networkID: ', 6, 1, 0.83, 0.390, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(NetworkGetNetworkIdFromEntity(dude10)) , 6, 1, 0.94, 0.390, 0.6, 0, 255, 0, 255)
     drawTxt('is entity networked: ', 6, 1, 0.84, 0.420, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(isEntityNetworked) , 6, 1, 0.94, 0.420, 0.6, 0, 255, 0, 255)
     drawTxt('requestControl', 6, 1, 0.838, 0.450, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(requestControl) , 6, 1, 0.94, 0.450, 0.6, 0, 255, 0, 255)
     drawTxt('doesEntityExist', 6, 1, 0.838, 0.480, 0.6, 0, 255, 0, 255)
     drawTxt(tostring(doesEntityExist) , 6, 1, 0.94, 0.480, 0.6, 0, 255, 0, 255)
end
end)

result

full script here

This seems to be something close to what I think I need to implement to resolve my problem here