Yanfly's Leech Seed - But remade for MP?

Yanfly made a lot of useful Tips n Tricks videos, including how to make the Leech Seed skill from the Pokemon games. I'd like to make a skill in the same way, but have it leech MP instead of HP.

Yanfly's setup is this. First there's a skill, this skill is very simple and all it does is applying a state to the target. The state on the other hand has some special code snippet in it's note box to make it work (it also requires some of Yanfly's plugin).

Spoiler: The code snippet is this:
Code:
<Custom Regenerate Effect>

// Check if the original caster isn't the target and that the original target is alive.
if (origin !== target && origin.isAlive()) {
  // Determine the damage dealt.
  var damage = target.hp / 8;
  // Round up the damage.
  damage = Math.ceil(damage);
  // Cap the damage to 500.
  damage = Math.min(500, damage);
  // Play the healing animation on the original caster.
  origin.startAnimation(46);
  // Original caster gains HP.
  origin.gainHp(damage);
  // Show the HP gained.
  origin.startDamagePopup();
  // Clears the original caster's HP popup.
  origin.clearResult();
  // Play the poison animation on the target.
  target.startAnimation(59);
  // Damage the target's HP.
  target.gainHp(-damage);
  // Check if the target is dead.
  if (target.isDead()) {
  // If the target is dead, make it collapse.
    target.performCollapse();
  }
}
</Custom Regenerate Effect>

Now, I don't really know JavaScript myself so even while everything is nicely commented (which helps a lot with understanding) I can't really say I'd know how to do what I'd like to do.

But I suspect this is could be super simple for someone who knows just a wee bit of JavaScript, so hopefully someone can help me out here.

I'd be very grateful.
Thanks for taking your time and reading all the way down here. 👋
I don't know JS either but I'm gonna try, wish me luck:
Code:
<Custom Regenerate Effect>

// Check if the original caster isn't the target and that the original target is alive.
if (origin !== target && origin.isAlive()) {
  // Determine the damage dealt.
  var mpdamage = target.mp / 8;
  // Round up the damage.
  mpdamage = Math.ceil(mpdamage);
  // Cap the damage to 500.
  mpdamage = Math.min(500, mpdamage);
  // Play the healing animation on the original caster.
  origin.startAnimation(46);
  // Original caster gains MP.
  origin.gainMp(mpdamage);
  // Show the MP gained.
  origin.startDamagePopup();
  // Clears the original caster's MP popup.
  origin.clearResult();
  // Play the poison animation on the target.
  target.startAnimation(59);
  // Damage the target's MP.
  target.gainMp(-mpdamage);
  }
}
</Custom Regenerate Effect>

All I did was change anywhere it said "damage" to "mpdamage" so it's defined. Also changed anything that referenced HP to reference MP, keeping the style of code the same. I didn't change the animations or anything like that.

Edit: and I got rid of the collapse effect as it's mp and not hp

I'm sure I messed it up.

First time. Lol.
Find all gainHp from the codes above, and replace them with gainMp.

Edit: The way Jenova did should serve your purpose. Following his codes and you will be fine.
Find all gainHp from the codes above, and replace them with gainMp.

Edit: The way Jenova did should serve your purpose. Following his codes and you will be fine.

I don't even know how to code and i edited it on my phone. I feel so proud but i still think I messed something up.
Basically, I have not seen any issues from your codes. In case something goes wrong, we will make it right again here, so don't worry 😉
Thank you for the help guys. Unfortunally I got an error msg while testing this out. I copy pasted what @Jenova wrote but changed the damage "cap" and adjusted the damage as well. I don't think that's what crashed the game though because I did the exact same changed to the normal (hp) formula and that worked fine.

Spoiler: This is the error msg I got:
GEehbhz.png

And here is the code copy pasted directly out of my "MP Leech Seed" state. My own small changes to the damage values included:

Code:
<Custom Regenerate Effect>

// Check if the original caster isn't the target and that the original target is alive.
if (origin !== target && origin.isAlive()) {
  // Determine the damage dealt.
  var mpdamage = target.mp / 20;
  // Round up the damage.
  mpdamage = Math.ceil(mpdamage);
  // Cap the damage to 200.
  mpdamage = Math.min(200, mpdamage);
  // Play the healing animation on the original caster.
  origin.startAnimation(46);
  // Original caster gains MP.
  origin.gainMp(mpdamage);
  // Show the MP gained.
  origin.startDamagePopup();
  // Clears the original caster's MP popup.
  origin.clearResult();
  // Play the poison animation on the target.
  target.startAnimation(59);
  // Damage the target's MP.
  target.gainMp(-mpdamage);
  }
}
</Custom Regenerate Effect>
Just delete the last "}". I think it should solve the problem.
@JamesRyan
Yes, that seems to work. Can't confirm that all the numbers are correct but hopefully they are. The enemy is (probably) loosing MP. That one is hard to confirm. But I am getting their MP, that I can confirm.

Most likely, it works like it should. I think.

Thank you.
It is now working as intended. They lose MP and you gain MP, I can guarantee.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-leech-seed-but-remade-for-mp.118275/