ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. attachElementToBone

Function

attachElementToBone

Server and clientMiscellaneousTrilogy Hub only

Attaches an element (e.g. an object) to a ped's bone, with an offset and rotation. The element moves with the bone, e.g. a hat with the head or a weapon in a hand. Bone numbers are the same as in getBoneIDs (e.g. 1 pelvis, 8 head, 25 right hand, 35 left hand).

Syntax

bool attachElementToBone(element theElement, ped thePed, int bone [, float offX, offY, offZ = 0, float offRotX, offRotY, offRotZ = 0, bool follow = true])

Arguments

theElementelement
The element to attach.
thePedped
The ped.
boneint
Bone number.
offX, offY, offZfloat, optional = 0
Offset.
offRotX, offRotY, offRotZfloat, optional = 0
Rotation in degrees.
followbool, optional = true
Whether the element stays glued to the bone and follows it as the ped runs and moves (default yes). false = the element is placed once at the bone and stays there.

Returns

true on success.

Example

The player holds a box in the right hand.

addCommandHandler("paczka", function(player)
    local box = createObject(1271, 0, 0, 0)
    attachElementToBone(box, player, 25, 0.05, 0.1, 0, 0, 0, 0)
end)

Notes

Works on both sides. On the server every player sees it, in a client script only that player does (e.g. a local object in another player's hand).

You can change the offset and rotation later without re-attaching: setElementBonePositionOffset, setElementBoneRotationOffset.

Offset axes. offX, offY, offZ and the rotation are in the bone's space - the same one getPedBoneMatrix returns (row 1 = X axis, 2 = Y, 3 = Z). The easiest way to tune the offset is to draw the axes from getPedBoneMatrix with dxDrawLine3D. Works for objects with a custom model (engineReplaceModel) too. getElementPosition of an attached element returns this frame's position.

See also