Disperse Damage through allies

Hi people!!


I'm here again to see if you can answer me a hard question and find a solution.

I'd like to create a state in wich if you are damaged then the damage is spread proportionally through your allies.

I thought Yanfly did something similar but I couldn't find it.


Thank you in advance.
This???
Yes, As I am looking for all damage to be spread the code I should take should be this:

Spoiler
<Custom React Effect>
// Check if the damage is positive.
if (value > 0) {
// Get the living members of the same party.
var members = target.friendsUnit().aliveMembers();
// Make an empty group to list affected members.
var affected = [];
// We'll go through each member to check them.
for (var i = 0; i < members.length; ++i) {
// Getting the individual member.
var member = members;
// Does the member exist and is the member affected by state 91 (the Joint Penalty state)?
if (member && member.isStateAffected(91)) {
// If the member is affected, add it to the affected group.
affected.push(member);
}
}
// Divide up the damage by how many members are affected.
value = Math.ceil(value / affected.length);
// We'll go through each of the affected members now.
for (var i = 0; i < affected.length; ++i) {
// Getting the individual affected member.
var member = affected;
// Ignore the effect if the member is the target of attack.
if (member !== target) {
// Let's play animation 12 on the affected member.
member.startAnimation(12);
// The affected member takes damage.
member.gainHp(-value);
// We'll have the affected member reveal a damage popup.
member.startDamagePopup();
// Clear the results of the effect.
member.clearResult();
// Next, check to see if the member is dead.
if (member.isDead()) {
// If the member is dead, we'll make it collapse.
member.performCollapse();
}
}
}
}
</Custom React Effect>




But I need not to check if they have the state, just the party.
 


I tried this but it doesn't work:
 

Spoiler
<Custom React Effect>
// Check if the damage is positive.
if (value > 0) {
// Get the living members of the same party.
var members = target.friendsUnit().aliveMembers();
// Make an empty group to list affected members.
var affected = [];
// We'll go through each member to check them.
for (var i = 0; i < members.length; ++i) {
// Getting the individual member.
var member = members;
}
// Divide up the damage by how many members are affected.
value = Math.ceil(value / affected.length);
// We'll go through each of the affected members now.
for (var i = 0; i < affected.length; ++i) {
// Getting the individual affected member.
var member = affected;
// Ignore the effect if the member is the target of attack.
if (member !== target) {
// Let's play animation 12 on the affected member.
member.startAnimation(12);
// The affected member takes damage.
member.gainHp(-value);
// We'll have the affected member reveal a damage popup.
member.startDamagePopup();
// Clear the results of the effect.
member.clearResult();
// Next, check to see if the member is dead.
if (member.isDead()) {
// If the member is dead, we'll make it collapse.
member.performCollapse();
}
}
}
}
</Custom React Effect>




I'm VERY bad on scripting, can you help me?
I'm not sure what you are asking for :/


When the state is on more than one character, any damage they take will be dispersed between those affected. Is that not what you want?
I'm not sure what you are asking for :/


When the state is on more than one character, any damage they take will be dispersed between those affected. Is that not what you want?

No.

Sorry if I didn't explained it correctly.

What I want is that if the mage is hitted and he has the state "damage dispersion", the damage suffered by the mage is divided between the members of the party.
Then, if the hit is -100HP and there are 4 members, then each member will suffer -25HP.
Ah now I get it. I've just gone out but I'm pretty sure I know how to do it. If no one else has answered by the time I get back I'll get it working for you


EDIT: So this should work, all I've done is taken away the if that checks for the state on the members and instead if a character has the state on them and gets attacked it will disperse the damage. Just edit the number for what animation to play if needed.

Spoiler
<Custom React Effect>
// Check if the damage is positive.
if (value > 0) {
  // Get the living members of the same party.
  var members = target.friendsUnit().aliveMembers();
  // Make an empty group to list affected members.
  var affected = [];
  // We'll go through each member to check them.
  for (var i = 0; i < members.length; ++i) {
    // Getting the individual member.
    var member = members;
    // Does the member exist and is the member affected by state 91 (the Joint Penalty state)?


      // If the member is affected, add it to the affected group.
      affected.push(member);
    }


  // Divide up the damage by how many members are affected.
  value = Math.ceil(value / affected.length);
  // We'll go through each of the affected members now.
  for (var i = 0; i < affected.length; ++i) {
    // Getting the individual affected member.
    var member = affected;
    // Ignore the effect if the member is the target of attack.
    if (member !== target) {
      // Let's play animation 12 on the affected member.
      member.startAnimation(12);
      // The affected member takes damage.
      member.gainHp(-value);
      // We'll have the affected member reveal a damage popup.
      member.startDamagePopup();
      // Clear the results of the effect.
      member.clearResult();
      // Next, check to see if the member is dead.
      if (member.isDead()) {
        // If the member is dead, we'll make it collapse.
        member.performCollapse();
      }
    }
  }
}
</Custom React Effect>
Thank you!!!


An error appears that say "undefined is not a function".
Thank you!!!


An error appears that say "undefined is not a function".

I cleaned the formula to see if there were something wrong,
Did it works with you Beenbaba?

Spoiler
Code:
<Custom React Effect>
if (value > 0) {
  var members = target.friendsUnit().aliveMembers();
  var affected = [];
  for (var i = 0; i < members.length; ++i) {
    var member = members;
      affected.push(member);
    }
  value = Math.ceil(value / affected.length);
  for (var i = 0; i < affected.length; ++i) {
    var member = affected;
    if (member !== target) {
      member.startAnimation(12);
      member.gainHp(-value);
      member.startDamagePopup();
      member.clearResult();
      if (member.isDead()) {
        member.performCollapse();
      }
    }
  }
}
</Custom React Effect>

Original thread: https://forums.rpgmakerweb.com/threads/disperse-damage-through-allies.63341/