KRISS Vector
An attach hub New
A rail point is a few centimetres wide, sits next to other points, and mounted devices bring their own point on top of it.
The problem
Every slot of the weapon had its own interaction point with an attach action for the compatible items. In practice: the points are 4–9 cm apart, the mounted device has its own point at the same place, and the points jump from one to the next while you aim. The vanilla attach action does not help: it fills the first suitable slot, whatever you look at.
The hub
One point, the default context in the middle of the weapon, offers everything:
- Target action –
HasLocalEffectOnlyScript()returns true: it changes a variable on the client only and runs nowhere else. - Attach actions – one per slot and candidate (the n-th compatible item). Each carries its slot in the prefab and shows only when its slot is the target. The server needs no state.
class MyGun_HubAttachAction : SCR_InspectionUserAction
{
[Attribute("", desc: "Slot this action fills")]
protected string m_sSlotName;
[Attribute("0")]
protected int m_iCandidate;
override bool CanBeShownScript(IEntity user)
{
if (MyGun_Target.Get(GetOwner(), user) != m_sSlotName)
return false; // only the target slot shows its actions
return super.CanBeShownScript(user);
}
}
Candidates
For a slot: the user's items, minus the ones already on a weapon, minus the ones AttachmentSlotComponent.CanSetAttachment() rejects, minus the ones the inventory cannot move
(CanMoveItemToStorage or, for a replace, CanSwapItemStorages), and each prefab only once. Cache the scan for about 300 ms: the UI asks every frame.
Detach
Attachments move back to the inventory with FindStorageForItem() and TryMoveItemToStorage(). Third-party devices bring their own Detach action; the hub only covers the parts that have none.