I have simple command which spawns 10 peds. here is code:
RegisterCommand('spawn', function(source, args)
local modelName = 'a_m_y_business_02'
local modelHash = GetHashKey(modelName)
local pl_ped = GetPlayerPed(-1)
if not IsModelInCdimage(modelName) or not IsModelAPed(modelName) then
sendMessage('Error. Not a ped or there is no ped like this.')
return
end
RequestModel(modelName)
sendMessage('[] Loading model...')
while not HasModelLoaded(modelName) do
Wait(333)
end
for i = 0, 10 do -- pos is from GetEntityCoords of player
local ped = CreatePed(4, modelHash, pos.x, pos.y, pos.z, 0.0, true, true)
print('net id : ' .. PedToNet(ped) .. ' local id: ' .. ped)
Wait(50)
end
SetModelAsNoLongerNeeded(modelName)
sendMessage('[] Ped spawned.')
end)
When i execute that command 10 times and i have around 100+ peds they dont get network id anymore. It seems like net id is limited between 1 - 250 number. Is there any function to change that limit of network objects?
This is what gets printed after those 100+ peds: https://gyazo.com/3f9cf9e5582e54811307d9025bc0db8f
No, though this is not a global limit - only a limit along the player’s cull radius. Why are you needing to spawn 100 peds within the player’s range at once, rather than dynamically spawning them in as needed?
The reason im spawnig peds like this because i want them to be synchronized with every player on server.
Here is an example:
Player One (p1) is in the main city and Player Two (p2) is in Paleto Bay. If i spawn 10 peds around p1 and p2 then p1’s peds will disappear for p2 because they are too far. I cant spawn them dynamically because i want every player to see the same peds.
Currently im achieving this by setting one of the players as “host” which spawns networked peds every some time. Is there any different way to do this so i can have more peds networked?
Edit:
After writing this i realised my thinking error. Peds wont get removed from p2 until he is on server so you can actually spawn them dynamically while synchronized with other players. Thanks for help
Thanks for suggestion, i was thinking about similar approach to this. Can you tell me how network ids work? Does every player when spawning peds have different range of these ids for peds or its the same for everyone?
The game transparently allocates network object IDs from a pool of free IDs, they generally correlate to a given player at the time they join, but migration and deletion can and will lead to non-contiguous ID ranges.