MV Help with Yanfly's "Cup of Life Skill"

I'm trying to create a healing skill that that heals the user to 100% HP every time, and the 'overflow' of the amount healed is split between the other two party members.

ONLY the user can use this skill.

I figured I could just swap the 'user' and 'target' portions of the code using

$gameParty.members().indexOf($gameActors.actor(id))

But the problem is the user's position is never the 'same' in battle, as I have 3 members in battle at a time, and 8 party members total...

Here's the link;

Spoiler: Here's the code for Yanfly's "Cup of Life" skill
<Custom Confirm Effect>
var hpdiff = target.mhp - target.hp;
if (this.isHpEffect() && target.isAlive() && value < 0 && (Math.abs(value) > hpdiff)) {
var difference = Math.abs(value) - hpdiff;
value = -hpdiff;
user.gainHp(difference);
user.startDamagePopup();
user.clearResult();
user.startAnimation(46);
}
</Custom Confirm Effect>
I figured I could just swap the 'user' and 'target' portions of the code using

$gameParty.members().indexOf($gameActors.actor(id))
I fail to see how you'd need this at all. If the scope of the skill is set to the user, the target will be the user anyway.

the only thing you'd need to change is the part where the user gains HP.

Code:
$gameParty.members().forEach(member => {
  if(member.isAlive())
  {
    member.gainHp(Math.floor(hpdiff * 0.5));
    member.startAnimation(46);
    member.startDamagePopup();
    member.clearResult();
  }
 });
I fail to see how you'd need this at all. If the scope of the skill is set to the user, the target will be the user anyway.

the only thing you'd need to change is the part where the user gains HP.

Code:
$gameParty.members().forEach(member => {
  if(member.isAlive())
  {
    member.gainHp(Math.floor(hpdiff * 0.5));
    member.startAnimation(46);
    member.startDamagePopup();
    member.clearResult();
  }
 });
That’s the lunatic code provided in Yanfly’s Tip and Tricks for the skill, “Cup of life”

And would the code you provided, he’s the remaining members for the “overflow” of HP that didn’t heal the user?
This should work:

Code:
<Pre-Damage Eval>
 var overflow = target.hp;
 var targets = $gameParty.aliveMembers();

 targets.forEach(function (member) {
  if (member.actorId() !== 2) {
    member.gainHp(Math.floor(overflow / (targets.length - 1)));
    member.startAnimation(46);
    member.startDamagePopup();
    member.clearResult();
  }
 });
</Pre-Damage Eval>

Damage formula should be a.mhp.

I more simply used target.hp to set the overflow amount.
Since the skill is meant to fully heal the user and distribute the overflow, there is no need to calculate the difference, as it will always be the user's current hp.

I also swapped the $gameParty.members() for $gameParty.aliveMembers() to optimize the targeting and amount of healing received.
Thanks buddy! It works perfectly! 😀

Original thread: https://forums.rpgmakerweb.com/threads/help-with-yanflys-cup-of-life-skill.158734/