altv-issues
altv-issues copied to clipboard
Store current components of alt.WeaponObject
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