x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.alt textalt text

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.

Product Version: UE 4.21
Tags:
01.png (403.7 kB)
02.png (334.1 kB)
more ▼

asked Feb 02 '19 at 11:41 PM in Blueprint Scripting

avatar image

inaudiblefuzz
1 1 1

avatar image ThompsonN13 Feb 03 '19 at 01:17 AM

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.

avatar image inaudiblefuzz Feb 03 '19 at 01:39 AM

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!!

avatar image ThompsonN13 Feb 03 '19 at 02:22 AM

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.

alt text

alt text

capture.png (187.0 kB)
capture1.png (273.4 kB)
avatar image inaudiblefuzz Feb 03 '19 at 02:25 AM

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.

avatar image inaudiblefuzz Feb 03 '19 at 02:43 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question