-
Notifications
You must be signed in to change notification settings - Fork 28
Attachments
Attachments are capable of changing model bodygroups and parent external models at the same time.
A few types of base attachments are provided by default, you can always find the available types here:
All the base attachment classes are abstract, you have to create a new class and derive it in order for it to show up in the component list. Every attachment component needs a unique name (this is the identifier used to match them), then you can choose to use bodygroups, external models, or both at the same time (e.g: remove the weapon ironsights when you want to attach a scope)
[Title( "Reflex Sight" )]
public class ReflexSightBG : SightAttachment
{
public override string Name => "Walther MRS Reflex";
public override string IconPath => "attachments/swb/sight/reflex/ui/icon.png";
public override string BodyGroup { get; set; } = "sight";
public override int BodyGroupChoice { get; set; } = 1;
public override int BodyGroupDefault { get; set; } = 0;
// Sight
public override float AimPlayerFOV { get; set; } = 50f;
public override float AimSensitivity { get; set; } = 0.5f;
}
More examples can be found here: https://github.com/timmybo5/simple-weapon-base/blob/master/code/DemoAttachments.cs
You can now add your newly created component to your weapon object
Equipping an attachment by code is instant and you can do so with the following code:
var attachment = weapon.Attachments.Find( a => a.Name == "Walther MRS Reflex" );
attachment.EquipBroadCast();
To unequip you just call:
attachment.UnEquipBroadCast();