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.
ClipAmmo (ie 2 when you can fire two more shots before reloading)
MaxClipAmmo (ie 30- the maximum number of shots you can fire before having to reload)
StoredAmmo (ie 550 - the backup ammo that acts as a pseudo inventory)
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.
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.
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.
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.