Okay.
So now that we have a listen for event gameplay ability and we know that it's being activated right
away, we can start sending events.
So how do we do that?
Well, we've already seen that we can send gameplay events.
We've done so in our custom anim, notify where we call send gameplay event to actor.
Now this is the ability system blueprint library, static function, and notice that it takes in an
event tag and a payload.
So when we receive the events that payload is available, we can send data through it.
We're planning on sending in the event tag that we set on that data, this struct here and a magnitude.
So our job now is to send this as soon as we've caused fatal damage and we know when that happens from
within our attributes set.
So let's go ahead and open our attribute set.
So in aura attribute set in post gameplay effect, execute, we're checking the evaluated data to see
if it's incoming damage.
And we know then if it's fatal, we've already made that determination.
So here, if it's fatal, we're taking our combat interface.
We're casting the target Avatar actor to it and calling die.
So the target Avatar actor is the thing getting hit.
And we need to do a couple things.
We need to get that target Avatar Actors XP rewards, so that we can set that magnitude value in a gameplay
event and send that off.
We also need to know who to send this gameplay event to, so we need to know something about the target
and the source.
And those are all info that we've stored in the props effect properties struct.
So we could just create a function here to send an event and we can pass props into it.
And that's how I'd like to handle this.
So I'm going to open the header file and way down at the bottom I'm going to make a void function in
the private section called Send XP event and this will take a const f effect properties struct by const
reference called props.
And we'll go ahead and generate this function.
And Ryder did that annoying thing where it gave me an inline function definition, not what I want.
So I'm going to go into the CPP file and define it.
And here is where we need to figure out a few things.
For one, we need to know how much XP to reward the attacker.
So that's a value we need to figure out.
But we made a ability system library function that can do that.
If we go to that CP file, we can find get XP reward for class and level.
And as long as we know the character class and the character level, we can get an XP reward value.
So we can call that as long as we have the character class and the character level.
So we need to get that.
So closing the Blueprint library there, let's figure out how we can get the level and the class.
Well, we can get that combat interface because the combat interface here defined in interaction.
I'm going to go to the public folder interaction and open combat interface.
We have get player level and we have get character class.
We can get those values from the combat interface.
So in send Exp event, let's just cast that target character to an eye combat interface.
We'll say eye combat interface combat interface equals cast to eye combat interface.
And we're going to cast props dot target character.
Now we can wrap this in an if statement, and then feel free to access those values.
We can get the player level as an int 32, we'll call it level, we'll call it target level because
it's the target character and that will be combat interface get player level.
We can also get the target class with a character class, target class, we'll call it.
And we'll use combat interface get player class.
No, it's actually get character class.
Now that we have those two and those could be const, we can make them a const int 32 and a const character
class.
We can now get that exp reward from you or ability system library get exp reward for class and level.
Now this does need a world context object so we could just pass in props dot target character.
The next input is the character class so we can pass in target class.
And finally we need the character level and that's target level.
Now this returns us an int 32 so we can store it in a const int 32 called exp reward.
Like that and I'll go ahead.
And now that we know the XP reward, we can send a gameplay event.
Now the gameplay event is on you Ability system Blueprint library and the function is called send gameplay
event to actor, same as the one we used in Blueprint.
Now it needs to know what actor to send this gameplay event to and we're going to send it to the source
character.
That's the character causing damage.
That's the one that needs the XP reward.
The XP reward itself came from the target that got slain.
Now we're going to send the event to the attacker, the source character.
So it's going to be props dot source character.
That's the target.
Now a gameplay tag will be used for this event.
That's the tag that our ability will be listening for.
And remember, we set this up to use that tag for the meta attribute.
So we need to get that tag.
So I'm going to make a const for a gameplay tags.
So that can be const, it can even be a const reference and we can call this gameplay tags and I'm going
to use F or a gameplay tags get.
And then the tag will pass in will be gameplay tags dot attributes meta incoming exp.
Now the last input is an gameplay event data.
We need to make one of these because we have to send through the magnitude that our ability is going
to use for a set by call or magnitude on our event based effect.
So we need to make an gameplay event data called payload.
Let's do it.
So F gameplay event data, we'll call it payload, and we're going to set a couple things on it.
For one, we're using that event tag on the struct in our ability.
So even though we're sending that tag in send gameplay event to actor, the tag we're sending in the
function call is what our wait gameplay event ability task is listening for.
But then we're taking the payload data and getting the event tag from that.
So we need to set that and that's going to be the same gameplay tag.
So we're setting that and then we're going to take payload and set it to magnitude.
It's called event magnitude.
Now it's a float.
We're going to set it equal to Exp reward.
So we are getting an implicit conversion from INT to float, but no big deal.
And now that we have our payload, we can pass it in.
And with that we now have a function send exp event and we can call that up here in post gameplay effect
execute if the damage is fatal.
So we're going to call send exp event and pass in props.
And as long as everything works, we should see an output log because our gameplay event will be received
by our ability that's listening for it and then our ability will apply a gameplay effect spec to its
owner and it's going to change the incoming XP meta attribute.
And then we'll log that to the output log with our UI log.
So with all that, we're now ready to launch this and try it out.
Okay, so moment of truth here.
We've got everything set up.
I can close this and notify.
We know that.
Listen for event is activated when the event is received.
Though I would also like to print a string to make sure that we're receiving it.
So print string here and I'll just print the event tag from our payload.
So I'm going to get a debug string from the gameplay tag and we'll print that too.
And then if this effect is applied and our meta attribute is changed, we should also see something
in the output log.
So I'm going to press play and open and dock the output log here and then we can slay this enemy we
got standing over here.
And let's see what happens.
Couple more shots should do it.
One more will definitely do it.
And we actually had an assertion it says we should call execute git character class instead of calling
git character class directly.
And that's right, because git character class is a blueprint native event.
So what we should actually do here in send Exp event is call the execute version.
Let's go ahead and do that.
So right here where we're getting our character class, let's just get a combat interface and call execute
git character class and pass in props dot target character.
Like so.
So if you forget, that's okay.
If you try to call a function directly, that's a blueprint native event.
You have to call the execute version here in C plus plus get player level was okay because it's not
a blueprint native event.
So let's go ahead and try this again.
All right.
We can press play.
It says we're listening for events.
Let's kill this enemy.
We have a cooldown, so I can't do this fast.
Okay, so we killed the enemy.
It looks like we did not get an event.
So I'm going to go into my listen for event.
My print string is gone.
That's okay.
Let's see though, if we receive anything.
So I'm going to print a string and say event received.
We'll go ahead and kill this thing.
Okay.
So we did receive an event.
Let's see what that event tag was.
So we'll get a debug string from that event tag.
We'll see if it was the correct tag.
One more should do it.
Okay.
Attributes dot meta dot incoming exp.
So we did get the correct tag and we created an effect spec.
We set a set by caller magnitude and we called apply gameplay effect spec to self getting the ability
system component from the actor info.
So we are applying the gameplay effect.
Let's double check with that gameplay effect.
Looks like it's called event based effect where setting incoming exp we're adding to it using a set
by caller with attributes.
Dot meta dot incoming exp.
So that looks good.
Next, we can make sure that we're actually getting to this point in our attributes set.
So if evaluated data dot attribute is incoming exp.
We can see right here if we reach that so we can press play.
And we can try once again.
One more should do it.
Okay.
And we are reaching this far.
So we know that incoming XP is being set and we should see that UI log.
So I'm going to remove that breakpoint and resume and take a look at the output log.
And I'm going to search for log ora.
And there it is, incoming XP 2020, 2020 and in GA.
Listen for event.
We could even see that magnitude.
If we print that as a string, let's give that one a try.
One more, maybe two.
Okay, one last one.
There we go.
And 20 So we are receiving that event that's working.
So I don't need that print string anymore.
We can remove that.
I don't need this print string anymore.
Make sure it's event received hooked up to a sign tag set by color magnitude.
That looks good.
And I don't need my UI log right here.
Excellent.
So things are all tied together almost.
We know that in the case of causing fatal damage, we're getting this incoming exp.
Meta attribute set.
The last piece of the puzzle is to actually set the exp on the player state and then we should be able
to set up listening for that change updating in the HUD.
So a couple things left and we'll have exp working and then we'll start working on leveling up.
Excellent job and I'll see you in the next video.