Hello, we are currently trying to develop a script for a valet job, where an NPC spawns at a random time, comes to the player and he then parks it into a garage, however, we have just encountered a weird error/behaviour with creating vehicles on server. Both CreateVehicleServerSetter and CreateVehicle.
We are trying to spawn a vehicle, then spawn a ped inside, but with no luck, only the vehicle spawns, the ped doesn’t.
This is the code in question:
AddEventHandler("myscript:server:NewCustomer", function(RandomCar, RandomPed)
local model = type(RandomCar) == "string" and GetHashKey(RandomCar) or RandomCar
local veh = CreateVehicleServerSetter(RandomCar, "automobile", Config.CarSpawn, Config.CarSpawn.w or 0.0)
while not DoesEntityExist(veh) do Wait(0) end
local netId = NetworkGetNetworkIdFromEntity(veh)
local ped = CreatePedInsideVehicle(veh, 2, RandomPed, -1, true, true)
while not DoesEntityExist(ped) do Wait(0) end
local pedNetId = NetworkGetNetworkIdFromEntity(ped)
TriggerClientEvent("myscript:client:NewCustomer", -1, netId, pedNetId)
end)
That code is being invoked with this command currently because of debug purposes:
RegisterCommand("newcustomer", function(source)
local RandomCar = "adder"
local RandomPed = "S_M_Y_Valet_01"
TriggerEvent("myscript:server:NewCustomer", RandomCar, RandomPed)
end, false)
The server event then calls the client, which is supposed to handle all the moving and stuff, but it isn’t even called:
RegisterNetEvent("myscript:client:NewCustomer", function(netId, pedNetId)
-- Configure car
local veh = NetToVeh(netId)
SetEntityHeading(veh, Config.CarSpawn.w)
SetVehicleFuelLevel(veh, 100.0)
SetVehicleEngineOn(veh, true, true)
-- Configure ped
local ped = NetToPed(pedNetId)
SetPedRandomComponentVariation(ped)
SetPedRandomProps(ped)
SetPedFleeAttributes(ped, 0, 0)
SetPedDiesWhenInjured(ped, false)
SetBlockingOfNonTemporaryEvents(ped, true)
SetEntityInvincible(ped, true)
SetPedCanBeDraggedOut(ped, false)
...and continues
The weird behaviour is with the creation on server, when the netId of the spawned vehicle is always 65534 and nothing else, when I tried creating the ped on client, the script errored with this message:
[ 4003797] [b2699_GTAProce] MainThrd/ ^3Warning: [entity] GetNetworkObject: no object by ID 65534^7
[ 4003797] [b2699_GTAProce] MainThrd/ SET_VEHICLE_FUEL_LEVEL: No such entity
[ 4003797] [b2699_GTAProce] MainThrd/
[ 4003797] [b2699_GTAProce] MainThrd/
[ 4004813] [b2699_GTAProce] MainThrd/ No entity with id '0' exists.
This seems oddly similar to