RPG Maker MZ - implementing stat drain when you are hit while guarding.

I use MP as stamina, so each turn, the player recovers some MP. I want to make it so if they guard, and are hit while guarding, it drains some MP. I don't want this to happen if they are hit while not guarding, however.
You'll need to use a plugin that allows you to attach code to a state.

If you're using VisuStella plugins, their Battle Core has notetags for it. If you're not, you can use my Eval Tags plugin, linked in my signature.

Using my Eval Tags, you'd give your Guard state the notetag:
Code:
<Action Respond Eval>
if (skill.isDamage())
    target.gainMp(-10);
</Action Respond Eval>

That will make you lose 10 MP every time you're hit while guarding. You can change the number or make it a formula inside the parentheses.
Wow! Thanks very much for this. Much appreciated.
You'll need to use a plugin that allows you to attach code to a state.

If you're using VisuStella plugins, their Battle Core has notetags for it. If you're not, you can use my Eval Tags plugin, linked in my signature.

Using my Eval Tags, you'd give your Guard state the notetag:
Code:
<Action Respond Eval>
if (skill.isDamage())
    target.gainMp(-10);
</Action Respond Eval>

That will make you lose 10 MP every time you're hit while guarding. You can change the number or make it a formula inside the parentheses.
Just a question, I get
TypeError
this.checkEnemyEval is not a function

when entering battle, with this notetag applied to the guard state.
When you get crashes, please press F8, go to the Console tab, and post a screenshot of the full error trace.

I'll look at it, but it would help to see where that's coming from in the code. That line should never be getting called for an actor.

The code in an Action Respond Eval also shouldn't be getting run when you enter a battle. So I'm confused by the whole situation.
Apologies. Pressing F8 on my pc after rpg maker crashes doesn't open the boot options. I'm not sure how to get to the tab you are asking about. If you have any suggestion that would be appreciated.
Are you on Mac? You should be able to get there with F12, also, but F8 is the hotkey created by MZ.

If you're not able to provide the error trace for the crash, there's not much I can do to help.
I'm on pc. I'll try to find a way to provide error trace. Thanks.
Both F8 and F12 should work on PC unless you have other plugins interfering with it.
I have a several plugins going, like multitweaks, etc. I'll have to eliminate them to see if any are interfering with F8/12. I have a couple plugins that effect battle, but I unchecked them and still got the crash. I will see what I can do.

Edit:

@ATT_Turan
rmmz1.png
Both F8 and F12 should work on PC unless you have other plugins interfering with it.
Sorry to pester you, just wanted to check if you have a second. The above screenshot is the report.
Just so you know, editing in tags doesn't create a notification for the person 😉

I dunno, the error makes no sense to me. That line of the code (327) is not calling that function (checkEnemyEval)

1724252935778.png


My only suggestions are:
- try re-downloading the plugin from my post. Put it in your plugins folder, then right-click it in your plugin manager and Refresh. Save project and start a new playtest.

- If that doesn't help, try turning off all other plugins, save, start new playtest.

If you're still getting the error when that's the only plugin running, show me that trace as you did above. And maybe if you can duplicate it in a test project that you can share with me.
Just so you know, editing in tags doesn't create a notification for the person 😉

I dunno, the error makes no sense to me. That line of the code (327) is not calling that function (checkEnemyEval)

View attachment 315339

My only suggestions are:
- try re-downloading the plugin from my post. Put it in your plugins folder, then right-click it in your plugin manager and Refresh. Save project and start a new playtest.

- If that doesn't help, try turning off all other plugins, save, start new playtest.

If you're still getting the error when that's the only plugin running, show me that trace as you did above. And maybe if you can duplicate it in a test project that you can share with me.
Late reply. Thanks for your help. It was the Enemy Actor MZ plugin by VSMA that was interfering. It allows animated SV enemy actors.

Original thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mz-implementing-stat-drain-when-you-are-hit-while-guarding.170927/