Popular Post Tekken Posted January 3, 2021 Popular Post Share Posted January 3, 2021 (edited) 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: Spoiler function testFunction(player) theGun = createObject(358, 0, 0, 0); thePara = createObject(371, 0, 0, 0); attachElementToBone(theGun, player, 24, 0, 0, 0, 0, 0, 0);-- Attach the sniper model to bone #24 of the player, no offset is needed because the default GTA weapon models fit perfectly fine into bone #24 attachElementToBone(thePara, player, 3, 0.1, -0.14, 0, 90, 0, 0);-- Attach parachute to bone #3 of the player with a small position and rotation offset, so it looks nice end addCommandHandler("atest", testFunction) function testFunction2() if theGun then detachElementFromBone(theGun); destroyElement(theGun); theGun = nil; end if thePara then detachElementFromBone(thePara); destroyElement(thePara); thePara = nil; end end addCommandHandler("dtest", testFunction2) /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! Edited January 6, 2021 by Tekken Added test example. + added github 2 6 Link to comment
Scripting Moderators ds1-e Posted January 3, 2021 Scripting Moderators Share Posted January 3, 2021 (edited) It would be nice to mention that's possible due of work of @Einheit-101 and @Saml1er Edited January 3, 2021 by majqq 2 Link to comment
Tekken Posted January 3, 2021 Author Share Posted January 3, 2021 I was looking for the credits but couldn’t find them thank you very much I will update as soon! Link to comment
RekZ Posted January 5, 2021 Share Posted January 5, 2021 (edited) I think the min_version is wrong and if you attach the items in another resource using "exports", when you restart the resource where you create the objects the attachtobones resource give errors, for what I tested it works fine with multiple players. Not starting resource attachtobones as <min_mta_version> section in the meta.xml contains invalid version strings Edited January 5, 2021 by RekZ Link to comment
Tekken Posted January 5, 2021 Author Share Posted January 5, 2021 Thank you, I will take a look later, the versions I took from wiki "onClientPedsProcessed". I will have to check if objects and/or ped exists and if not to delete the entry from table, will be fixed in the next version. Link to comment
Tekken Posted January 6, 2021 Author Share Posted January 6, 2021 Resource got updated! Link to comment
Scripting Moderators ds1-e Posted January 6, 2021 Scripting Moderators Share Posted January 6, 2021 2 minutes ago, Tekken said: Resource got updated! My suggestion is to put it on GitHub, it will allow us to see changes you've introduced. And in addition suggest any code changes (e.g performance wise). Link to comment
Tekken Posted January 6, 2021 Author Share Posted January 6, 2021 Just now, majqq said: My suggestion is to put it on GitHub, it will allow us to see changes you've introduced. And in addition suggest any code changes (e.g performance wise). Well here we go https://github.com/mihayy5/attachToBones I'm sure there is a lot to be improved so take a look. Link to comment
Tekken Posted January 7, 2021 Author Share Posted January 7, 2021 GitHub version got some optimizations, thank you @majqq Link to comment
Tekken Posted January 9, 2021 Author Share Posted January 9, 2021 Both community and github got some optimizations go ahead and check them out! Thank you to @majqq Link to comment
Gordon_G Posted January 9, 2021 Share Posted January 9, 2021 (edited) Great work I've personnaly manually updated my bone_attach resource the exact day when the onClientPedsProcessed got realized. I've immediatly seen the difference. Now attached elements are totally synced with the ped movement because when you use onClientRender or onClientPreRender you have a little delay beforce re-positionning the attached obj when the player moves very fast (like aiming). Edited January 9, 2021 by Gordon_G 1 Link to comment
Lergen Posted January 13, 2021 Share Posted January 13, 2021 Always good to see stuff like this, script optimization is something that's often overlooked despite how important it can be. Props to your good work and for keeping it open-source. Link to comment
Einheit-101 Posted January 17, 2021 Share Posted January 17, 2021 Good work. I was waiting for a long time for this bug to get fixed so i could write a better bone attachement function. 1 Link to comment
Tekken Posted January 17, 2021 Author Share Posted January 17, 2021 7 minutes ago, Einheit-101 said: Good work. I was waiting for a long time for this bug to get fixed so i could write a better bone attachement function. Thank you for your work! Glad you released it! 1 Link to comment
Tekken Posted January 22, 2021 Author Share Posted January 22, 2021 Update v1.4 -Added all bone_attach exported functions; -Added all functions to client side; -Even more optimization; Available functions: attachElementToBone(element, ped, bone, offx, offy, offz, offrx, offry, offrz) detachElementFromBone(element) isElementAttachedToBone(element) getElementBoneAttachmentDetails(element) returns a table with {ped, bone, offx, offy, offz, rotationMatrix}; setElementBonePositionOffset(element, offsetx, offsety, offsetz) setElementBoneRotationOffset(element, offsetrx, offsetry, offsetrz) Note: all functions are available client side! They're not synched with all clients! DOWNLOAD Cheers! Link to comment
Mimimiguel Posted January 22, 2021 Share Posted January 22, 2021 First of all, nice job, really appreciated I have a question, why is not compatible with the old offsets? Is there any feasible workaround to work with them? I'm really interested in improving the performance of the bone_attach resource, since in my server is probably one of the most resource consuming script for the users, but, reworking all the offsets would be hours and hours of work. Thanks! Link to comment
Tekken Posted January 22, 2021 Author Share Posted January 22, 2021 Thank you, well while I have tested and it does worth the work as you will get about 50 to 60% better performance even more maybe, the offsets are not compatible as this resource calculates position by bone matrix and the bone_attach resource had some custom functions made for this. There might be a workaround but I’m a little nul when it comes to maths so I can’t say how, that’s why we have put up a github page, is someone known how they’re free to contribute. Link to comment
MTA Anti-Cheat Team Dutchman101 Posted January 22, 2021 MTA Anti-Cheat Team Share Posted January 22, 2021 It would be interesting to see a performance comparison between this and pAttach (just like this, another recent "bone_attach" replacement by @Patrick) Link to comment
Tekken Posted January 22, 2021 Author Share Posted January 22, 2021 3 hours ago, Dutchman101 said: It would be interesting to see a performance comparison between this and pAttach (just like this, another recent "bone_attach" replacement by @Patrick) Will do with all 3 of them just to see the differences. As Patrick did some days ago. Link to comment
Moderators Patrick Posted January 22, 2021 Moderators Share Posted January 22, 2021 7 hours ago, Tekken said: Will do with all 3 of them just to see the differences. As Patrick did some days ago. I uploaded a new version of pAttach (1.1), please use that version if you do it. I ran all tests again with the latest versions of resources, you can find new results in my thread. And there is a typo in your resource (version 1.4), m_rad is not defined. I defined it for myself to run the tests. Link to comment
Tekken Posted January 23, 2021 Author Share Posted January 23, 2021 18 hours ago, Patrick said: I uploaded a new version of pAttach (1.1), please use that version if you do it. I ran all tests again with the latest versions of resources, you can find new results in my thread. And there is a typo in your resource (version 1.4), m_rad is not defined. I defined it for myself to run the tests. Well I run the tests and I get about the same results as yours so @Dutchman101 you have the results! Also may I or not discontinue this resource? as pAttach gives better performance? I personally don't like OOP so I may try to rework the table structure as this is I think the most harmful part performance wise. Thank you. Link to comment
MTA Anti-Cheat Team Dutchman101 Posted January 26, 2021 MTA Anti-Cheat Team Share Posted January 26, 2021 On 23/01/2021 at 19:07, Tekken said: Also may I or not discontinue this resource? as pAttach gives better performance That's up to you.. i would advise you just add a line about it to your OP, and preserve this resource. Maybe someone (for any technical or bug reason) has no choice but to use an alternative to pAttach in the future, and maybe you can still come closer to (or even surpass) its level of performance by updates with tweaks to attachToBones in the future. So for the latter, you might not even want to discontinue development. 1 Link to comment
Tekken Posted January 26, 2021 Author Share Posted January 26, 2021 Yes that’s what I’m gonna do, thanks! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now