Well, you could add a timer via script which detects the attack key presses and depends on the rate of fire.
For example, if your weapon fires 3 rounds per second, after 3 seconds you will have spent 9 rounds.
Since it will be timed, the ammo use may be approximate (but it shouldn't be too difficult to set up a float timer) but if it's a
minigun, 20 rounds give or take won't matter much.
When the timer detects that you should be out of ammo, you can disable your attack key until you either press your reload key
(and force the reload animation) or unequip your weapon
Edit: Based on the timer you can also remove from your inventory the approximate ammo spent.
This approach would only really work though if we can set up a more accurate timer, but I'm pretty sure there is a way, I just can't
remember