Replenishing Ammo

I simply can’t get my head around how to increase my current ammo and keep replenishing it without it going above the “max” current ammo. Any ideas for a solution? It’s probably just adding a float but i honestly can’t get my head around where i should add another float and etcera.

TL;DR Problem with ammo and can’t figure out simple solution. :confused:

Video & Images

Ammo Bar Function

Ammo Decrease Function
AmmoDecreaseFunction.png

BombAmmo

UsingAmmo

IncreaseCurrentAmmo (Buff/PowerUp)

Create a branch that checks if it’s larger than max ammo, and if yes, sets it as max, and if no, just adds the wanted amount :slight_smile:

Could you make a node, cause i’m really spacing out and my brain isn’t making any sense at the moment. :confused:

Something like this.

Use a clamp node you input the minimum and maximum values and it will clamp the variable to those values

I’m honestly so clueless, by previous nodes do you mean the "Switch has Authority and the “InputAction” ?
I tried to do something like your picture but failed horribly. Please make it crystal clear. :smiley:

As mentioned earlier can you try to make a node, for where i would place that clamp?

Sorry not at my computer at the moment so I can’t will try and post later

Lets say CA = current ammo and MA = max ammo.
You want to add 5 ammo to CA but CA <= MA.

Use a clamp node (Clamp (float) | Unreal Engine Documentation) :
Value: CA + 5, Min: 0 , Max: MA. After that , set the CA to the return value.

Put a Clamp Integer node down. Plug Current Ammo into the top input. Plug Max Ammo into the bottom input. Plug Set Current Ammo into the output. Replace that Branch with this node.

You are done.

Clamp will keep the value you input between the minimum and the maximum inputs. It will then send that information through the output. The value will never go lower or higher than what you have clamped it to within that node.

What happens to the value after the node is finished is beyond the Clamp’s scope.

Is this correct?

Exactly. Except change it to a Clamp Float. Wasn’t paying attention to the type of variables you had. But yes, that is exactly what I meant.

Forgot to add 1 to the Current Ammo, but other than that…

It does work, but it makes the player able to continue spawning bombs which is not what i want. While we’re at it, would you have any clue on how to replenish a bomb after it is destroys itself? In other words. The max ammo is always 4, and the buff blueprint increase your “max current ammo” by 1. So let’s say, i spawn and i begin with 1 current ammo and it will stay that way until i pick up a “ammo buff” does the clamp save the “Max current ammo” and how would i then make it replenish itself to the max current ammo after the bomb has destroyed it self?

UPDATE

Finally made the **** thing work, will have to do some tinkering and etcera to make it perfect. But the it finally works! Thanks for the help fellas.

Haven been at the forums until now.
Glad to see you made it work :slight_smile: