# Combat and Inventory: Fight with Equipped Weapons

> For the complete documentation index, see [llms.txt](llms.txt).

Equip a rifle from a backpack, fire it, then reload from an ammo stack. Inventory supplies the weapon actor in the player's hand and counts the reserve rounds. Combat uses that actor to fire and tracks the rounds loaded in its magazine. Start with a working [equipment slot](inv-guide-equipment.html) and a [firearm with shooting and reload abilities](cbt-guide-firearms.html).

## Weapon Manager

Procedure: Let equipment supply the active weapon

1. On the character, keep its `NinjaEquipmentManagerComponent` and use `NinjaCombatEquipmentAdapterComponent` as its only Combat Weapon Manager. Return the adapter from Get Weapon Manager Component (`GetWeaponManagerComponent`) on the Combat System Interface. Remove the rifle from Combat's default weapon classes if it was previously spawned there.

2. Give the rifle's Item Definition a project tag such as `Item.Weapon.Primary`. In its Equipment Fragment, add the `Inventory.Equipment.State.Equipped` state. Choose Actor as the presence and assign a Blueprint based on `NinjaCombatEquipmentWeaponActor`. Put the rifle mesh and its Firearm Component on this actor.

3. Let the hand slot accept the item's tag and set its equipped socket. In the combat ability's Weapon Query, require both the item tag and the equipped state. Move the rifle from the backpack into that slot. Combat searches the equipment's tags and returns the first matching weapon actor.

## Weapon Actor

If your game already has a weapon actor, keep its Combat Weapon Interface and add a `NinjaEquipmentActorComponent` to access the equipment and its item. The supplied equipment weapon can use the item's level as its hit effect level. To drive damage from a rolled item stat, read the item's Dynamic Attributes fragment in the weapon's `GetAdditionalCombatMagnitudes` override and add the value under the damage tag your effect reads. In C++, extend `GetAdditionalCombatMagnitudes_Implementation` and preserve the parent's magnitudes. An Offhand Position fragment can also supply the support-hand position for a two-handed weapon.

## Ammo Storage

Procedure: Reload from an inventory stack

1. Add `NinjaCombatInventoryAmmoAdapterComponent` to the character as its only ammo storage component. Create an ammunition Item Definition tagged, for example, `Inventory.Item.Type.Ammo.Rifle`. Add a Stack and Quantity fragment, set a stack limit of at least ten, and enable Can Be Observed.

2. On the adapter, set All Ammo Types Query to include your ammo items. On the rifle's Firearm Definition, set Ammo Query to the rifle ammo tag. The first query tells the adapter which stack changes to watch. The rifle's query determines which rounds it can actually take.

3. Give the backpack ten reserve rounds. Use a full magazine of at least three, fire three shots, and trigger a magazine reload. At the reload notify the magazine should refill and seven rounds should remain in inventory.

For an ammo counter, read `GetAvailableAmmo` with the rifle's query when the widget opens. Bind `BindToAvailableAmmoChangedDelegate` on the ammo storage interface for later changes. Unbind with `UnbindFromAvailableAmmoChangedDelegate` when the widget closes. Combat calls `TakeAmmo` during reload, so the widget only displays the result.

## Try It in Play

Replace the rifle in the hand slot with a second weapon bearing the same primary tag and a visibly different mesh. Fire again and check which actor supplies the shot. Move it back to the bag and verify the slot no longer supplies a weapon. Finally, try reloading the rifle with only an incompatible ammo stack. Its magazine and that stack should both keep their counts.

