YEP's Buffs & States Core state custom effect help

Hi all,

I'm looking to create a state, presumably using Lunatic Mode in YEP's Buffs & States Core that inflicts elemental damage during the HP regeneration window of each turn. Disclaimer: I don't know / understand javascript, but I try to and figure it out as much as possible.

The formula I want the damage to use is - in layman's terms:

5% of affected actor's Total HP = Value of elemental damage to inflict. However, once that initial value is determined, I want that to be treated as if it were an incoming attack of that element, so that the actor's resistance, or lack thereof, will change the amount of damage they receive.

The second part of this state, is that I want this same effect to occur to the actors in the slots adjacent to this actor. So if the actor was in slot 2, I would want this effect to occur on the actors in slots 1 and 3, even though they actually aren't afflicted by the state themselves.

Thanks for any help you can give me.

EDIT: I think it's worth mentioning I'd like an animation to play at the point where the damage occurs too, just to call attention to itself.

EDIT AGAIN: It's also worth mentioning that I'll need variants of this type that deal damage to all party members, as opposed to just those next to the afflicted actor.
For damage to neighbouring members, you could try:
Spoiler
Code:
<Custom Regenerate Effect>
var animId = 59;    // animation ID
var elemId = 6;     // damage element ID
var ix = user.index();
var allies = user.friendsUnit().members();
[ix-1, ix, ix+1].forEach(function(n) {
  var ally = allies[n];
  if (ally && ally.isAlive()) {
    var dmg = ally.mhp * 0.05; // 5% max HP
    dmg *= ally.elementRate(elemId);
    ally.startAnimation(animId);
    ally.gainHp(-Math.round(dmg));
    ally.startDamagePopup();
    ally.clearResult();
  }
});
</Custom Regenerate Effect>
For damage to all (living) allies, maybe something like this instead:
Spoiler
Code:
<Custom Regenerate Effect>
var animId = 59;    // animation ID
var elemId = 6;     // damage element ID
var allies = user.friendsUnit().aliveMembers();
allies.forEach(function(ally) {
  var dmg = ally.mhp * 0.05; // 5% max HP
  dmg *= ally.elementRate(elemId);
  ally.startAnimation(animId);
  ally.gainHp(-Math.round(dmg));
  ally.startDamagePopup();
  ally.clearResult();
});
</Custom Regenerate Effect>
Just edit the values on the "// commented" lines as appropriate~ 🙏

After a brief test, I'd suggest using Yanfly's Battle Engine Core plugin to make the damage numbers show up. 😴

(Also, if by "total" HP you meant "current" HP, just replace mhp with hp. 😅)
Thanks so much for this @caethyril !

I'm having some trouble getting it to work, but I think that may be due to other plugins I am using. Once I figure that out, I'll test it right away!
Since you mention Yanfly's plugins, maybe double-check you have them up-to-date and in the recommended order in the Plugin Manager. Recommended order can be found here: http://yanfly.moe/yep/

Hope it works out! 🙏

Original thread: https://forums.rpgmakerweb.com/threads/yeps-buffs-states-core-state-custom-effect-help.110120/