Divert the Tips & Tricks of Yanfly : Aura of Sacrifice (Resolved)

Hello,
Once again I try to change a Tips & Tricks to adapt it to my needs.
I think it's doable but I need someone who knows java script.
This is the "Aura of Sacrifice" effect. In the script that I will show you below, it allows you to create a state that will redirect the damage suffered by the allied characters to a single ally (the tank logically).
Example: I have 4 characters in my team (A B C and D).
A has the damage redirection state.
All damage suffered by B C and D are redirected to A. The script also reduces the amount of damage suffered by 50%.

Now I will explain what I would like.
I would like to create a state that is placed on an enemy, redirecting half of the damage suffered by my allied characters on him.
Example: If A B C and D must suffer 100 damage
==> they only take 50 damage each, and the enemy marked with the state will take 200 (4 x 50).

Is it possible ?
(Translation made by google, please ask me to rephrase if necessary)
The original formula:


<Custom React Effect>
// Check if the action dealt HP damage
if (this.isHpEffect() && value > 0) {
// Get the target's allies
var members = target.friendsUnit().aliveMembers();
// Get the Aura's Origin State ID
var auraOriginId = 246;
// Make the origin user undefined
var auraOriginUser = undefined;
// Loop through each member
for (var i = 0; i < members.length; ++i) {
// Get the currently looped member
var member = members;
// Check if the member exists, isn't the target, and is the aura holder
if (member && member !== target && member.isStateAffected(auraOriginId)) {
// Set the origin user to that member
auraOriginUser = member;
// Break the loop
break;
}
}
// Check if the origin user exists
if (auraOriginUser) {
// Calculate the amount of reduction
var reduction = Math.ceil(0.50 * value);
// Set the damage to the target to 0.
value = 0;
// Make the origin user take damage instead.
auraOriginUser.gainHp(-reduction);
// Display an animation on the origin user.
auraOriginUser.startAnimation(2);
// Make the origin user display a damage popup.
auraOriginUser.startDamagePopup();
// Check if the origin user is dead
if (auraOriginUser.isDead()) {
// Collapse the origin user if dead
auraOriginUser.performCollapse();
}
// Clear the origin user's results
auraOriginUser.clearResult();
}
}
</Custom React Effect>
Any time you're posting code, you should always put it in code tags (the </> icon on the top bar) - this will preserve indents and prevent brackets from being treated as BBCode.

For example, there are places where your code has members[i] but it doesn't show up and displays as italics instead, making that portion of code unreadable.

So this seems like it should be not too hard, putting a state on the enemy that has the Alive Foe Aura tag. In your code below, I don't know why you're using "Get the target's allies" - the aura wouldn't be coming from an ally (another party member), it would be coming from an enemy in the troop. So replace friendsUnit() with opponentsUnit()...the rest of the code, while a bit unnecessarily convoluted, should work from there.

You will also, of course, want to cut value by half, rather than setting it to 0.

Example: If A B C and D must suffer 100 damage
==> they only take 50 damage each, and the enemy marked with the state will take 200 (4 x 50).
There's no such thing as simultaneous damage. If you have a lot of multiple target skills, I don't think there's a simple way to store up all the damage and display it once at the end of the action - you'd see 4 hits of 50 damage.
i have a skill like that. sorry, i didnt read your whole post. heres what i have:

i have a skill place a state on the target. and i have a state on the skill user. it can be placed by the skill but mine is just a passive.

this passive skill (on the skill user) goes like this in its notetag:

Code:
<Custom React Effect>
   if(value > 0){
      var newDmg = Math.floor(value * 1.5);

      // Get the group of alive enemies and allies.
      var enemies = user.opponentsUnit().aliveMembers();
      var friends = user.friendsUnit().aliveMembers();
      // Loop through each of the enemies.
      for (var i = 0; i < enemies.length; ++i) {
         // Get the enemy.
         var enemy = enemies[i];
         //if any of them have the targeting state...
         if(enemy.isStateAffected(43)){
            // Make the enemy take damage.
            enemy.gainHp(-newDmg);
            // Prompt the enemy's damage popup.
            enemy.startDamagePopup();
            // Clear the results of the enemy taking damage.
            enemy.clearResult();
            // Check if the enemy is dead.

            if(enemy.isDead()){enemy.performCollapse();}
         }
      }

      // Loop through each of the allies.
      for (var i = 0; i < friends.length; ++i) {
        var friend = friends[i];

        if(friend.isStateAffected(43)){
          friend.gainHp(-newDmg);
          friend.startDamagePopup();
          friend.clearResult();

          if(friend.isDead()){friend.performCollapse();}
        }
     }
  }
</Custom React Effect>

mine checks to see if allies and enemies have the state because my game allows players to target allies. the user skill redistributes damage (half more than the user received) to any one with the state (43 in my game) applied by the skill.
Any time you're posting code, you should always put it in code tags (the </> icon on the top bar) - this will preserve indents and prevent brackets from being treated as BBCode.
Sorry I did not know.
Your solution works very well. Actually, it's not that I wanted to use "Get the target's allies", I just showed you the original "aura of sacrifice" formula.
Thank you for your response.
Thanks also to oooNUKEooo, so I didn't need to try but thank you.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/divert-the-tips-tricks-of-yanfly-aura-of-sacrifice-resolved.148568/