altmp / altv-issues

Issues and roadmap for alt:V project
93 stars 16 forks source link

Store current components of alt.WeaponObject #2220

Open GVMP opened 8 months ago

GVMP commented 8 months ago

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