ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. attachPedToVehicle

Function

attachPedToVehicle

ServerPedsTrilogy Hub only

A ped (NPC or player) rides on the outside of a vehicle: on the step, in the truck bed or on the roof. Every player's game places it from the vehicle's position each frame, so it does not lag behind at high speed. A player is frozen meanwhile and does not collide with that vehicle.

Syntax

bool attachPedToVehicle(ped ped, vehicle vehicle [, float x = 0, float y = 0, float z = 0, float rotation = 0, string block = nil, string anim = nil])

Arguments

pedped
An NPC or a player.
vehiclevehicle
The vehicle.
xfloat, optional = 0
Offset to the right of the vehicle's centre, in metres.
yfloat, optional = 0
Offset forward.
zfloat, optional = 0
Offset up.
rotationfloat, optional = 0
Rotation relative to the vehicle's heading, in degrees.
blockstring, optional = nil
Block of an animation played in a loop.
animstring, optional = nil
Animation name.

Returns

true on success.

Example

local truck = createVehicle(422, 1500, -1680, 14)
local worker = createPed(260, 1500, -1680, 15)
attachPedToVehicle(worker, truck, 0, -1.6, 0.9, 180, "ped", "SEAT_idle")

Notes

The ride ends after detachPedFromVehicle, when the vehicle is destroyed, the ped enters a vehicle or dies.

See also