function RequestVehicleModel(modelHash)
if not IsModelInCdimage(modelHash) then return end
RequestModel(modelHash)
while not HasModelLoaded(modelHash) do
Wait(0)
end
end
RegisterCommand('spawnCargobob', function(source, args)
local cargobobHash = `cargobob`
local carHash = `adder`
local myPed = PlayerPedId()
local spawnCoords = GetEntityCoords(myPed)
RequestVehicleModel(cargobobHash)
local cargobob = CreateVehicle(cargobobHash, spawnCoords+vec3(0.0,0.0, 10.0), GetEntityHeading(myPed), true, false) -- Spawns a cargobob above players location
SetHeliBladesSpeed(cargobob, 1.0) -- sets the helicoper blades to max spin speed
SetPedIntoVehicle(myPed, cargobob, -1) -- sets the player into the cargobob
SetModelAsNoLongerNeeded(cargobobHash) -- removes model from game memory as we no longer need it
CreatePickUpRopeForCargobob(cargobob, 1) -- 0 = hook, 1 = Magnet Enable rope from cargobob
RequestVehicleModel(carHash)
local vehicle = CreateVehicle(carHash, spawnCoords, GetEntityHeading(myPed), true, false) -- Spawns a vehicle for the cargobob to pickup
SetModelAsNoLongerNeeded(carHash)
Wait(1000)
AttachVehicleToCargobob(cargobob, vehicle, GetEntityBoneIndexByName(vehicle, 'bodyshell'), 0.0, 0.0, 0.0) --Attach the vehicle to the magnet or hook
end)