A skill/formula that activates when attacked

(Credit to the post https://forums.rpgmakerweb.com/index.php?threads/absorb-damage-state.82101/ )
I don't know where it is and I've been looking for it...

At the current moment...

Code:
<Custom React Effect>
if (value > 0 && this.isPhysical()){
target.gainMp(value);
target.startAnimation(58); //Change x into an animation ID if you want to display animation when this effect is activated.
value = value * 0.2;
target.startDamagePopup();}
</Custom React Effect>

The way it's supposed to work is that...- So the question is.
What is the code that I would need to apply the effect?
The effect is : "Upon taking damage from a foe, gain an amount of SP equal to 1% of damage taken."

I'm not a great coder myself, I'm more of an artist and event type of person. But when it comes to this...
Hmm, okay, let me make sure I've got this right: You want an effect that gains 1% MP(SP) equal to damage taken. Is that all damage taken, or just physical damage? The code you've posted is a react effect, so that does process before damage is taken - I assume you're using Yanfly's Buff+State Core.
I do not have RPG Maker MV in front of me at the moment, however I did make this up quickly. Let me know if it works/does what you intend it to do. It should return 1% of physical damage taken as MP, showing animation 58.
Spoiler
<Custom Respond Effect>
if(value > 0 && this.isPhysical()) {
value = Math.ceil(value *.01);
target.startAnimation(58);
target.gainMp(value);
target.startDamagePopup();
}
</Custom Respond Effect>
Hmm, okay, let me make sure I've got this right: You want an effect that gains 1% MP(SP) equal to damage taken. Is that all damage taken, or just physical damage? The code you've posted is a react effect, so that does process before damage is taken - I assume you're using Yanfly's Buff+State Core.
I do not have RPG Maker MV in front of me at the moment, however I did make this up quickly. Let me know if it works/does what you intend it to do. It should return 1% of physical damage taken as MP, showing animation 58.
Spoiler
<Custom Respond Effect>
if(value > 0 && this.isPhysical()) {
value = Math.ceil(value *.01);
target.startAnimation(58);
target.gainMp(value);
target.startDamagePopup();
}
</Custom Respond Effect>


WhatI want is the effect to gain 1% MP(SP) equal equal to damage taken.
If it can be done, ALL damage taken. Sorry I din't specify before I AM using Buff+State Core.

So if someone does 100 damage I will recover 1 sp. 200 damage, then it will be 2 sp. rounded up as well too if possible.
Ah, ALL damage taken! Alright, no problem. Just sub the "this.isPhysical()" for "!this.isHpRecover()".
That will run the effect for anything NOT healing and more than 0 damage. The Math.ceil should round up to a whole number. Example: damage is 116. 1% should be 1.16, but Math.ceil will take that to 2. Therefore, the target will recover 2 Mp. If you would like it to round down instead, so that 1.16 will be 1, then simply use Math.floor. Let me know if that works! 🙂
Ah, ALL damage taken! Alright, no problem. Just sub the "this.isPhysical()" for "!this.isHpRecover()".
That will run the effect for anything NOT healing and more than 0 damage. The Math.ceil should round up to a whole number. Example: damage is 116. 1% should be 1.16, but Math.ceil will take that to 2. Therefore, the target will recover 2 Mp. If you would like it to round down instead, so that 1.16 will be 1, then simply use Math.floor. Let me know if that works! 🙂

Thank you that helped out a BUNCH!. That's it 🙂

Original thread: https://forums.rpgmakerweb.com/threads/a-skill-formula-that-activates-when-attacked.112373/