MV [Solved] Need help altering code for a state's effect

I have this code for one of my states that works for the most part in converting 0.1% of damage taken into MP that the target recovers while still taking the rest of the HP damage but for some reason it doesnt work when the target currently has 0 MP, which sucks when the point of the state is to recover MP upon being damaged.

What part of the code do I change and what do I change it to so that the effect is still applied even when the target's MP is at 0?
<Custom React Effect>
if (this.isHpEffect && value > 0) {
var offset = Math.floor((Math.min(value * 0.1, target.mp)));
value += offset;
target.gainMp(+offset);
}
</Custom React Effect>
Hey bro, how are you?

A few points about your code.

Math.min() returns the smallest of the numbers you give it,
when the target's current MP is 0, Math.min() will always choose 0 because it's the smallest number. This means offset becomes 0, and the target gains 0 MP.

You could try to simplify, to see if it works:

Code:
<Custom React Effect>
if (this.isHpEffect && value > 0) {
var mpGain = Math.floor(value * 0.001);
target.gainMp(mpGain);
}
</Custom React Effect>

Calculate the amount of MP to recover based on damage / the target gains the calculated MP

An observation is that 0.1 does not correspond to 1% but rather to 10%, for 0.1% of damage, use value * 0.001.
Hey bro, how are you?

A few points about your code.

Math.min() returns the smallest of the numbers you give it,
when the target's current MP is 0, Math.min() will always choose 0 because it's the smallest number. This means offset becomes 0, and the target gains 0 MP.

You could try to simplify, to see if it works:

Code:
<Custom React Effect>
if (this.isHpEffect && value > 0) {
var mpGain = Math.floor(value * 0.001);
target.gainMp(mpGain);
}
</Custom React Effect>

Calculate the amount of MP to recover based on damage / the target gains the calculated MP

An observation is that 0.1 does not correspond to 1% but rather to 10%, for 0.1% of damage, use value * 0.001.
That works perfectly! Thank you! Also it's fine with the % stuff, I wanted it to be like that but thank you! I'll keep it in mind for later stuff!
just to note
if (this.isHpEffect && value > 0) {
isHpEffect is a function, not a property. since it is defined it wont be false or cause an error, but also that means things that arent hp affects like mp damage will still trigger this. change it to isHpEffect()

converting 0.1% of damage taken into MP that the target recovers while still taking the rest of the HP
...
value += offset;
youve already ensured by the opening condition that value is a positive number. offset can only be a positive number, so by doing that youve increased the damage the target takes, not reduced it.

Math.floor((Math.min(value * 0.1, target.mp)));
As pointed out, Math.min() returns the lowest value given. did you mean to make it so that the effect caps the mp recovery so that it never visually overheals the mp? youd need for one input to be the max mp - the current mp rather than just the current mp

I cant remember if healing in a react effect counts as being positive when the skill is a recovery type skill or not, so an added isDamage() check should work in preventing heals from triggering it if they are positive.

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

Original thread: https://forums.rpgmakerweb.com/threads/solved-need-help-altering-code-for-a-states-effect.179783/