Conservative Ammo Reloading - #18 Creating A First Person Shooter (FPS) With Unreal Engine 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] good afternoon ladies and gents when you boys versus here and welcome back to another Unreal Engine 4 FPS video in today's video we are going to be creating something called a conservative ammo system so what that is is essentially it's a bit more of a commonly used ammo system similar to Call of Duty and Battlefield so I will try to explain it as best as I can so in the last video we did create an ammo system now when we did shoot and they use some of their ammo what we do is essentially take away the whole clip from the max ammo and put it into the ammo essentially throwing away and losing anything in the current clip that the player hasn't used now what this is the system that we had before is a bit more tactical and it's a bit more realistic however games like Battlefield when you only shoot once or twice it's only going to take one or two bullets from the max ammo and then put it into your current clip which is nice now the reason why they do this is because it sort of stops the player having to think about when they can and can't reload so much it just makes things a bit smoother and so what we're essentially going to be doing in today's video is pretty much converting the current system that we have got and putting it into this new conservative ammo system now bear in mind this video is entirely optional you can choose exactly which ammo system you want it's entirely up to you however to create this one I do advise that you go ahead and watch the last video where we created the lastest reload system with the function the inputs is they're still going to be reusing some of the stuff we had from there so having said that what you want to do is open up your third person character real quick and then you want to get into this reload function now before I do that just know I'm going to be keeping this from the last video so like I said if you haven't seen the last video already you won't have this so make sure you do go ahead and copy that go into your reload animation and then from there what we're going to be doing is pretty much getting rid of all the existing logic for the reload stuff and we're going to be starting from scratch so what we're going to be doing now then before we start anything is we need to create a new ammo variable and that's simply going to be called ammo different now the reason why we're making this is so we can pretty much store the difference between the clip size and the ammo so that the engine knows exactly how much ammo to take from the max ammo and put into the current clip so what we're going to do is set this variable type for ammo difference to integer just to make it exactly the same as all the other ones that we have got so starting from the beginning then what I want to do is pretty much set up a system to check to see whether or not the player actually needs to reload because they haven't fired I don't want to run the code and I don't want it to waste any of their am or anything like that so I'm going to run a quick check and that's going to be checking to see if integer is less than and the two values that we're going to be working with for this is going to be the ammo and the clip size so what this is doing essentially if the ammo is less than the clip size that means they have fired so it's going to return true and then from there we're going to tell it to replenish the ammo if it isn't less than that it means they haven't fired and I'm simply going to tell it to print the string and that string the text for that is simply going to be for ammo so to type that in properly full ammo and that's so good so what I'm going to do now then it's quickly compile this just to test it to make sure it isn't reloading when it doesn't need to so without firing anything to press R and it's going to say full ammo that's so good I'm gonna fire once and now if I try and reload it's not going to do anything free I'm going to code there but it's not returning full ammo either so that's all good so what we need to do now then knowing that that's all set up from working we need to set up all the logic for the reload stuff now so what we need to do then is essentially get the difference between the clip size and the ammo so that we can take that from the max ammo and put it into the current clip so the way that we're going to do this is simply use integer - integer and we're just going to take away one from each other to get the difference so get your clip size at the top hook this up just like this and then at the bottom get your ammo and that's pretty much gonna deduct the difference and then with this what we can do is then check to see if integer is greater than and then hook this up into your B and then if you're a hook this up into your max ammo so what this is essentially doing is checking to see whether or not the max ammo is greater than the difference and the reason why I want to do this is because I need to know whether or not the player can actually you know put the whole difference in there and we're going to turn this into a branch as well so if we hook this up into here for true it's going to run that check and then if it is true we're going to tell it to simply take away the difference from the max ammo and then put it into the current mo and then if it isn't we're simply just going to tell it to put whatever is left into it now this is where our ammo difference comes into play what I need to do with this value here where we're actually getting difference I need to use this to set ammo difference and the reason why I'm turning this into a variable as opposed to just hooking up everything to this is because it makes things easier and also it doesn't store the number sometimes when you're going from so deep into the blueprints it's a bit of an odd one but just use a variable and it makes things so much easier and what you also want to do is copy there so press ctrl-c and ctrl-v to get a second one as we'll need one for both true and then one for false as well so we're going to hook it up just like that leaving a little bit of space now the one at the top here what you do need to do is hook up ammo difference into this over here just like we have done for the other one just so it has a target source so with this nail then so is max ammo is greater than the difference or we're going to do from this is simply set ammo and we are just going to add on the difference so we're going to do integer plus integer with the top value being the existing value for ammo and then the second value is simply going to be your difference so dragon your difference just like that and that's all good so what should happen now if I compile press play and then shoot a couple of times press reload it should go back up to 25 and that's all good however it's not taking that difference away from the max ammo yet so that's something that we need to do pretty much just doing the reverse of this so simply set max ammo and then this time instead of doing integer plus integer you want to do integer - integer as we're takin away from the value so what we're going to do then is get our original max value a max ammo value and then what we're going to do is pretty much to take away that ammo difference from the max ammo just like that so now then if we compile this press play shoot a couple of times fresh reload and you can see now it's only taken away the bullets that's used so if we test this again if we shoot once it should set our max ammo to 99 when we reload and you can see it's down there and it's a bit more conservative and it's not wasting any ammo at all which is perfect now there's only one last step that we need to do and that's the way the player does not have enough ammo to you know reload the gun completely like it needs to be so what we're going to do in that instance is essentially just tell it to add whatever it's got into it so what we're going to do is from this one over here for false on this little line we are simply going to tell it to set ammo and we're simply going to set the ammo to the max ammo so basically it's just taking whatever values in the max ammo and just putting it into the ammo which is all good so what we're going to do now then is from sex we are going to do set max ammo and then from this we are just going to do and just we're just going to set this equal to zero so we're going to leave it exactly how it is now if we're doing this doing it this way it's not always going to work 100% for us and what we need to do instead of just adding on the max ammo that's going to throw away whatever the now already so what I want to do is simply integer plus integer instead so hook this up hook this up and then if we get our original ammo value hook this up in here as well and that will get everything working for us so if we compile this and your code looks exactly the same as mine 100% is going to work exactly as it should so what I'm going to do before I end the video is one last test to quickly see if our reload function is working as it should so I'm going to shoot once just to test this or twice even press reload and you can see the max ammo has gone down that's all good and no matter how far I go through the clip it's only going to take away of a difference so what I'm going to do now then is I am going to go all the way down to the last clip and I'm going to use about half of it and I'm going to make sure that I can still reload properly so ten and seven that's fine press reload and you can see it's now only added on the last bit and that's all good and if I use all my last bullets and try reload it's not doing anything I can't fire again it's not changing from zero and that's so good so having said that that is pretty much everything for the video guys I hope you have enjoyed it just as much as I have once again thanks for watching stay awesome keep creating your boy vs. signing out this series was made possible by you guys supporting me on patreon if you want to help create other series like this and check out my patreon page and your link in the description [Music]
Info
Channel: DevSquad
Views: 41,970
Rating: undefined out of 5
Keywords: Unreal Engine 4, UE4, FPS, FPS Tutorial, FPS Game, First Person, First Person Shooter, Unreal Engine 4 FPS Tutorial, unreal engine, VirtusEdu, Virtus Learning Hub, Game Dev, Game Design, Shooter Tutorial, How to make a FPS game, Beginner, Blueprints, Unreal Engine Tutorial, FPS Tutorial Series, Tutorial Series, Player, Character Animation, Custom Character, Blendsplace, Weapon, Gun, Ak47, AK-47, Weapon UE4, Zoom, Reloading, Ammo, Magazine, Conservative, Reload
Id: 5e13-2C_r_c
Channel Id: undefined
Length: 10min 4sec (604 seconds)
Published: Sun Aug 13 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.