Wanting to create different types of Ammo

Happy Saturday, Everyone!!

I was hoping I could pick your brains with regards to an ammo system. Currently, I have AmmoCurrent and AmmoMax. These variables are saved within my Gun_Parent. From there I can go into my Gun_Children and tweak their ammo capacity, projectiles, etc. Everything was going well until I realized I had no idea how to give these guns different ammo types. Most of the tutorials that I have watched have stored the Ammo within the CharacterPlayer so they’re hard to follow along to. I’m trying to figure out how to create various types of ammo and assign them to the guns and eventually assign them to ammo boxes. This is what I have so far.

This is as far as I was able to get. Every gun shares the same ammo. I was hoping to tackle this issue with your help as I have been stumped for a few days now.

I really appreciate your help!! Thank you.

I’ll go ahead and move the variables over to the PlayerCharacter to sync up with what others are doing. From there… How can I create / incorporate the various ammo types into my game? When I was making my FireBullet Function I couldn’t figure out how to switch the BP’s of the Gun_Children. As it turns out all I had to do was Right Click on the Spawn Actor Class and Promote to a variable!! Then within the children I could assign the Projectile. It took me a week to figure that out… I felt so silly. I wonder if there’s something like that within the ammo I’m just missing. So far it has been a lot of trial and error. So any tips you could offer I would greatly appreciate. Thanks!!

the tutorials store the ammo in the character since it makes sense to store the information there and its easy to reference. what is it you dont understand? maybe we can explain certain bits in greater detail.

the simplest solution would be to create a variable for each ammo type (say pistol, rifle, shotgun) in the character. this way you just have to have your guns get the actor that is holding the gun and firing and decrement the specific variable.

in the below example you will see a quick method i threw together. as you can see in the second picture i made a variable for each ammo type. more on the second picture in a minute. the first picture shows how things could be done within the gun. in the gun i used a custom event fire which will be called to fire the gun and the event has a input of the fpscharacter type (where we have the ammo variables). the gun also has a ammo type variable which is a enumeration of the ammo types (basically a list). ok so you would set the ammo type variable depending on the type of weapon, it just tells which kind of ammo should be used when the weapon is fired. so on fire we get ammo type and select the variable from the character, then we check to ensure ammo is greater than 0, and if it is we decrement the ammo, and finally do the script to fire the weapon. it sounds confusing i know and i didnt explain well but its not too hard.

anywho back to the second pictures script. the script shown here is one method to add ammo via pickups. you have a ammo bp actor and then just have it call the addAmmo event and specify the ammo type and amount. the amount is added to the current ammo then clamped to a max amount and set.

sorry if this is poorly written and confusing, im pretty tired atm so ill try to clarify it a bit in the morning.

I cannot thank you enough for taking the time!! It means a lot more then I could say. It’s scary / intimidating trying to figure things out it’s awesome when someone steps in to help fill-in the blanks! That gives me a lot to tinker around with.

So I was going to put your suggestion after my FireBullet Function within the Gun_Parent. I created a few ammo variables within my PlayerCharacter. I also created an Enum for AmmoType. I’m not sure how to move forward with that (Enum?) that you called directly after the Ammo Variables. I’ve never seen that before… I couldn’t find it.

i have one question how would you go about doing a reload function with this kind of set up cheers