How To Get Clip Size

SteveC

Member
Hey y'all!

Was having an issue getting clip size to display in a HUD UI. I'm listening to the event:
Code:
EventHandler.RegisterEvent<Item, ItemType, float> (m_Character, "OnItemUseConsumableItemType", OnUseConsumableItemType);

And inside that, I'm just testing what I'm getting from the event (this script is a modified version of SlotItemMonitor and inherits from ItemMonitor ):
Code:
protected override void OnUseConsumableItemType(Item item, ItemType itemType, float count)
        {
            if (item.UIMonitorID != m_ID || itemType != m_ConsumableItemType) {
                return;
            }

            //m_LoadedCount.text = count.ToString();
            Debug.Log ("count: " + count);
            Debug.Log ("item.name: " + item.name);
            Debug.Log ("itemType.Capacity: " + itemType.Capacity);
            Debug.Log ("itemType.name: " + itemType.name);
        }

I'm using a slider w/ a text field, and "count" works perfect to return the current ammo count, but I can't seem to return a max clip size using these fields:
Code:
item.ItemType.Capacity
itemType.Capacity

What I'm hoping to achieve is to return the two as strings to concatenate and display as something like "14/30" (CurrentAmmo/MaxClipSize), and calculate a number between 0-1 w/ it for the slider.

What's the correct way to return the clip size for a given item?

Thanks much!
 
Last edited:
The clip size exists on the ShootableWeapon which is an ItemAction. You'll want to loop through all of the ItemActions attached to the Item and then get the ClipSize property if that ItemAction is a ShootableWeapon.
 
Thanks, Justin! Here's my working test:

Code:
protected override void OnUseConsumableItemType(Item item, ItemType itemType, float count)
{
            if (item.UIMonitorID != m_ID || itemType != m_ConsumableItemType) {
                return;
            }
               
            ItemAction itemAction = null;
     
            if (m_ItemActionID < item.ItemActions.Length) {
                itemAction = item.ItemActions[m_ItemActionID];
            }

            var usableItem = itemAction as ShootableWeapon;

            string currentAmmo = count.ToString();
            string clipSize = usableItem.ClipSize.ToString ();

            string preparedString = currentAmmo + "/" + clipSize;
            float calculatedSliderValue = count / usableItem.ClipSize;

            Debug.Log ("preparedString:" + preparedString);
            Debug.Log ("calculatedSliderValue: " + calculatedSliderValue);

            m_PrimaryProgressBar.fillAmount = calculatedSliderValue;
            m_PrimaryTextBar.text = preparedString;
}
 
Last edited:
Top