(Answered) (Yanfly) Mana Shield help?

In my game the highest MP you can have is 500, but the highest health is around the 10000 mark, so I'm hoping this can be modified to still have an 85% damage reduction, but only deal 5% of the reduced damage to MP.


How would I achieve this?


<Custom React Effect>


if (value > 0 && this.isHpEffect()) {


var mpDmg = Math.floor(value * 0.85);


mpDmg = Math.min(mpDmg, target.mp);


target.gainMp(-mpDmg);


value -= mpDmg;


}


</Custom React Effect>


*edit* Although it doesn't solve the code, I did find a Mana Shield plugin that can do the same thing.


https://alistairengine.wordpress.com/2015/11/01/alistair-plugins-mana-shield/


In the config I simply changed the "Default MP Ratio" to 20 instead of 1. Works for the full damage range until I'm out of MP.
<Custom React Effect>


if (value > 0 && this.isHpEffect()) {


var mpDmg = Math.floor(value * 0.85);


mpDmg = Math.min(mpDmg, target.mp);


target.gainMp(Math.floor(-mpDmg * 0.0588235));


value -= mpDmg;


}


</Custom React Effect>


That should do it, the only change is on the target.gainMP line where I multiplied the damage by 1/17 (in decimal approximation format to avoid issues of it rounding it to 0 midway).
I tried that (copy and paste) and it no longer has the 85% damage reduction. It reduces the damage taken to health by the amount of damage dealt to mana.
Ok, try this. Something odd must be going on with the mpDmg variable as that should not be possible what you described unless JavaScript isn't using local variables correctly.


<Custom React Effect>


if (value > 0 && this.isHpEffect()) {


var mpDmg = Math.floor(value * 0.85);


mpDmg = Math.min(mpDmg, target.mp);


var realmpDmg = Math.floor(mpDmg * 0.0588235);


target.gainMp(-realmpDmg);


value -= mpDmg;


}


</Custom React Effect>


If that doesn't work, see if the original code works, as at this point I'll suspect the original code is broken. Though, do check and see if the *real* damage to HP and MP is what we want, sometimes the pop-ups don't reflect the damage one really takes.


Edit: Added a missing ;. If it crashes retry the cut and paste.
Well with the new code you gave me something strange happens. I'll write out the damage I took in battle for a dozen turns or so.


Over 7000 health and 100 MP on the dot.

Spoiler
Damage Taken - MP Damage Taken


100 Without Mana Shield


15 - 4


15 - 4


15 - 4


15 - 4


15 - 4


17 - 4


21 - 4


25 - 4


29 - 4


33 - 3


36 - 3


39 - 3


42 - 3


45 - 3


48 - 3


51 - 2


So on and so forth.

Basically it seems as though the lower my MP the less damage reduction it gives me.


*edit* Re-tested with the first code you gave me and it does the same thing.
The 15 - 4 is what is should do. 15 is 15% of normal damage, and 4 is 1/17 of 85 (rounded down, hence the 4 and not 5), No idea why it is doing this though, almost looks like it is checking your percent of MP too?


What happens with the original code? I'm starting to think either the original code is wrong, or something is interferring with it, as all I did was change the amount of MP damage applied. Nothing else was touched, so the HP damage should not be changing.
With just 100 MP it did 15 - 85.


With 1000 MP it did 15 - 85 until I had no MP left. 


*edit* Tried changing the code to:


<Custom React Effect>


if (value > 0 && this.isHpEffect()) {


var mpDmg = Math.floor(value * 0.85);


mpDmg = Math.min(mpDmg, target.mp);


target.gainMp(Math.floor(-value * 0.0588235));


value -= mpDmg;


}


</Custom React Effect>


Since it looks like "value" is synonymous with mpDmg from the last line, it stayed the exact same MP damage all the way through to 0 MP, but the damage reduction for HP damage was reduced as I lost MP. I think the second line needs an adjustment as well, though I'm unsure.


*edit* Although it doesn't solve the code, I did find a Mana Shield plugin that can do the same thing.


https://alistairengine.wordpress.com/2015/11/01/alistair-plugins-mana-shield/


In the config I simply changed the "Default MP Ratio" to 20 instead of 1. Works for the full damage range until I'm out of MP.
Odd...the variable should have worked. Unless I used one already reserved in the code. Anyways, I'd use the mana shield code instead, I've had no problem with that one myself.


As for what value does, value is the damage being dealt. So you'd have to change the number in front of it to 0.05 to get 5% damage to MP, as now it is doing 5.88%.
Yeah I'm not sure what was going on with the damage reduction being reduced as my MP went down, but I'm glad I found the plugin. It was on Yanfly's YouTube for the "Magic Guard" tutorial.


Thanks for the help, though. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/answered-yanfly-mana-shield-help.60286/