WEBVTT

00:06.830 --> 00:07.910
Welcome back.

00:08.030 --> 00:10.610
Now things are coming along pretty nicely.

00:10.610 --> 00:11.990
We have a nice HUD.

00:12.020 --> 00:14.330
We're showing the abilities that we have.

00:14.330 --> 00:20.480
And now that we have the capability to visualize certain things, it's time to get a little bit deeper

00:20.480 --> 00:26.000
with a couple of important aspects of gameplay abilities, cost and cooldown.

00:26.030 --> 00:33.830
Now, when we launch a fireball, our fireball doesn't actually have a gameplay ability cost.

00:33.830 --> 00:39.980
In other words, in most games you would expect your mana to go down as you spend mana as a resource

00:39.980 --> 00:48.350
to cast a spell so we can implement a cost and a cooldown is also something we're not implementing.

00:48.350 --> 00:55.340
Sure, we can't spam it, but that's only because we're putting a delay in place for our gameplay ability.

00:55.370 --> 01:00.710
Firebolt At the very end, before we end the ability we delay by half a second.

01:00.710 --> 01:02.690
So this is basically a hack.

01:02.690 --> 01:07.080
Without the delay, we could spam this ability as quickly as we want it.

01:07.080 --> 01:10.650
In fact, we could spam it so fast that we could.

01:14.870 --> 01:16.080
Well, do that.

01:16.100 --> 01:21.590
So cooldowns are important and a delay is not a cooldown.

01:21.590 --> 01:26.810
So we're going to implement those in these next couple of videos and we're going to start with a cost.

01:26.810 --> 01:30.770
As a cost is important and we have a mana resource.

01:30.770 --> 01:39.800
So it only makes sense that we spend mana to cast spells so our mana can be affected by a cost and we

01:39.800 --> 01:42.830
implement cost in the gameplay ability itself.

01:42.830 --> 01:49.370
If we click on class defaults and scroll all the way down to the bottom, we have a costs section and

01:49.370 --> 01:53.780
a cooldowns section and notice that both of these have gameplay effects.

01:53.780 --> 01:56.480
That's how cost and Cooldowns are implemented.

01:56.510 --> 01:58.910
They're implemented with gameplay effects.

01:59.090 --> 02:05.990
A cost gameplay effect can be created and assigned right here, and it'll automatically work in a way

02:05.990 --> 02:09.560
that you would expect a gameplay cost to work.

02:09.560 --> 02:13.250
So how do we implement a gameplay cost effect?

02:13.280 --> 02:19.890
Well, we first create the effect and I'm going to create one for our firebolt ability right here in

02:19.890 --> 02:21.660
the Firebolt folder.

02:21.660 --> 02:27.900
I'm going to right click, create a new Blueprint class, search for gameplay effect and choose the

02:27.900 --> 02:35.130
gameplay effect class and call this g underscore cost underscore firebolt.

02:36.290 --> 02:45.380
So we can open the firebolt gameplay effect and all we need to do is leave its duration policy at instant

02:45.380 --> 02:53.180
and add a modifier so we can click plus for the modifiers array, expand it and for the attribute we

02:53.180 --> 03:00.080
choose which attribute is the resource that should be spent to cast this ability.

03:00.170 --> 03:02.980
So in our case we're going to choose Mana.

03:02.990 --> 03:06.770
So we need to find Aura attribute Setmana.

03:06.770 --> 03:14.570
We choose that and we leave the modifier OP at Add and choose a modifier magnitude.

03:14.750 --> 03:21.680
Now we could hardcode a value in here and if we're spending the resource, it has to be negative.

03:21.680 --> 03:25.430
So we're going to put, say, -20 mana.

03:25.790 --> 03:32.210
Now of course you could use a curve table for this and scale it based on the gameplay effects level

03:32.210 --> 03:32.810
as well.

03:32.840 --> 03:40.740
But I'm just going to Hardcode 20 and, and in order to implement this as a cost gameplay effect, all

03:40.740 --> 03:47.130
we do is go over to the Firebolt gameplay ability and set the cost gameplay effect class.

03:47.130 --> 03:51.150
Here we're going to choose GE cost Firebolt.

03:51.240 --> 03:54.360
Now we've assigned a cost gameplay effect.

03:54.510 --> 03:57.930
Now how does this actually get enforced?

03:57.960 --> 04:04.680
Well, there's a function on our gameplay ability that we have to call in order to commit that cost

04:04.680 --> 04:12.260
and we can call that function immediately after activating the ability and it's called commit ability.

04:12.270 --> 04:19.080
Now notice there are several versions we have commit ability, we have commit ability cooldown and commit

04:19.110 --> 04:24.120
ability, cost commit ability will commit both the cooldown and the cost.

04:24.120 --> 04:29.370
And what that means is it will attempt to spend the resources.

