Multiple damage types and pick up

1st – im still very new to blueprinting / unreal engine so please bear with me.

I am trying to make a tank game that is sort of like the old school crash team racing the ability to pick up different ammo types and amounts and a general ammo.

I have the general ammo figured out.
I also think i have the different ammo types figured out. (using a parent blueprint.)

BUT what im running into is how do i do something along the line of only having 10 ammo instead of endless?

(Does that make sense?)

If you mean amount of ammo, you need to create an integer variable on your tank weapon (or tank weapon component), and have it decreased every time you fire a bullet. If the variable reaches 0, then don’t let the weapon spawn projectiles (or linetraces).

i made a little script that shows the basics of what vorixo described. in the picture the 1 key would be the one that you use to fire your weapon. on fire you first get your ammo and see if its greater than zero (basically do i have ammo), if this is true then we can fire the weapon. the actual firing of the weapon part of the script is dependant on your situation but the important bit here is that you decrement (value - 1) the ammo variable so that the next time you press the one key you will have one less ammo.

i also added a little script at the bottom for adding more ammo and making sure that it doesnt go over a set limit.

thank you so much!! I’ll put it in and see how it works and let you know! thank you so much for the quick response too!

Ok so looking at it, how does the tank realize which ammo its picking up? do i need a sequence you think?

it depends on how you have the ammo types stored. does each ammo type have its own variable or are you going to use an array to store the ammo inventory? in either case i would probably just add another input to the event for type. then you could use an array with each index representing a different ammo type, or you could use a select or switch on enum. you could also use a struct which could contain all the info about a round if you wanted to. theres a ton of ways to do it.

the picture shows one method using an array where each array index would be a different ammo type.

this is what im running at the moment.

Link to google photos since its not letting me upload here…

which would you suggest that would be easier on the program to run? ammo types or array?
just to explain a little bit more, im trying to have 5-6 different ammo types with variable differences of speed, damage, how many come in the ‘pack’ and delay time.

i have the numbers all figured out i just dont know How to implement it. if i should have separate ammo blueprint assets for each item (and if so how to call those in when.) or if there’s a list / tag i can use.

i would probably make each ammo type its own blueprint and they should all derive from a common parent. so you would make a ammo base class then create a child class for each ammo type.

as for whats easier to run or more optimized i couldnt really say im not a pro and i mainly focus on creating and prototyping things so i havent gotten to much into optimization. it also depends on how its implemented.

oh also your link doesnt work it gives a 404 error.

of course it gives an error. everything is being difficult with this thing.

well now theres quite a few errors here. first in the images on the left you are setting the variables to their current value so you are basically accomplishing nothing there. theres also no need to set those values as your going to want to have default values anyways. ammo count also isnt needed in these blueprints either as ammo count is only relevant to the tank bp. speaking of, on to the tank bp. your special shot event is set to only be true when the ammo count is less than 0 which is backwards you want it to be true when your ammo count is greater than 0 (thats my fault since i did it wrong in the example). as for the ammo pickup event your getting errors because there is no valid input object.

ill try to make a comprehensive example and post some pics or something to help you out in little while.

thank you so much!!!
as a valid input object would that be like the capsule collider?

nope, in your case it would need to be an instance of the bp_speedammo for that cast to work. so basically it would need to be a actor that exists in the world.

ok so first things first, in the tank bp we need to create the variables for the ammo inventory for each type. in the first picture below you will see that i made a variable for SpeedAmmoCount, MaxSpeedAmmo, GrenadeAmmoCount, and MaxGrenadeAmmo. these will all be used in the ammo pickup item at the end. i also created a variable AmmoTypeToUse which we are going to use to switch between the two ammo types (equipping one or the other). for a basic equipping / swapping ammo type i used the 1 key as the input event then plugged it into a flip flop (every time theres input the flipflop uses a different output pin), then set the AmmoTypetoUse variable to either 0 or 1 (0 = speed, 1 = grenade). now for the fire script i used the 2 input key which goes into a switch. the switches output is determined by the ammo type variable. then the script checks to make sure that there is ammo of the required type and if there is the ammo is decremented and a projectile is spawned. this section could be turned into a function to simplify the script.

now for the projectiles i made a base projectile which contains a collision component, a mesh, and a projectile movement component (this was all based on the first person projectile so values based on that). all i did here was to add a damage variable so that damage can be changed dynamically if you wish and so damage can be set in children. then i added a a on hit event which applies damage to the hit actor. a note here for when you create a child of this bp for the speedAmmo, if you want to increase the speed of the projectile you just need to set the initial speed in the projectile movement component as seen on the right.

the last blueprint i made was a AmmoPickup. for this i used a on overlap event then casted to the tank class. the cast here takes the actor that is overlapping the ammoPickup and checks to see if its of the tank class. if the overlapping actor is of the tank class then we get the current value of the ammo type that we want to add to then add a specified number to it (ammo to add variable) then we use the clamp to make sure that we dont do over the max ammo amount. lastly we set the ammo count and destroy the pickup actor. for the other ammo types you would just make a copy of this blueprint then change the variables. i guess i should also add that i get the variables of the tank by dragging off the as tank pin and searching for them.

this may not be well explained and let me know if it isnt. i wrote it and created it pretty quick. i personally would have tried to make things a bit more complex in the tank class but thats just to make it more modular. i just kept it simple and brute forced here for the sake of simplicity and time. but anyways its getting late here so let me know if you need help or have questions and ill see what i can do to help out tomorrow.

1st. Thank you so much!!! You are beyond amazing and awesome!! do you have a youtube / something i can follow you at?
I know its stupid, i know there’s a way to, but cant remember how to change the variable like this…

actually got most of it, but this one part wont connect. any idea why / how?

i dont know what Im missing… it wont connect and is giving me this error.

you have been amazingly helpful. and i really really appreciate it.

So to activate ammo speed, i put the pick up speed blueprint in environment?

those variables are within the tankBP so you need to drag off of the cast node then search for them. so drag off the as tank pin (or your equivalent) and when the search comes up type in get speedAmmoCount (or whatever your variable is called) it should be near the bottom of the list. that covers the nodes themselves as for the dot circled in the lower left thats just a reroute node. you can get a reroute either by dragging off and searching for reroute or you can just double click on the wire between to nodes to create one.

as for having a youtube channel ive thought about it but just havent done it yet.

the variable your trying to set isnt a variable from the tank class its from the ammo class. thats why your getting the error. what you want to be setting is the same variable that you got and added to, the SpeedAmmoCount variable.

i dont know what you mean by activate ammo speed. the pickups are just an item for adding ammo like what a healthpack would be in other games. then theres a blueprint for the speed projectile which is different as the projectile is what will actually be fired.

im really sorry im stupid thick lately >.< . i have part of it working but its not keeping track of the amount special ammo after being used.

(I have the pick up count at 5, it only shoots 2 then switches to grenade/not enough grenade ammo.)