- Documentation
- Shared functions
- attachElementToBone
Function
attachElementToBone
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
detachElementFromBoneDetaches an element attached to a bone withattachElementToBone. The element goes back to its own position (the one fromsetElementPosition), so if it should stay where the hand was, set its position before detaching.setElementBonePositionOffsetChanges the offset of an element attached to a bone, without re-attaching it. The element moves relative to the bone right away.setElementBoneRotationOffsetChanges the rotation of an element attached to a bone, without re-attaching it.attachElementsAttaches an element to another. The attached element moves and rotates together with the one it is attached to. An object attached to a vehicle is carried by the game in the same frame as the vehicle physics, so it stays exactly in place even at high speed and in turns.