How do I implement refilling max ammo when I pick an item off the floor, CoD style?

Hi everyone! I’m very new to Unreal Engine! Started since March 2023!

I’m making a Top-Down zombie shooter and I got stuck on how to refill the max ammo to max like Call of Duty? The pickup item is fine. It’s just when my BP character is about to run out of ammo and go to pick it up, it refills the current ammo and not the max ammo. Here is what I have so far. Ammo (current) is 30. Max Ammo (the one I’m trying to fix) is 80. Starting Ammo (was informed to put that there when game starts) is 0.

Can you help me please?

You should have four variables:

  1. ClipAmmo (ie 2 when you can fire two more shots before reloading)
  2. MaxClipAmmo (ie 30- the maximum number of shots you can fire before having to reload)
  3. StoredAmmo (ie 550 - the backup ammo that acts as a pseudo inventory)
  4. MaxStoredAmmo (ie 600 - the maximum amount of ammo you can store. Kinda like a weight limit)

In green is ClipAmmo, in red is StoredAmmo. Games typically don’t show the max ammo count.
image

Ignore how all of my variables are floats- just like you have, they should be integers.
Get rid of that “Starting Ammo” variable. I’m not sure who informed you to put that there, but you should not. It seems to be acting as a maximum ammo counter as opposed to the Max Ammo variable. These are really problematic names.

The max values (MaxClipAmmo & MaxStoredAmmo) should never be changed at runtime.


Shoot should subtract 1 (decrement) from ClipAmmo and shoot if ClipAmmo is greater than 0.

Reload finds the maximum amount of ammo we can reload adjusts ammo accordingly

The ammo pickup should simply add to stored ammo without going over the cap

Should I put everything in the BP character blueprint or in their respective blueprints? ie, Ammo in Item blueprint, Gun shoot in Gun blueprint?

Also, where do I find Local Var Reload Amount?

This is what I got so far:

All of these variables should be in the gun blueprint. Unless you have a proper inventory system for the stored ammo- but what I just showed you isn’t compatible with an inventory system as is.

Local Var Reload Amount is a local variable. Meaning a variable only within the function. You should just name it ReloadAmount- I was hoping the Local Var would hint at what it was. image

You can get rid of that Set Max Clip Ammo node. If you notice, it’s not actually doing anything.

Also, don’t forget to comment on your nodes. Working on long strings of mathematics nodes, you’ll often get lost- having comments reduces the time you stay lost. Though this isn’t super long, they’ll still be helpful.

1 Like

You were right, Mr. Rokenrock! Not only that, I also found out I had to update the ammo text and I forgot to do that! ><

I got rid of all the extra stuff, renamed and placed them accordingly in their respective blueprints.

Once again, I thank you! You’re awesome! :slight_smile:

1 Like