Jump to content

2 Screenshots

About This File

Most of the server developers (ones that don't patiently wait for *something large*, though this resource is powerful enough) use their own server-side object attachments implementation that represents some large JSON with all the object and attachment information. This resource lets you cache "static attachments" in the client-side code so thanks to efficient utilization of the shared data it just uses a small shared variable to do the attachment processing without any need to create server-side objects nor send its data.

 

For example, if you want to attach a specific object to specific ped bone with spefic bone offset and object rotation, this will only use a ~4-8 byte shared variable keeping it accurate. User-made implementations I have seen before usually take ~100 bytes per an object.

 

API: Client-side

  • mp.attachmentMngr.register(attachmentId, model, bone, offset, rotation)
  • mp.attachmentMngr.addLocal(attachmentId) (synced!)
  • mp.attachmentMngr.removeLocal(attachmentId) (synced!)

 

API: Server-side

  • player.addAttachment(attachmentId, remove)
  • player.hasAttachment(attachmentId)

 

Example Resource

There's an example resource in /client-packages/epic-attachments folder. It lets you toggle attachments (there are like 30 attachments) using a NativeUI-based menu. Thanks to root for his contributions made to the example resource.

 

 

 


What's New in Version 1.0.4   See changelog

Released

Bug fix

  • Like 11

User Feedback

Recommended Comments

n0minal

Posted

Quick thing to be fixed, at line 9 on clientside you get a error message when trying to use .hasOwnProperty if the entity.__attachmentObjects variable isn't set, just need to check if the variable exists before adding Local:
 

  if(!entity.__attachmentObjects || !entity.__attachmentObjects.hasOwnProperty(id))
H5tred

Posted

If you are getting the error message for .hasOwnProperty

add if "(!entity.__attachmentObjects) entity.__attachmentObjects = {};"

before "if (!entity.__attachmentObjects.hasOwnProperty(id))"

 

  • Like 1
PanaFive

Posted

On 7/26/2020 at 3:28 PM, rootcause said:

To anyone using 1.1 and having a problem with objects spawning but not actually attaching, replace client_packages/static-attachments/index.js with this: https://gist.github.com/root-cause/c68468e47bc8afd4972fb8ab72e7c380

Why i crash after spawn object in hand ?
 

function playerActionAnim(p, b)
{
    function c(a, b, c, d, f)
    {
        mp.attachmentMngr.addClient(p, mp.game.joaat(a));
        loadAnimDict(b, () => { mp.players.exists(p) && 0 !== p.handle && p.taskPlayAnim(b, c, 1, 0, -1, d, 1, !1, !1, !1) });
        if(f)
            setTimeout(() => {
                mp.players.exists(p) && 0 !== p.handle && (mp.attachmentMngr.removeFor(p, mp.game.joaat(a)))//, p.clearTasksImmediately())
                mp.gui.chat.push(`dans fonction C 5`);
            }, f)
    }
    switch (b) {
        case "itemPhone":
            //c("useItemPhone", "amb@world_human_stand_mobile@male@text@base", "base", 49, 600000);
            break;
        default:
            break;
    }
}

mp.events.addDataHandler("animItem", function(a, b) {
    playerActionAnim(a, b)
});

mp.attachmentMngr.register("useItemPhone", "prop_player_phone_02", 28422, new mp.Vector3(.0, .0, -.0), new mp.Vector3(0, 0, 0));

 

PanaFive

Posted (edited)

thanks
 

Edited by PanaFive
Mugala

Posted

client crashes on 1.1 at 'entityStreamIn' event.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...