Welcome back.
So we know that we're applying a gameplay effect whenever we launch a fireball and that gameplay effect
is going to result in subtracting from the health of the enemy.
Now that we know about damage meta attributes, we're going to use a meta attribute for damage rather
than having our gameplay effect reach in and change the health directly.
So if I go to blueprints ability system gameplay effects and go to my G damage and scroll down, we'll
see that this is an instant gameplay effect set to subtract ten from the health.
So this is very much a placeholder gameplay effect, right?
It's hard coding negative ten.
We're not even using a curve table or anything like that and we're setting the health, but we'd like
to modify the meta attribute and then allow the attribute set to go through any processing of that data
that we'd like it to do.
And we'd also like to use that damage meta attribute in any of our custom calculations as well.
We can change this to a custom calculation class, for example, as damage is going to be one of the
more complicated types of modifiers.
So anyway, we'd like a damage meta attribute and for that we're going to close the editor and head
back over to our attributes set.
So I'm going to open my attribute set.
I'm also going to close other tabs and get my header and CPP files open here and here in my Aura attribute
set, we're going to create a new attribute and this one will be our first meta attribute.
So just below vital attributes, I'm going to make a multi-line comment that says meta attributes.
And we'll have our first one.
So we'll have a gameplay attribute data called Incoming Damage.
And incoming damage is going to get a new property, but it's not going to get replicated.
It will not get a rep notify as meta attributes are not replicated.
We set them on the server and then on the server we process the data and then change any replicated
attributes.
Based on those calculations, we can make it blueprint read only though and we'll give it a category.
But the category is going to be meta attributes and we can make attribute accessors.
So let's go ahead and use our attribute accessors macro passing in you ora attribute set and incoming
damage.
So that takes care of making the meta attribute.
So how do we actually use the meta attribute?
That's the next thing we'd like to handle.
So let's go into our CPP file and we'll go to post gameplay effect, execute right here and here we
can actually check to see if the evaluated data has the attribute incoming damage and then we can respond
accordingly.
So down here at the bottom we'll just place an If check and say if data dot evaluated data dot attribute
equals and we'll use get incoming damage attribute.
So here we know that we're actually getting a change to incoming damage.
Now incoming damage being a meta attribute should be used for its value and then reset or zeroed out.
In other words, we're going to consume that data.
So to do that, we usually make a local float variable that has the value of incoming damage.
So we could make a const float called local incoming damage and set it equal to the result of get incoming
damage.
So we're getting its float value.
So we're caching that value locally and then we can set that meta attribute to zero so we can say set
incoming damage and we can pass in zero.
So now that we have local incoming damage, we can decide what to do with it and we should only really
do anything if its value isn't zero.
So we're going to check if local incoming damage is greater than zero.
And in that case, we can do something.
Now, so far, we have really nothing to do with this meta attribute except to use it to set the health
value.
So we can do that.
We can set the health value and we can even handle any additional clamping as well.
We can make a const float called New Health and calculate what the health should be now and what that
should be is the result of get health minus this local incoming damage.
And we can make sure that that is not going to be a negative value.
So when we call set health, we can call set health with an F math clamp.
Clamping the value.
New health between zero.
And Maxhealth so we can call get Maxhealth.
Now, here's the cool thing.
At this point, we can tell certain things about the damage that has been done.
For example, if new health is now zero, then we know that this damage caused was fatal.
In other words, we could do something like const, bool, be fatal equals new health.
Less than or equal to zero.
Because if new health is less than or equal to zero.
Well, we know that be fatal is going to be true.
If enough damage was done to kill the owner of this attribute set.
So that's kind of neat.
Now we'll be doing more with our meta attribute, but this is the backbone.
This is the basic framework of how it should work.
We use the meta attribute instead of changing health and our gameplay effects that currently affect
health are now going to be changed to affect the meta attribute on the target and they'll be adding
to it.
They won't be subtracting because we do the subtraction here.
Our new health is our health value minus that local incoming damage.
So why don't we change our damage gameplay effect so that it's now using our meta attribute?
We can go ahead and compile and launch the editor.
So back in the editor, we can open up g damage and we can scroll down to its modifier.
And now instead of setting the health attribute, we're going to use incoming damage.
And instead of a negative value, we need this to be a positive value.
I'm going to make it a little larger.
Let's make it 25 and compile and we can do some damage.
I'm going to go ahead and launch a fireball.
And there we go.
We see that it's affecting the health.
We're subtracting 25 from it all because we're adding to that damage meta attribute.
So the damage meta attribute is essentially zeroed out, each frame consumed to be used in calculations
regarding damage.
Now, of course, we can get down to zero life and we haven't programmed anything for death.
We haven't programmed any hit reaction, anything like that.
Those are things that we'll get to.
But now at least we're doing damage with a meta attribute, and that allows us to do lots of things.
We can check the amount of damage done.
We can also perform custom calculations with the damage.
We have options.
All right.
So G damage is looking better.
However, we're still hardcoding 25 for the damage and it would be nice if this damage were somehow
linked to the gameplay ability.
So if the gameplay ability has its own damage variable, how are we going to make sure that our gameplay
effect is using the damage from the gameplay ability?
Well, that's going to bring us to the fourth option for magnitude calculation type, which is set by
caller.
So we'll get into that next.
I'll see you soon.