M MY Multiplayer: Wiki
Side
Kind

attachElements

Shared

Hangs one element on another. From then on it follows the target until it is detached.

bool attachElements(element element, element target [, float x, y, z = 0, 0, 0, float rx, ry, rz = 0, 0, 0, string|int socket = nil])

Parameters

NameTypeDescription
elementelementThe element to attach.
targetelementThe element it hangs on.
x, y, zfloatOffset from the target.default 0, 0, 0
rx, ry, rzfloatRotation relative to the target.default 0, 0, 0
socketstring|intWhere on the target to attach: a ped's bone (its MTA id or its rig name) or a vehicle's or object's component or frame. A number only works for peds, players and objects. Without a socket, the element follows the target's root.default nil

Returns

true if it was attached. false when either element cannot be attached, when it would make a cycle, when they are in different dimensions, when the target has no such socket or when onElementAttach was cancelled.

Players, peds, vehicles, objects, sounds, effects and client lights can be attached. Attaching to another target detaches the element from its current one. When the target is destroyed, the element is detached where it stands.

Example

local vehicle = createVehicle("infernus", 1544.0, -1675.0, 13.6)
local ped = createPed("male01", 1544.0, -1675.0, 15.0)
attachElements(ped, vehicle, 0, 0, 1.2)
Coming from MTAWorks as in MTA, with the socket as an extra argument.

See also