Hi
Does anyone know how RPC Native works?
Why can create Entity(CreatePed, CreateVehicel, etc.) without any players in the server?
Below is my test
This is my test code(server side):
RegisterCommand('testsv', function(source, args, rawCommand)
local netId = tonumber(args[1])
if netId then
local ped = NetworkGetEntityFromNetworkId(netId)
print(ped, NetworkGetEntityOwner(ped))
return
end
for i=1, 1000 do
local ped = CreatePed(4, GetHashKey('A_F_M_Beach_01'), vector3(-1573.464, -2615.42, 13.92969), math.random(0, 360), true, true)
local netId = NetworkGetNetworkIdFromEntity(ped)
print(('count: %s, pedId: %s, netId: %s, entityOwner: %s'):format(i, ped, netId, NetworkGetEntityOwner(ped)))
if netId == 0 then
print('not enough network id to spawn a new ped?')
break
end
end
end, false)
Test steps:
-
When there is no player in the server, I execute the command
testsv
on the server console:
-
Then I use the command
testsv 7135
to select a spawned ped net id to check whether this entity exists, in fact, the entity ID exists, which means that the entity does exist.:
-
I enter the server and can indeed see these peds:
After my test, as long as the result of NetworkGetEntityOwner is -1, the entity will not be deleted because there are no players in the server.
I want to know how RPC CreatePed works on the server side.
As far as I know, if the entity to be spawned can only be spawned on the client side, is the server side also a client?
There is also a test about not having enough network id
Since my English is not good, I made a video demonstration: https://www.youtube.com/watch?v=JiFK9lM4w8I
If the ped spawned on the client can only spawn 1~200+ at most, the ped spawned later will not be networked because it does not have enough network IDs, but if it is spawned on the server using RPC, the network ID can be as many as 1~8191, so more peds can be spawned.
Why is there a difference between client spawn and rpc spawn?
English is not my native language. I have described my question as much as possible. I hope someone can answer it for me. I am grateful!