How to retrieve ammo in clip?

jabobwhitey

New member
Hi there! I'm loving the controller, makes my life so much easier!

I am currently building some basic UI components for my game, and need to show both the amount of ammo in the inventory as well as the amount of ammo already in the clip for the currently equipped weapon. I searched the forums/doucmentation and couldnt seem to find anything!

I am retrieving the bullets from the inventory with the following:

inventory.GetItemIdentifierAmount(bulletType)

And using the OnInventoryAdjustItemIdentifierAmount and OnItemAbilityActive to check for changes.

But is there any API I can use to get the ammo in the clip?

Thanks!
 
Hi there! I'm loving the controller, makes my life so much easier!

I am currently building some basic UI components for my game, and need to show both the amount of ammo in the inventory as well as the amount of ammo already in the clip for the currently equipped weapon. I searched the forums/doucmentation and couldnt seem to find anything!
For an example take a look at the SlotItemMonitor.OnEquipItem. This method will loop through the ItemActions to get the loaded ItemIdentifier, which is located on the IUsableItem.
 
Amazing, thank you. I can now get the consumable and inventory amount. I am seeing a strange issue though. It seems when the pistol is fired the consumable amount doesn't decrement, and instead only goes down after the next shot. It then reloads when the bullets get to 1 instead of 0. Any idea why that might be happening?

Here is my code for retrieving the consumable/inventory ammo:

Code:
private void UpdateAmmoCount()
    {
        if (weaponType == WeaponEnum.Unarmed)
            return;

        ItemAction itemAction = activeItem.ItemActions[0];
        if (!(itemAction is IUsableItem usableItem))
            return;

        if (usableItem.GetConsumableItemIdentifier() == null)
            return;

        int consumableCount = usableItem.GetConsumableItemIdentifierAmount();

        switch (weaponType)
        {
            case WeaponEnum.Pistol:
                {
                    Debug.Log("Pistol fired");
                    int ammountInInventory = inventory.GetItemIdentifierAmount(bulletType);
                    ammoCountText.text = consumableCount.ToString() + " / " + ammountInInventory.ToString();
                    return;
                }
        }
    }
 
When is UpdateAmmoCount called? It should subscribe to the OnItemUseConsumableItemIdentifier which will happen after the ammo has been consumed.
 
Ah, sorry! Found it, in ShootableWeapon. If anyone comes across this the future, you can subscribe to the event like so:
EventHandler.RegisterEvent<Item, IItemIdentifier, int>(character, "OnItemUseConsumableItemIdentifier", OnItemUseConsumableItemIdentifier);
 
Top