I am having an issue with getting an entity from a network ID here is some code.
Client Side:
local enemies = {}
RegisterCommand('spawnpeds', function(source, args, rawCommand)
local peds = {
{
ped = { model = 's_m_y_blackops_01' },
coords = { x = 0.0, y = 0.0, z = 0.0, hdg = 0.0 }
},
{
ped = { model = 's_m_y_blackops_02' },
coords = { x = 5.0, y = 5.0, z = 0.0, hdg = 0.0 }
}
}
for i,var in pairs(peds) do
local hash = GetHashKey(var.ped.model)
RequestModel(hash)
while not (HasModelLoaded(hash)) do
Wait(0)
end
local entity = CreatePed('PED_TYPE_MISSION', hash, var.coords.x, var.coords.y, var.coords.z, var.hdg, true, true)
var.ped.netId = NetworkGetNetworkIdFromEntity(entity)
end
TriggerServerEvent('Server:SetData', player.serverId, peds)
end)
RegisterNetEvent('Client:SetData')
AddEventHandler('Client:SetData', function(source, data)
for i,var in pairs(data) do
var.ped.entity = NetworkGetEntityFromNetworkId(var.ped.netId)
while not (DoesEntityExist(var.ped.entity)) do
Wait(0)
end
print(var.ped.entity)
end
local enemies = data
end)
Server Side:
RegisterNetEvent('Server:SetData')
AddEventHandler('Server:SetData', function(source, data)
TriggerClientEvent('Client:SetData', -1, data)
end)
When my friend and I get in the server and I type the command spawnpeds
. When I look in the client console it gets the ped entities successful but for him, it just shows 0 and says 'GetNetworkObject: no object by id
. What am I missing, I have tried an amplitude of things such as:
SetNetworkIdCanMigrate()
SetNetworkIdExistsOnAllMachines()
NetworkSetNetworkIdDynamic()
SetNetworkIdSyncToPlayer()
NetworkRequestControlOfNetworkId()
NetworkHasControlOfNetworkId()
NetworkDoesNetworkIdExist()
NetworkDoesEntityExistWithNetworkId()
PedToNet()
NetToPed()
Any help would be much appreciated!