04:29.400 --> 04:35.910
In other words, this can fail if we call commit ability and we don't have the proper resources, we

04:35.910 --> 04:39.330
will be prevented from activating the ability.

04:39.330 --> 04:41.670
And this does return a boolean.

04:41.670 --> 04:46.230
And what we can do with this boolean is just print a message.

04:46.260 --> 04:53.490
We're going to print a string and pass that boolean in and see what that boolean value is after calling

04:53.490 --> 04:54.600
commit ability.

04:54.600 --> 04:58.290
So I'm going to compile press play and cast the spell.

04:58.290 --> 04:59.940
Now take a look at our mana.

04:59.940 --> 05:05.790
It has gone down and the server has printed the message true to the screen.

05:05.790 --> 05:06.360
Look at that.

05:06.360 --> 05:06.980
True.

05:06.990 --> 05:15.360
That means that our gay firebolt has reached this commit ability and it has succeeded because there's

05:15.360 --> 05:17.850
enough resources to pay for the spell.

05:17.850 --> 05:19.080
Now we're getting low.

05:19.080 --> 05:21.240
Soon we won't be able to cast it.

05:21.240 --> 05:23.160
It looks like right about here.

05:23.160 --> 05:26.400
Where out of mana or just about out of mana.

05:26.400 --> 05:29.250
It doesn't look like we have enough to pay for the ability.

05:29.250 --> 05:34.290
I'm going to attempt to cast the ability and nothing happens.

05:34.650 --> 05:36.060
Interesting, right?

05:36.060 --> 05:38.820
We don't even get that string printed.

05:38.820 --> 05:43.920
So the return value returns true if the commit ability succeeds.

05:43.920 --> 05:49.350
But if the commit ability does not succeed, it doesn't even reach any farther.

05:49.350 --> 05:51.450
We don't even hit that print string.

05:51.450 --> 05:57.900
Now we can add a print string at the beginning and say ability activated.

05:59.120 --> 06:02.840
And let's see what happens if we spend up all of our mana.

06:03.690 --> 06:06.110
All the way to that last bit of mana.

06:06.120 --> 06:09.270
And now if we attempt to cast.

06:09.300 --> 06:11.850
Look at this, it doesn't even cast.

06:11.850 --> 06:18.780
So even though it's kind of paradoxical, but even though we reach the commit ability, otherwise we

06:18.780 --> 06:23.860
wouldn't be able to check to see if we have any mana if commit ability fails.

06:23.880 --> 06:25.950
This act is undone.

06:25.950 --> 06:30.000
It's as if we never even activated the ability at all.

06:30.330 --> 06:32.690
Kind of crazy right now.

06:32.700 --> 06:36.780
Commit ability, as I said, commits both the cost and the cooldown.

06:36.780 --> 06:43.350
So if we're interested in committing the cost at one point in the ability and the cooldown later on,

06:43.350 --> 06:48.780
we could do that because we have commit ability, cost and commit ability cooldown as well.

06:48.780 --> 06:53.850
But commit ability will do both in one fell swoop if that's what you want.

06:54.710 --> 06:57.020
So I'm going to get rid of those print strings.

06:57.020 --> 06:59.720
And now we're committing an ability cost.

06:59.720 --> 07:03.170
And if we wanted to, we could have that ability.

07:03.170 --> 07:07.340
Cost depend on the level of our ability.

07:07.370 --> 07:13.460
Now game play abilities themselves have a level, and if we use a scalable float, they'll use their

07:13.460 --> 07:14.110
level.

07:14.120 --> 07:20.660
So the question is, is the cost gameplay effect applied at the level of our ability?

07:20.690 --> 07:21.020
Right.

07:21.020 --> 07:26.750
Because we're not applying this gameplay effect, the ability does it automatically with commit ability

07:26.750 --> 07:27.360
cost.

07:27.380 --> 07:35.960
So to answer that question, I'd like to dive into C plus plus and take a look at commit ability cost.

07:35.990 --> 07:44.150
Now here we see it in gameplay ability and I've opened the CPP file and let's see what it does.

07:44.180 --> 07:48.560
It first checks if it should ignore costs which should ignore costs.

07:48.560 --> 07:51.800
And if it does then well, we just succeed.

07:51.800 --> 07:53.600
We don't check the cost.

07:53.630 --> 07:57.630
But then it calls check cost and apply cost.

07:57.660 --> 08:01.320
Now check Cost has a comment that says Last chance to fail.

08:01.350 --> 08:08.190
Maybe we no longer have resources to commit since after we started this ability activation and then

08:08.190 --> 08:09.330
we have apply cost.

08:09.360 --> 08:12.210
Now I'd like to take a look at apply cost.

