State or trait that converts hp damage to mp damage

I know this exists and I'm pretty sure I have the plugin to do it, but I just can't remember where to find it. I need a trait or a state that will convert a percentage of hp damage taken into mp damage.


So, for example, if the state splits the damage 50/50 and my actor is hit with an attack that would do 100 HP damage, she would take 50 HP damage and 50 MP damage instead.
Put this in a state and you're ready to go!


<Custom React Effect>
if (this.isHpEffect && value > 0) {
var offset = Math.floor((Math.min(value/2, target.mp)));
value -= offset;
target.gainMp(-offset);
}
</Custom React Effect>


Also if you want more control over the damage % mitigation instead of dividing value you can change that line to 


var offset = Math.floor((Math.min(value * 0.5, target.mp)));



and just change the "0.5" to another number between 1 and 0 (example: 0.2 = 20%, 0.02 = 2%)
Jeeze, thank you. You're awesome.


Just to be clear, if I put in 0.2, will that split it into 80HP/20MP damage or 20HP/80MP damage?
if you put 0.2 it'll take 20% off of the incoming damage and convert it to mp damage, so 80% would still be hp damage
Awesome. Now, let's say I have a separate state that halves all MP damage and knocks 25% all HP damage. Would that result in a final 10% MP damage and 60% HP damage?
Order of execution depends on the priority value you give the state. If you gave the state you mentioned a higher priority it wouldn't touch the mp damage from the state I wrote out and so it'd knock off 25% from the attack, and then the state I wrote out (while set to 20%) would take the 20% of the remaining 75% and mitigate that to mp damage. If you give my state priority I believe it will make it so it does the initial conversion to 80% hp 20%MP and then your mentioned state should halve the mp damage and take 25% from the remaining 80% of the hp damage
Awesome.


Now, how do I make a state that cuts mp damage in half?
Actually I'm looking into the code to see how it determines what is MP damage and what is not and because they don't store damage types as an array I can't add another one so the two of them would not interact currently.


I can make a code that halves mp damage from abilities marked to do mp damage.
Actually, I MIGHT be able to do something but this is gonna take a bit of experimentation 
My goal is to have two states, one that redirects a percentage of HP damage to MP damage (let's say 20% for the sake of discussion) and one that then reduces incoming MP by a percentage (50% for the sake of discussion).


So an attack that would deal 100 HP damage would end up doing 80 HP damage and 10 MP damage.


If that can be acheived, I would be very happy.
Something that does that directly doesn't seem possible to me, but what I CAN do is make a second state that recovers MP damage based on a special variable you can have MP damaging effects modify. Naturally you'll be able to control the rate that returns that. On the plus side of that, it would have an extra little visual que to make it feel more present in the game
I... don't know what you mean. lol.
So like, in your example, instead of making the damage be split as 80 and 10, you could make it so it's still 80 and 20, but then regenerate 10. It would be the same in terms of net value, but it would be something I could definitely make without pouring through the source code. And with it, custom abilities could interact.
That would be awesome.


Could you elaborate on how custom abilities could interact?


*adds Fugama as co-producer in game credits*
Okay, I got this one all tested out and it seems that after damage execution it does in fact count the Mp damage as an MP effect. By going the regen route, the code got a bit simpler for the mp regen state! here's that state.

Code:
<custom apply effect>
  //store a new param to track MP damage
target._mpConvert = 0;
</custom apply effect>


<custom Respond effect>
  //check if MP was damaged
if (this.isMpEffect && value > 0){
  //adds the value of damage dealt to the param we made earlier
    target._mpConvert += value;
}
</custom Respond effect>

<custom regenerate effect>
// This is the formula for what percent of mp damage the user will regain, (0.5 is 50%, 0.05 is 5%), make it a variable for this function.
var recovMpRate = Math.floor(user._mpConvert * 0.5);
//gain MP based on the formula above
	user.gainMp(recovMpRate);
// reset the count to 0 for the next turn
user._mpConvert = 0;


</custom regenerate effect>

<custom remove effect>
  //remove the paramater on state removal
user._mpConvert = undefined;
</custom remove effect>
TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': float parameter 3 is non-infinite.
at which point did that happen? is it at the end of the round of combat?
I created a skill to do 100 mp damage with no variance or critical. I had one of my actor my actors use it on another actor who had the state you created. a yellow "100" popped up and then I got that error.
I can't seem to recreate it, but I did fix up a bit of the code so maybe one of those fixes fixed it?

Code:
<custom apply effect>
  //store a new param to track MP damage
target._mpConvert = 0;
</custom apply effect>


<custom Respond effect>
  //check if MP was damaged
if (this.isMpEffect() && value > 0){
	//find the smaller number
	var addAmount = Math.min(value, target.mp);
  //adds the value of damage dealt to the param we made earlier
    target._mpConvert += addAmount;
}
</custom Respond effect>

<custom regenerate effect>
// This is the formula for what percent of mp damage the user will regain, (0.5 is 50%, 0.05 is 5%), make it a variable for this function.
var recovMpRate = Math.floor(user._mpConvert * 0.5);
//gain MP based on the formula above
	user.gainMp(recovMpRate);
// reset the count to 0 for the next turn
user._mpConvert = 0;


</custom regenerate effect>

<custom remove effect>
  //remove the paramater on state removal
user._mpConvert = undefined;
</custom remove effect>
Same problem. Here's the debug F8 screen thing.


TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': float parameter 3 is non-finite.


at TypeError (native)


at Bitmap.gradientFillRect (file:/js/rpg_core.js:997:24)


at Bitmap.gradientFillRect (file:/js/plugins/YEP_CoreEngine.js:622:41)


at Window_BattleStatus.Window_Base.drawGauge (file:/js/plugins/YEP_CoreEngine.js:1449:17)


at Window_BattleStatus.Window_Base.drawActorMp (file:/js/rpg_windows.js:566:10)


at Window_BattleStatus.Window_Base.drawActorMp (file:/js/plugins/YEP_SkillCore.js:1081:44)


at Window_BattleStatus.Window_Base.drawActorMp (file:/js/plugins/UNCO_AmmunitionSystem.js:1786:49)


at Window_BattleStatus.drawGaugeArea (file:/js/plugins/YEP_BattleStatusWindow.js:487:12)


at Window_BattleStatus.drawItem (file:/js/plugins/YEP_BattleStatusWindow.js:455:10)


at Window_BattleStatus.Window_Selectable.drawAllItems (file:/js/rpg_windows.js:1250:18)rpg_managers.js:1756 SceneManager.catchException

Original thread: https://forums.rpgmakerweb.com/threads/state-or-trait-that-converts-hp-damage-to-mp-damage.70637/