Resource:Bone attach
This resource lets you attach elements to players/peds bones using its exported functions.
Download can be found at the MTA community page.
Resource developed by: Devan_LT
Exported functions/events
This function attaches element to the bone of the ped or player.
bool attachElementToBone (element theElement, element theAttachToPed, int theBone[, float xPosOffset = 0, float yPosOffset = 0, float zPosOffset = 0, float xRotOffset = 0, float yRotOffset = 0, float zRotOffset = 0])
Required Arguments
- theElement: Element which you want to attach..
- theAttachToPed: The ped or player which you want to attach element to.
- theBone: The number of the ped or player's bone which you want to attach element to.
- 1: BONE_PELVIS1
- 2: BONE_PELVIS
- 3: BONE_SPINE1
- 4: BONE_UPPERTORSO
- 5: BONE_NECK
- 6: BONE_HEAD2
- 7: BONE_HEAD1
- 8: BONE_HEAD
- 21: BONE_RIGHTUPPERTORSO
- 22: BONE_RIGHTSHOULDER
- 23: BONE_RIGHTELBOW
- 24: BONE_RIGHTWRIST
- 25: BONE_RIGHTHAND
- 26: BONE_RIGHTTHUMB
- 31: BONE_LEFTUPPERTORSO
- 32: BONE_LEFTSHOULDER
- 33: BONE_LEFTELBOW
- 34: BONE_LEFTWRIST
- 35: BONE_LEFTHAND
- 36: BONE_LEFTTHUMB
- 41: BONE_LEFTHIP
- 42: BONE_LEFTKNEE
- 43: BONE_LEFTANKLE
- 44: BONE_LEFTFOOT
- 51: BONE_RIGHTHIP
- 52: BONE_RIGHTKNEE
- 53: BONE_RIGHTANKLE
- 54: BONE_RIGHTFOOT
Optional arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- xPosOffset: The x offset, if you want the elements to be a certain distance from one another (default 0).
- yPosOffset: The y offset (default 0).
- zPosOffset: The z offset (default 0).
- xRotOffset: The x rotation offset (default 0).
- yRotOffset: The y rotation offset (default 0).
- zRotOffset: The z rotation offset (default 0).
Returns
Returns true if element was successfully attached, false otherwise.
This function detaches element from the bone of the ped.
bool detachElementFromBone (element theElement)
Required Arguments
- theElement: Element which you want to detach.
Returns
Returns true if element was successfully detached, false otherwise.
This function checks if element is attached to a bone.
bool isElementAttachedToBone (element theElement)
Required Arguments
- theElement: Element which you want to check.
Returns
Returns true if element is attached to a bone, false otherwise.
This function gets ped, bone and offset details of attached element.
bool getElementBoneAttachmentDetails (element theElement)
Required Arguments
- theElement: Element which you want to get attachment details of.
Returns
Returns ped, bone, x, y, z, rx, ry, rz used in attachElementToBone if element is attached, false otherwise.
This function changes position offset of attached element.
bool setElementBonePositionOffset (element theElement, float xPosOffset, float yPosOffset, float zPosOffset)
Required Arguments
- theElement: Element which you want to change offset of.
- xPosOffset: New x position offset.
- yPosOffset: New y position offset.
- zPosOffset: New z position offset.
Returns
Returns true if position set successfully, false otherwise.
This function changes rotation offset of attached element.
bool setElementBoneRotationOffset (element theElement, float xRotOffset, float yRotOffset, float zRotOffset)
Required Arguments
- theElement: Element which you want to change offset of.
- xRotOffset: New x rotation offset.
- yRotOffset: New y rotation offset.
- zRotOffset: New z rotation offset.
Returns
Returns true if rotation set successfully, false otherwise.
This function gets position and rotation of the ped bone.
bool getBonePositionAndRotation (element theAttachToPed, int theBone)
Required Arguments
- theAttachToPed: The ped or player which bone you want to get position.
- theBone: The number of the ped or player's bone which you want to get position.
Returns
Returns bone x, y, z position and rotation if ped is streamed in and bone number is valid, false otherwise.
Example
This example makes the player carry a money bag when they type 'getbag':
-- this function is called whenever someone types 'getbag' in the console: function attachCash (thePlayer) local x, y, z = getElementPosition (thePlayer) setPedAnimation (thePlayer, "ROB_BANK", "CAT_Safe_Rob", -1, true, false, false) local objPick = createObject (1550, x, y, z) setTimer (function (thePlayer) setPedAnimation (thePlayer, nil) exports.bone_attach:attachElementToBone (objPick, thePlayer, 4, -0.3, 0.2, 0, -125, 0, 0) end, 1000, 1, thePlayer) end addCommandHandler ("getbag", attachCash)