Hi MTA community recently I was browsing the useful functions list and I saw a new and interesting function available from version 1.5.8 r20704 onwards: attachElementToBone() and using the "onClientPedsProcessed" event. After seeing that this function gives better accuracy and better performance than 'bone_attach' resource I told myself why not making a new bonne attach resource, so this is what I did basically just using the function and the event I just created a synchronization between client and server with tables.
Thank you to Einheit-101 and Saml1er for they’r hard work. Also thank you majqq for pointing me they’re credits!
I called it attachToBones you can download it here: https://community.multitheftauto.com/index.php?p=resources&s=details&id=18372
GitHub (If you want to help): https://github.com/mihayy5/attachToBones
It contains 2 server-side exported functions:
attachElementToBone(theElement, thePed, boneID, offsetX, offsetY, offsetZ, rotationOffsetX, rotationOffsetY, rotationOffsetZ)
theElement: The element which should be attached to the ped/player bone. Should work with any element that is supported by matrix functions.
thePed: The ped or player which the element should be attached to.
boneID: The target bone where the element should be attached to.
offsetX: The X position offset from the bone.
offsetY: The Y position offset from the bone.
offsetZ: The Z position offset from the bone.
rotationOffsetX: The rotation X-axis offset from the bone, in degree.
rotationOffsetY: The rotation Y-axis offset from the bone, in degree.
rotationOffsetZ: The rotation Z-axis offset from the bone, in degree.
NOTE: rotationOffsetX, rotationOffsetY and rotationOffsetZ are automatically converted to radians!
For a list of bone ID you can check the wiki page : attachElementToBone
detachElementFromBone(element)
element: The element which should be detached from the ped/player.
VERY IMPORTANT !
THE OFFSETS ARE NOT COMPATIBLE WITH THE ONES FROM 'bone_attach' so you may have to rework all the positions.
You can quickly test using those 2 test functions
Code:
/atest - to attach a sniper to player hand and a parachute to his back.
/dtest - to detach them!
Hope you find it useful! Cheers.
P.S. PLEASE take note that I did not tested it with more than one player online so I will appreciate ALL feedback you can give!