Add ammo cost to shooter modules

Cheo

Active member
Hello, if you've played Half-Life then surely you remember the SPAS-12 shotgun which has an alternate firing mode that costs an additional shell. I was trying to do something similar, but realized that UCC's hitscan shooter module only removes a single bullet from the clip when firing. This feature can easily be added by first adding an ammo cost property like that to the shooter module :

C#:
        [SerializeField] protected int m_AmmoCost = 1;
        public int AmmoCost { get { return m_AmmoCost; } set { m_AmmoCost = value; } }

Then in Fire just add this condition :

C#:
            if (ammoData.Valid == false || ShootableAction.ClipRemainingCount < m_AmmoCost)
            {
                ShootableAction.OnDryFire(m_ShootableFireData);
                return;
            }

I recommend doing something similar in DryFireSubstate.CanStartUseItem, especially when using automatic weapons :

C#:
            if (clipRemaining >= m_AmmoCost)
            {
                return true;
            }

I hope this can be added, as this is not a niche feature in shooter games, we shouldn't have to add that ourselves. Thanks in advance.
 
Last edited:
Thanks for sharing! For this I would actually subclass the module and then override the methods. This will will make updating extremely easy :)
 
Well I was hoping this could be added to the official code - once again this is not a niche feature and it shouldn’t break anything, you would spare other devs the time to add that themselves.
 
Back
Top