Resource:Bone attach: Difference between revisions
(Created page with "{{Resource page}} __NOTOC__ This resource lets you attach elements to players/peds bones using its exported functions. Download can be found at the [https://community.multithe...") |
(Fixed available bone IDs being incorrect) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This resource lets you attach elements to players/peds bones using its exported functions. | This resource lets you attach elements to players/peds bones using its exported functions. | ||
Download can be found at the [https://community.multitheftauto.com/index.php?p=resources&s=details&id=2540 MTA community page]. | Download can be found at the [https://community.multitheftauto.com/index.php?p=resources&s=details&id=2540 MTA community page].<br> | ||
Resource developed by: [https://community.multitheftauto.com/index.php?p=profile&id=5138 Devan_LT] (also known as [https://forum.mtasa.com/profile/1985-crystalmv/ CrystalMV]) | |||
==Exported functions/events== | ==Exported functions/events== | ||
Line 16: | Line 17: | ||
[[Image:Bones.jpg|thumb|Bone numbers]] | [[Image:Bones.jpg|thumb|Bone numbers]] | ||
<div style="border: 3px red solid; margin-bottom:3px; padding-left:5px;"> | <div style="border: 3px red solid; margin-bottom:3px; padding-left:5px;"> | ||
*'''1:''' | |||
*'''2:''' | *'''1:''' head | ||
*'''3:''' | *'''2:''' neck | ||
*'''4:''' | *'''3:''' spine | ||
*'''5:''' | *'''4:''' pelvis | ||
*'''6:''' | *'''5:''' left clavicle | ||
*'''7:''' | *'''6:''' right clavicle | ||
*'''8:''' | *'''7:''' left shoulder | ||
*'''8:''' right shoulder | |||
*'''9:''' left elbow | |||
*'''10:''' right elbow | |||
*'''11:''' left hand | |||
*'''12:''' right hand | |||
*'''13:''' left hip | |||
*'''14:''' right hip | |||
*'''15:''' left knee | |||
*''' | *'''16:''' right knee | ||
*''' | *'''17:''' left ankle | ||
*''' | *'''18:''' right ankle | ||
*''' | *'''19:''' left foot | ||
*''' | *'''20:''' right foot | ||
*''' | |||
*''' | |||
*''' | |||
*''' | |||
*''' | |||
*''' | |||
*''' | |||
</div> | </div> | ||
====Optional arguments==== | ====Optional arguments==== | ||
Line 127: | Line 121: | ||
====Returns==== | ====Returns==== | ||
Returns bone x, y, z position and rotation if ped is streamed in and bone number is valid, false otherwise. | Returns bone x, y, z position and rotation if ped is streamed in and bone number is valid, false otherwise. | ||
</section> | |||
==Example== | |||
<section name="Example 1" class="server" show="true"> | |||
This example makes the player carry a money bag when they type 'getbag': | |||
<syntaxhighlight lang="lua"> | |||
-- 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) | |||
</syntaxhighlight> | |||
</section> | </section> |
Latest revision as of 09:49, 28 May 2019
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 (also known as CrystalMV)
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: head
- 2: neck
- 3: spine
- 4: pelvis
- 5: left clavicle
- 6: right clavicle
- 7: left shoulder
- 8: right shoulder
- 9: left elbow
- 10: right elbow
- 11: left hand
- 12: right hand
- 13: left hip
- 14: right hip
- 15: left knee
- 16: right knee
- 17: left ankle
- 18: right ankle
- 19: left foot
- 20: right foot
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)