08:12.570 --> 08:19.800
Here we see apply gameplay effect to owner and here's where we can see what level we're passing in for

08:19.800 --> 08:20.760
the gameplay effect.

08:20.760 --> 08:21.720
And take a look.

08:21.750 --> 08:28.290
We're passing in get ability level, so sure enough that gameplay effect will be applied at the level

08:28.290 --> 08:30.050
of our current ability.

08:30.060 --> 08:39.030
So if we want to, we can have a scalable float, we can have a curve table that will scale our cost

08:39.030 --> 08:41.280
depending on the ability level.

08:41.760 --> 08:42.870
Kind of cool.

08:43.110 --> 08:45.570
And that's going to be your quest.

08:45.600 --> 08:52.050
I'd like you to create a curve table for gameplay ability costs so you can create this curve table.

08:52.050 --> 08:58.530
You can call it cost curve table if you like, and add a cost curve for the firebolt ability and make

08:58.530 --> 09:04.170
sure you scale that manacost based on the level as you see fit.

09:04.200 --> 09:07.680
Pause the video and make this curve table now.

09:10.670 --> 09:18.470
Okay, so I'm going to make a curved table and I'm going to stick it in ability system data.

09:18.590 --> 09:28.460
And this means I need to go to miscellaneous Choose Curve table and this can be a constant curve table.

09:28.670 --> 09:32.930
I'm going to call this city underscore cost.

09:32.960 --> 09:34.390
We could call it ability cost.

09:34.400 --> 09:36.560
I'm just going to call it cost.

09:37.100 --> 09:38.350
Open that up.

09:38.360 --> 09:39.530
We have a curve.

09:39.530 --> 09:44.300
I'm going to rename it to Fire Dot Fire Bolt.

09:44.930 --> 09:55.520
And selecting it, I can click to add my level one value and I'm going to use positive numbers here.

09:55.880 --> 09:58.970
My first manacost will be 20.

09:59.000 --> 10:01.760
I'm going to keep it at 20.

10:01.790 --> 10:05.510
Actually, we'll go up to 25 at level two.

10:05.810 --> 10:09.140
35 at level three.

10:10.170 --> 10:19.440
Let's do 50 at level four, 91, 2150.

10:19.890 --> 10:21.300
We'll do two more.

10:22.100 --> 10:24.980
180 and 200.

10:26.550 --> 10:28.800
And we can take a look at the curve.

10:28.830 --> 10:32.190
And here's what it looks like, a nice step curve.

10:32.520 --> 10:39.810
So now that we have that, we can go back to cost firebolt and for the scalable float, we can use the

10:39.810 --> 10:48.300
curve table CT cost and instead of -20, we are going to use the scale value of negative one as our

10:48.330 --> 10:51.090
CT cost values are all positive, right?

10:51.090 --> 10:59.040
And for the curve, we're going to choose fire firebolt and we can see what that cost is at the levels

10:59.040 --> 11:00.660
zero through ten.

11:02.520 --> 11:03.300
Okay.

11:03.330 --> 11:07.920
Now our ability is given at level one, isn't it?

11:07.950 --> 11:14.040
So really, if we want that ability given at a higher level, let's go and look at where we're giving

11:14.040 --> 11:15.090
that ability.

11:15.180 --> 11:21.090
Here in the ability system component, when we create the ability spec, we're creating it at level

11:21.090 --> 11:21.900
one.

11:21.900 --> 11:28.800
So if we change this to two now, we can take a look at how that affects our cost.

11:28.830 --> 11:31.770
It should go from 20 to 25.

11:33.600 --> 11:35.250
So I'm going to close the editor.

11:36.290 --> 11:37.250
And you know what?

11:37.250 --> 11:40.760
Just to see a more dramatic change, let's put it at a higher level.

11:40.760 --> 11:45.500
Let's do five and we'll go ahead and compile and launch.

11:46.250 --> 11:51.410
And hopefully I have enough mana to pay for this cost at level five.

11:51.440 --> 11:53.240
That's going to be 70 mana.

11:53.270 --> 11:55.910
Let's see if it goes down more.

11:56.390 --> 11:59.070
Sure enough, it goes down a lot more.

11:59.090 --> 12:06.890
So our cost is scaled by the level according to our firebolt step curve.

12:06.980 --> 12:08.990
So that's looking great.

12:08.990 --> 12:12.200
I'm going to go ahead and close out of these.

12:13.090 --> 12:16.270
Tabs will open things again if we need to.

12:16.270 --> 12:18.130
And we have a cost.

12:18.160 --> 12:18.820
Excellent.

12:18.820 --> 12:19.570
Excellent job.

12:19.570 --> 12:24.430
I'm going to change this back so that we're applying the ability spec at level one.

12:24.670 --> 12:29.290
Go ahead and compile that great job and I'll see you in the next video.
