State or trait that converts hp damage to mp damage

See if it still does it with the UNCO_AmmunitionSystem plugin turned off, I don't have that and it's working for me so that may be where the inconsistency lies
Didn't work.


Hm... I created a new project and installed all the plugins listed in the F8 log. It doesn't throw an error, but the state doesn't work. The skill just does 100 MP damage.
It uses the buffs and states core
That's interesting.


I backed up my project and deleted every plugin except Auto Passive States. The state actually works.
So somewhere along the lines there must be some plugin that's messing stuff up? seems like process of elimination from there to figure out what's up
Well, that's what I thought. I guess the state wasn't working. The skill was only doing 50 mp damage, so I thought it was. I changed the state from 0.5 to 0.75 just to be sure, and it still only did 50. I added Buffs and States Core back, and the only plugins installed are Buffs and States Core and Auto Passive States. I'm getting the error message again.


And I just figured out that the error happens at the end of the turn.


Clean project, Auto Passive States and Buffs and States Core installed, added skill to do MP damage and state to reduce it. Gave the skill to one actor and the state to another. Had the first actor use the skill on the other. The state doesn't reduce the damage and it still crashes and gives me that error.
Are you giving them the state as a passive or through an ability?


If it's as a passive I need to actually add some code. Aside from that there's another small fix I did anyways
Here's the code if you want it to work as a passive. Just as a note, "Apply" effects don't happen with passive states. for those you need to use "Battle" effects, as they trigger at the start of combat.

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

<custom react effect>
if (this.isMpEffect() && value > 0){
	target._oldMp = target.mp;
}
</custom react effect>
<custom Respond effect>
  //check if MP was damaged
if (this.isMpEffect() && value > 0){
	//find the smaller number
	var addAmount = Math.min(value, target._oldMp);
  //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>

<custom victory effect>
  //remove the paramater on state removal
user._mpConvert = undefined;
</custom victory effect>

<custom defeat effect>
  //remove the paramater on state removal
user._mpConvert = undefined;
</custom defeat effect>
My bad. I didn't realize it would have to be different for a passive state.


Thank you, I'll test this out after work later.


UPDATE: It works! Finally! My only complaint is that is shows 100 mp damage, then 50 mp recovery. Is there a way to just show 50 mp damage? If not, that's fine. It's actually a nice way to show the player what happens when she takes MP damage.


UPDATE 2: I tested out the first state you made for me. Getting hit with a skill that only does 100 HP damage, she took 50 HP damage and recovered 48 MP...
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%)
How does one go about putting this script into a state?
How does one go about putting this script into a state?

its already a state. you just put the entire thing into the state's notebox. if youre using the plugin itll run the code between the <Custom React Effect> tags when the battler with the state takes a hit

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