Hello Community,
I tried to script a simple mission who i need a AI Vehicle with Peds.
But when I try to make the peds - it only returns 0 als handle and the peds never exist.
Are existing some requirements to spawn these?
For the Vehicle I use the ESX Spawn Code:
createVehicle = function(model, coords, heading, cb)
if type(model) == 'string' then
model = GetHashKey(model)
end
self.game.requestModel(model, function()
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false)
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
local timeout = 0
SetNetworkIdCanMigrate(networkId, true)
SetEntityAsMissionEntity(vehicle, true, false)
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false)
SetVehRadioStation(vehicle, 'OFF')
SetModelAsNoLongerNeeded(model)
if cb ~= nil then
cb(vehicle)
end
end)
So my code:
truck = createVehicle('stockade', -3.936, -709.842, 31.942, 336.8, true, false)
RequestCollisionForModel(truck)
N_0x06faacd625d80caa(truck)
SetVehicleDoorsLocked(truck , 7)
SetEntityAsNoLongerNeeded(truck)
SetVehicleOnGroundProperly(truck)
ped1 = CreatePedInsideVehicle(truck, 4, GetHashKey("s_m_m_armoured_01"), -1, true, false)
ped2 = CreatePedInsideVehicle(truck, 4, GetHashKey("s_m_m_armoured_01"), 0, true, false)
print(ped1) -- always 0
SetEntityAsMissionEntity(ped1, 0, 0)
SetEntityAsMissionEntity(ped2, 0, 0)
TruckBlip = AddBlipForEntity(thisMoneyTruck)
SetBlipColour(TruckBlip, 11)
After that i use a TaskVehicleDriveToCoordLongrange - but the vehicle doesn’t drive to.
The Code is executing without errors…