AttachVehicleOnToTrailer
DocsAttachVehicleOnToTrailer(vehicle, trailer, offsetX, offsetY, offsetZ, coordsX, coordsY, coordsZ, rotationX, rotationY, rotationZ, disableColls)Parameters
| Name | Type | Description |
|---|---|---|
vehicle | Vehicle | The vehicle to attach to the trailer |
trailer | Vehicle | The trailer to attach the vehicle to |
offsetX | float | The x offset of the vehicle |
offsetY | float | The y offset of the vehicle |
offsetZ | float | The z offset of the vehicle |
coordsX | float | The x coords of where you want the vehicle placed (must be an offset from the trailer itself) |
coordsY | float | The y coords of where you want the vehicle placed (must be an offset from the trailer itself) |
coordsZ | float | The z coords of where you want the vehicle placed (must be an offset from the trailer itself) |
rotationX | float | The x rotation of where you want the vehicle placed |
rotationY | float | The y rotation of where you want the vehicle placed |
rotationZ | float | The z rotation of where you want the vehicle placed |
disableColls | float | Should actually be a boolean, this will disable the collision between the vehicle you're attaching and the trailer |
Quick Snippet: Get CoordinatesoffsetXoffsetYoffsetZ
offsetXoffsetYoffsetZAdd 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 Vehiclevehicletrailer
vehicletrailerUse 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
-- Request the model before creating it
local truckTrailer = CreateVehicle(`tr2`, GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 8.0, 0.0), true)
-- Open the rear ramp so you can drive a vehicle on
SetVehicleDoorOpen(truckTrailer, 5, false, false)
-- Get the vehicle you're in and it's coords and rotation
local veh = GetVehiclePedIsIn(PlayerPedId())
local vehCoords = GetEntityCoords(veh)
local vehRotation = GetEntityRotation(veh)
-- Park the car where on the trailer you want it, you could make sure your vehicle is touching the trailer first using "IsEntityTouchingEntity"
AttachVehicleOnToTrailer(veh, truckTrailer, 0.0, 0.0, 0.0, GetOffsetFromEntityGivenWorldCoords(truckTrailer, vehCoords), vehRotation, false)
-- Do the following to detach the vehicle from the trailer
DetachEntity(veh, true, false)