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
Examples
-- 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)