Recover MP whenever you kill any enemy in a battle.

Hi, I'm working on a fangame in MV, and I'm wondering if there's any way to program a feature where you recover something like 5 or 10 MP whenever you kill any enemy during a battle.

Yes, this sort of feature also applies to normal attacks and even special attacks.

I know it sounds strange, but it's necessary for this situation (since it's a Cave Story fangame).
Depends on how willing you are to play around with plugins.

Using Yanfly's Action Sequence Packs, you can have skills in the Finish Action do something like check if the target isStateAffected(dead) and recover 10 MP to the user.
Depends on how willing you are to play around with plugins.

Using Yanfly's Action Sequence Packs, you can have skills in the Finish Action do something like check if the target isStateAffected(dead) and recover 10 MP to the user.
Lemme see if that will work..
That didn't really end well, as Victor's VE Basic Module plugin does not work together with the YEP Battle Core Engine..

Anything else?
That didn't really end well, as Victor's VE Basic Module plugin does not work together with the YEP Battle Core Engine..

Anything else?
Ah, fair enough.

Okay, in that case you're gonna want to do some crazy damage formula shenanigans. This thread is my best friend when it comes to this sort of thing, I pretty much have it open in a tab at all times for quick reference.

You're probably going to have to put this on every attack skill you have, but it would probably look something along the lines of
Code:
v[1] = a.atk-b.def; b.hp<==v[1] ? a.gainMP(10); a.atk-b.def;
Basically, this sets Variable 1 to equal however much damage the attack should do, then checks if the target's HP is less than that, and if it is, it'll regain 10 MP.

Unfortunately, I'm not sure how to accoint for variance, so if you have variance in your attacks, we'll need to figure out something else.
You can do this without relying on Yanfly.

First, have the skill apply a state to the enemy you hit. Also apply immortality (resist knockout).
Then, have the skill also activate a common event. Make sure this is ordered after the states.
Next, in the common event, check all enemies that are alive. If an enemy is alive & has the state, check if its HP is zero. If so, apply whatever effect you want.
Finally, remove the immortality state from all enemies.
You can do this without relying on Yanfly.

First, have the skill apply a state to the enemy you hit. Also apply immortality (resist knockout).
Then, have the skill also activate a common event. Make sure this is ordered after the states.
Next, in the common event, check all enemies that are alive. If an enemy is alive & has the state, check if its HP is zero. If so, apply whatever effect you want.
Finally, remove the immortality state from all enemies.
How do you even check if the enemy's HP is zero, when it comes to common events?
I'm not sure if there's a way to get the common event to check a specific target, but if you had it check EVERY enemy, it would probably work?

But if you're using immortal enemies for a cutscene or something that might complicate things.

Maybe combining damage formulae with common events will do it?
How do you even check if the enemy's HP is zero, when it comes to common events?
Control Variables → Game Data → Enemy → HP

Then, use a Conditional Branch to compare the value to zero.

And yes, you have to go through every enemy, but only check the one that has a matching state.
help.PNG

I know I'm definitely doing something wrong here..
With YEP_Skill Core, it is possible. You don't need YEP_Battle Engine to do so.


Here is a notetag that should work


<Post-Damage Eval>

if (target.hp <= 0){

user.gainMp(X);

}

</Post-Damage Eval>
View attachment 167533
I know I'm definitely doing something wrong here..
Actually, that looks just about how I'd do it. From here, if it doesn't work how you intended, it'll probably be a series of small tweaks.
If it's not working, try displaying a message to see if the conditions are activated or not.
With YEP_Skill Core, it is possible. You don't need YEP_Battle Engine to do so.


Here is a notetag that should work


<Post-Damage Eval>

if (target.hp <= 0){

user.gainMp(X);

}

</Post-Damage Eval>
My project uses Skill Core, so that could possibly work!

EDIT: I tried it, but whenever I kill an enemy, it abruptly gives me this error:
"SyntaxError
Unexpected Token }"
Silly question but did you replace X by -5 for example ?

You can try with "value >=target.hp" instead of "target.hp <= 0 "

EDIT : I forgot a ";" after the last "}"
Silly question but did you replace X by -5 for example ?

You can try with "value >=target.hp" instead of "target.hp <= 0 "

EDIT : I forgot a ";" after the last "}"
Yeah, I did replace X with that like "user.gainMp(5);" for example.

For some reason, it still gives me that strange Syntax Error, even if I do this.

1605283226713.png
Try in this order : target.hp >=0

If it doesn't work, try with "value >= target.hp" and <Pre-Damage Eval> !
Try in this order : target.hp >=0

If it doesn't work, try with "value >= target.hp" and <Pre-Damage Eval> !
Still gives me the same error.
1605417770461.png


1605418107088.png
I don't know what I miss. I think it is a parenthesis or space problem.

I will investigate this with my current project where the same kind of formula work.

Keep you in touch.

EDIT : check here


Maybe you need a space after the if condition
I don't know what I miss. I think it is a parenthesis or space problem.

I will investigate this with my current project where the same kind of formula work.

Keep you in touch.

EDIT : check here


Maybe you need a space after the if condition
1605474410346.png

The same error pops up, even if I try this..

Original thread: https://forums.rpgmakerweb.com/threads/recover-mp-whenever-you-kill-any-enemy-in-a-battle.129682/