From what I’ve observed from this and similar threads, the problem with NetworkGetNetworkIdFromEntity
is that the ID returned from the function is bound to the script that created the entity. When I spawn a vehicle with CreateVehicle
, obtain its ID and then restart the resource, the ID stops being valid and cannot be used. Also calling SetEntityAsMissionEntity
can help with reobtaining the correct network ID.
However, the problem si that the script itself is not synchronised. Although the game supports running scripts in a manner where one player is host and the others are clients, a FiveM resource is always run with the current player as the host, i.e. locally. NetworkIsHostOfThisScript
always returns true, no matter whether the player is the actual host of the session or not. The instance of the script is unique for each player, and thus the script is not synchronised.
It seems that if a player (session host) started a script on his own, possibly from a resource that is only made to spawn entities and return their IDs (a “pool resource”), the other players would be clients of the script and be able to access correct entities from functions like NetworkGetEntityFromNetworkId
.
The problem is that it’s apparently impossible at the moment to start a script in this manner. I’ve tried to use functions like RequestScript
, StartNewScript
etc. using my resource name, but it apparently cannot find them.
Are my assumptions correct? Is it possible to run a resource in this manner, to sychronize the entity pool over all players? If not, I suggest it be added (possibly a manifest instruction like hosted_client_script
or something), or a way to obtain the actual synchronisation ID of an entity - I know it’s not the network ID, because that’s local, but there is certainly a way the network protocol represents an entity when exchanging synchronisation information with other players, and this ID would be able to be used to identify an entity in a session.