MV Remove States from enemies and allies Skill code help

Alright!

So I want to make a move that removes positive states from enemies and negative ones from allies. To do this I have combined the code from Yanfly's tips and tricks for biotic Grenade, Absorb Ailments and Buff Breaker.


I thought I had what I needed here but I'm not getting it to remove any states.


Code:
<Target: Everybody> //yanfly target core


<Damage Formula>

// Check if target and user are on the same team.

if (target.isActor() === user.isActor()) {

  // Heal formula for allies.

  value = user.mdf * 6;

// Otherwise for enemies...

} else {

  // Damage formula for enemies.

  value = user.mat * 10;

}

</Damage Formula>


<Pre-Damage Eval>

// Check if target and user are on the same team.

if (target.isActor() === user.isActor()) {

  // Make it heal the ally instead.

  value = -1 * Math.abs(value);

 var group = user.friendsUnit().aliveMembers();

//make array with bad states to remove
  var absorbedBadStates = [];

   absorbedBadStates.push(5,11)

   // Loop through each member in the group
 for (var i = 0; i < group.length; ++i) {

   // Get the currently looped member
    var member = group[i];

    // Check if the member exists

    if (member) {
      // Loop through each of the absorbable states

      for (var j = 0; j < absorbedBadStates.length; ++j) {

        // Get the currently looped state's ID

        var id = absorbedBadStates[j]

        // Check if the state exists and if the member is affected by it

        if ($dataStates[id] && member.isStateAffected(id)) {

          //remove state

          member.removeState(id);

          Increase the amount healed

          value += value;

        }

      }

    }

  }

}else{

//good states to eat
var absorbedGoodStates = [];

    absorbedGoodStates.push(54, 56);

var group2 = user.opponentsUnit().aliveMembers();

  // Loop through each member in the group

  for (var t = 0; t < group2.length; ++t) {

    // Get the currently looped member

    var member2 = group2[t];

   
      // Loop through each of the absorbable states

      for (var b = 0; b < absorbedGoodStates.length; ++b) {

        // Get the currently looped state's ID

        var id = absorbedGoodStates[b]

        // Check if the state exists and if the member is affected by it

        if ($dataStates[id] && member.isStateAffected(id)) {

          //remove states

          member.removeState(id);

         //Increase the amount of damage

          value += value;
      

      }

    }

  }

}

</Pre-Damage Eval>

This is hurting enemies and healing allies, which is good, but its not removing the states or scaling the damage which makes me think there is something wrong with my loops

If someone knows how to Skill Core or Java Script to let me know where I went wrong here that would be awesome!
Your code is a lot more convoluted than it needs to be, especially considering the pre-damage eval runs once for each target, so looping through the targets is redundant. Try this:

JavaScript:
<Pre-Damage Eval>
  const damage = value;
  let absorbedStates = [];
  if (target.friendsUnit() === user.friendsUnit()) {
    value = -value;
    absorbedStates = [5, 11];
  } else {
    absorbedStates = [54, 56];
  }
  for (const state of absorbedStates) {
    if (target.isStateAffected(state)) value > 0 ? value += damage; : value -= damage;
    target.removeState(state);
  }
</Pre-Damage Eval>
@Trihan I very much appreciate the response!

It looks like that isn't removing the states for some reason, and it hurts the allies now
This is how I added your code, maybe it was me?

1665504773595.png

Code:
<Target: Everybody>
<Damage Formula>
// Check if target and user are on the same team.
if (target.isActor() === user.isActor()) {
  // Heal formula for allies.
  value = user.mdf * 6;
// Otherwise for enemies...
} else {
  // Damage formula for enemies.
  value = user.mat * 10;}
</Damage Formula>
<Pre-Damage Eval>
  const damage = value;
  let absorbedStates = [];
  if (target.friendsUnit() === user.friendsUnit()) {
    value = -value;
    absorbedStates = [5, 11];
  } else {
    absorbedStates = [54, 56];
  }
  for (const state of absorbedStates) {
    if (target.isStateAffected(state)) value > 0 ? value += damage; : value -= damage;
    target.removeState(state);
  }
</Pre-Damage Eval>
Try adding some debugging to it and see what the console says:

JavaScript:
<Pre-Damage Eval>
  console.log(target.isActor() ? "Target is actor" : "Target is enemy");
  const damage = value;
  console.log(`Base damage: ${damage}`);
  let absorbedStates = [];
  if (target.friendsUnit() === user.friendsUnit()) {
    console.log("Target is friend");
    value = -value;
    console.log(`Healing value: ${value}`);
    absorbedStates = [5, 11];
  } else {
    absorbedStates = [54, 56];
  }
  for (const state of absorbedStates) {
    console.log(`Checking state ${state}`);
    if (target.isStateAffected(state)) { console.log("Target has state"); value > 0 ? value += damage; : value -= damage; }
    console.log(`New damage/healing value: ${value}`);
    target.removeState(state);
  }
</Pre-Damage Eval>
@Trihan
Got about 7 unexpected token errors

1665505767529.png

1665505820392.png


they all look the same as far as I can tell

I know I have a bunch of plugins! But I've not had any trouble with adding code to the note box so I'm not sure what it could be
I wonder if you're using an older version of RMMV that doesn't support ES6 (e.g. const, let, string templates). What version is your editor (Help -> About from the menu bar)? The latest engine update was v1.6.2.

Does Trihan's suggestion work if you replace every const and let with var?
mine is in fact 1.6.1 so it may need an update!

That said I used this variant (using his suggestions to simplify) and it did what I wanted!

Code:
<Target: Everybody>

<Damage Formula>
// Check if target and user are on the same team.
if (target.friendsUnit() === user.friendsUnit()) {
  // Heal formula for allies.
  value = user.mdf * 6;
// Otherwise for enemies...
} else {
  // Damage formula for enemies.
  value = user.mat * 10;
}
</Damage Formula>

<Pre-Damage Eval>
// Check if target and user are on the same team.
if (target.friendsUnit() === user.friendsUnit()) {
  // Make it heal the ally instead.
  value = -1 * Math.abs(value);
 let absorbedStates = [];
 absorbedStates = [5, 11];
      for (var j = 0; j < absorbedStates.length; ++j) {
        // Get the currently looped state's ID
        var id = absorbedStates[j]
        if ($dataStates[id] && target.isStateAffected(id)) {
        target.removeState(id);
    value=value-100;
}}
}else{   
  let goodAbsorbedStates = [];
    goodAbsorbedStates=[54,56];
  for (var i = 0; i < goodAbsorbedStates.length; ++i) {
        // Get the currently looped state's ID
        var id2 = goodAbsorbedStates[i]
        if ($dataStates[id2] && target.isStateAffected(id2)) {
        target.removeState(id2);
       value=value+200;
}}
}
</Pre-Damage Eval>

I would like to thank both of you for your help and suggestions!!!
mine is in fact 1.6.1 so it may need an update!
I don't believe 1.6.1 to 1.6.2 changed anything in that regard. As far as I know, the only difference between the versions is in the Japanese localization for exporting to a game site in Japan.

Original thread: https://forums.rpgmakerweb.com/threads/remove-states-from-enemies-and-allies-skill-code-help.151913/