Welcome back everyone. In this video Our goal is to add the events and write a script to get our player shooting off a fireball. Exciting times. All right, we're going to start off in our project settings here. So jump up to your main toolbar, come under Settings, project settings, and select input along the left hand side, we're going to add a new action mapping at the very top. Let's click this plus button next to action mapping not access mapping action mapping, and we're going to name this black magic.
And we're going to bind two events or two not not events, two buttons to this event. The first one we're going to bind to this is going to be the num one key on the keyboard. The second one that I am going to bind to To make this event happen is going to be our game, pad trigger. gamepad right to trigger that's what I'm looking forward game pad right trigger. So if you got a gamepad that will fire this event off as well. Okay, so with that done, we can exit out of our project settings.
And next we're going to be doing some work inside of our BP player. So come to this directory content Metroidvania blueprints, characters, double click on your BP player to open her up. And in the My Blueprint panel, we're going to add a new graph. So we've currently got a graph for our move set. This is things like our movement, input, jump, landing, back, dash, etc. I want to have a separate graph for our black magic.
So in the graph section, let's add a new graph. Let's call it black magic And it's already open. So let's see what we can add to it. Let's start off with right clicking and adding our black magic events our action event that we just created. So the first thing we want to do after we press this button is we want to check if we've got our black magic actually slot in. Now this is working a little bit ahead.
Upcoming here in a little bit, we're going to be working on putting together a black magic selection menu so you can slot what black magic that you have active and available for use, you're not gonna be able to use all your different black magic like your electro spark and your fireball. At the same time. You can only use one of those when you press the white the right trigger button. So we need to find out which black magic Do we have slotted or that on our HUD that is available to us and we have Have a variable that's going to be storing this information. And our list of variables is getting quite lengthy here, under our player info category, we've got this be magic slotted, okay, we're going to drag that into our graph. If you remember right, we are going to be slotting array over here, we're going to be changing out what is slotted based on the menu screen that we're about to be building a little bit later on.
And we are going to drag out of this in type in switch on IE be magic so when we press the right trigger or the one button we're going to find out what black magic do we currently have slotted into our HUD and based on which one we do, we can do something. In this case we're concerned about the fireball. So we want to kick off some script to shoot out a fireball. A little bit down below this I'm going to right click and create a custom events Add Custom Event. And I'm gonna call this use fireball all caps. Sure.
Now with this Custom Event created, I can call this custom event from here, so I'm just going to type in use fireball. So this is essentially a wireless signal when we press the one button or the right trigger button we're going to see see if black magic slotted is fireball if it is we're going to send a wireless signal to tell this custom event to fire off. The reason I'm using a wireless signal here is because it's just gonna keep our graph a little bit cleaner here. I'm going to left click and drag around this tap the C key call this use black magic for that bit of script. And now I'm going to move our use fireball off to the right here because we're going to be building a lot more script for the time being because we do Want to shoot off a fireball here before the end of the video I'm going to change our be magic slotted I'm going to manually set this to be fireball here too.
If you want to make this instance editable while we're playing the game, let's just change that right there you set that to be instance editable. So while we're playing, we can change that up. Okay, so what do we want to do when we use the firewall? Well, first thing we need to do is we need to check Do we have enough manner to actually use the magic and it's a good thing we created a function for that in the last video, so let's drag and drop this function into the graph. We need to check Do we have enough mana to use this magic now? We need to input our magic attributes here.
So in our magic black fireball category, we've got fireball attributes. Let's plug this right in here. Now if you remember right, this fireball attributes struck at contains information about how much manna does it cost to use this. And in this function that we created the last video here it is check if enough magic to manna to use magic. The attributes that we just plugged in here we're going to break them apart, we're going to find out what their manna cost is. And if it is less than our current manna, we're going to say yes, we have enough manna let's fire off a fireball.
Okay, so we know we're going to need a branch node here. So let's keep the flow of execution going and put in a branch node. Now, checking to see if we have enough man is just one of the things that I want to check. So let's drag off of our enough manna and type in and we're going to bring in an and Boolean because there's three things that we want to see that are true before we're going to allow a fireball to be fired off. So do we have enough manna? That's one Second thing I want to find out is, is our fireball ready to be fired off by default it is.
So we're going to drag and drop that on this pin. Then I'm going to click the Add pin button to add another input over here and the thing that I want to check as well is if we are in missed form or not now we have not scripted anything related to miss yet, but this is kind of working ahead to make sure that this works when this course is all said and done. We're going to bring in this B is using Miss. We're going to get that and we're going to drag off of this and type in the word not. So if we are not in this form, and if our fireballs ready, and if we have enough manna if all three of those are true, then we're going to fire off the fireball more that to come. But if it's not true, what I'm going to do is I'm going to play a sound play a sound 2d And the sound that I want to play is going to be V R and negative Q, that one right there.
This is in your engine content. So if you don't see this particular sound effect, you can come under view options, check show engine content, it should be available for you. So we've got that v r negative Q. And you know what I'm going to right click on this pin, and I'm going to promote this to a variable. Over in our blueprint panel, I'm going to call this s FX. You insufficient manna, even though there could be a multitude of reasons why we were not able to cast this, I'm just going to call it that for now.
My insufficient man of sound, and I'm going to create a brand new category for this in case I want to use it later. And this will be let's call this our magic general category. There we go. And when we promoted that to a variable, it automatically populated that variable with the VR negative cue that we had slotted into this node right here. Okay, so all this is optional. You don't have to play the sound effects.
But I think it's nice to have. Okay, so if this is true, if this all evaluates to true, I want to bring in our function for updating of manna, we want update our manna like so. And I want to bring in doo doo doo doo doo our fireball attributes. plug this into our update manner, like so. And if you remember, update manna function was doing this. We're taking whatever attributes we're plugging in, in this case, it's the fireball attributes.
We're breaking our our attributes in To the manage costs and we're going to be subtracting our manna from our current to update our manna amount. Okay, so after we update the manna, we're going to bring in our be used fireball, drag and drop that in, we're going to set it and we are going to say yes, our player is now using the fireball. Remember, we're using some of these variables to drive our animations. So that's what that one's going to be used for. Then we're going to set our be fireball ready, drag and drop that into the graph, we're gonna set that and we're gonna say it's not ready right now, meaning you can't cast another one right now. You only can cast this one for the time being, then let's bring in a sequence node.
I'm going to hold down the S key, left click to bring in a sequence node. We're gonna make two things happen here. First thing I'm going to break In a delay node hold down the d dS and Dan key and left click we're going to do a short delay in fact I'm going to make this a 10th of a second point one seconds then I am going to spawn actor from class. The actor I want to spawn is going to be our BP fireball that we just created. There is our BP fireball make sure that BP fireball and not the skill be magic fireball BP fireball. Then we need to feed this a transform.
Where do we want to spawn this from? Well, we created a fireball spawn point. So let's left click and drag that in from our components panel. Then off of this, we can drag off and let's get the world transform. And this orange output can be plugged into the spawn transform input of that node. Then what I want to do is I want to play a Sound, play sound at location.
What sound do I want to play? Well, we just imported a sound called fire ball. It is this SF x fireball. Which location do we want to play it at? Well, why don't we play it at the location of our fireball spawn points, I'm going to drag off here again and say get world location. Yellow output means I can plug that into the yellow input.
And then I'm going to set our B use fireball. We're going to set that and remember earlier, we'd set this to true. Well, after we fire off the fireball, we're going to set this back to false. Okay, again, that's to drive some animations for our character that's to come yet. Okay, so off of this a sequence no then then one branch. Won't, I'm going to break off a wire here and we're going to bring in another delay node.
And the delay I want to set this duration for is going to be our fireball cool down, like so. And when this is done, we're gonna say the fireball is ready to be, we're gonna set this we're gonna set this to true again. So remember our fireball cooldown is going to be 1.13 seconds and after that has expired, we're going to say yes, our character can fire off the fireball once again. Okay, so with all this script done, let me just highlight it here to kind of show you what we got here. Maybe you can pause the video here to see the first part and here is the second part that's enlarge that a little bit. Okay, I am going to left click and drag, tap the C key and I'll call this a shoot.
Fireball something like that. Now let's Compile and Save and moment of truth you're testing this out now note, a fireball should appear but the proper anims won't be working yet and there will be no character exertion, noisy yet not a character exertion noise you should hear, you know, fireball shooting out so let's give this a try. Okay, so I need to be sure that I interact with the right Dyess here. Well actually I don't have to because in the upper right, you can see that I've already got the fireball slotted But anyways, let's pretend I've got to interact with that get the skill. Okay, now, tap the one key and you can see that Ball is shooting out. If I turn this way, shooting out and look in the upper right, you can see that my man account is actually decreasing as well as I fire it out.
So if I spam the one key really fast, you'll notice that you're hearing that kind of rejection sound. And that's because in the script, if our fireball is not ready, and I'm trying to spam that button, it's basically saying, hey, you can't use it right now. One of these things is evaluating to be false. Okay, so again, if you tried to test that out, no, it wasn't working. Make sure you got your be magic slotted here, temporarily set to fireball. And we can also test this out live in game.
If I do shift in f1. I'm going to grab my window right here. Let me jump back to the main level editor. Here's my BP player. Now let me go be magic slotted remember, I made this instance this variable instance variable I'm gonna set it now to be electrical spark so now I don't have fireball slot it in. Let me bring my play window once again and you can see in the upper right here I've got electro sparks slotted in and now if I try casting fireball nothing will happen even if I you know collect this fireball skill which I don't need to do right now nothing's going to happen however shift in f1 I changed my be magic slotted back to fireball I will be able to fire that off again I hit the Escape key.
Well, long story short, you will be able to fire it out again. Guys. I think the point is proven. We've gotten a fireball shooting out. So happy, happy day. All right, let's get on to some animations next.
That'll do it all for this one. We will see you in the next One