AttachVehicleToCargobob
DocsAttachVehicleToCargobob(cargobob, vehicle, vehicleBoneIndex, x, y, z)Parameters
| Name | Type | Description |
|---|---|---|
cargobob | Vehicle | The cargobob |
vehicle | Vehicle | The vehicle that will be attached |
vehicleBoneIndex | int | A Vehicle bone the hook/magnet should attach to or -1 for none/default [GET_ENTITY_BONE_INDEX_BY_NAME](#\_0xFB71170B7E76ACBA) |
x | float | x hook/magnet Offset |
y | float | y hook/magnet Offset |
z | float | z hook/magnet Offset |
Quick Snippet: Get Coordinatesxyz
xyzAdd this command to your client script to retrieve precise locations in-game.
-- Add this to your client.lua. Type /pos in-game to copy coords.
RegisterCommand('pos', function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
local output = string.format("vector4(%.2f, %.2f, %.2f, %.2f)", coords.x, coords.y, coords.z, heading)
print(output)
TriggerEvent('chat:addMessage', { args = { '^4[COORD]^0', output } })
end)Quick Snippet: Get Vehiclecargobobvehicle
cargobobvehicleUse this to get the current vehicle handle for this native.
-- Get the vehicle the player is currently in
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle ~= 0 then
print("Vehicle handle: " .. vehicle)
print("Model: " .. GetEntityModel(vehicle))
else
print("Player is not in a vehicle")
endVehicle Models

adder
alpha
blade
ardent
asea
cogcabrio
baller
blistaReturns
voidThis native does not return a value.
Examples
Official
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)