altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

Store current components of alt.WeaponObject

Open GVMP opened this issue 1 year ago • 0 comments

Description of the problem

Right now we only have

public giveComponent(componentType: number): void; public removeComponent(componentType: number): void;

The only issue now, if you want to update some components on the existing weapon, you have to manually store a list of current components by yourself or remove the whole WeaponObject and re-create it with the updated components.

Desired solution for the problem

if(this.attachedWeapons.has(attachWeapon.hash)) {
    const attachedWeapon = this.attachedWeapons.get(attachWeapon.hash);
    const toRemove = attachedWeapon.components.filter((s) => !attachWeapon.components.includes(s));

    for(const remove of toRemove) {
        attachedWeapon.removeComponent(remove);
    }

    const toAdd = attachWeapon.components.filter((s) => !attachedWeapon.components.includes(s));

    for(const add of toAdd) {
        attachedWeapon.giveComponent(add);
    }

    return;
}

Alternatives you considered

No response

Additional context

No response

GVMP avatar Jan 30 '24 09:01 GVMP