Increase Damage if Enemy has a Debuff or Status Ailment

I'm working on creating a skill that inflicts damage to all enemies, and deals extra damage to enemies that are affected by a debuff or negative state. The code I have doesn't seem to be working, though.
Spoiler
Code:
<After Eval>
target.hasNegEffect = false;
var negEffects = [];
//Negative effects are states 4-14
negEffects.push(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
target.debuffDmg = 1;

//loop through parameters to find a debuff
for (var i = 0; i < 8; i++){
 //if the target has any debuff, stop the loop
 if (target._buffs[i] < 0){
  target.hasNegEffect = true;
  break;
 }
}

//go into this loop only if the first loop doesn't find any debuffs
//if target.hasNegEffect is true, there's no point searching for anything else
if (!target.hasNegEffect){
 for (var j = 0; j < negEffects.size; j++){
  var id = negEffects[j];
  if (target.isStateAffected(id)){
   target.hasNegEffect = true;
   break;
  }
 }
}

//if the target is found to have a negative effect, increase the damage by 45%
if (target.hasNegEffect){
 target.debuffDmg = 1.45;
}
</After Eval>
Spoiler
Damage formula:
Spoiler
6000 * b.debuffDmg
Well...your code is a bit overly convoluted for what you want to do, but it looks functional to me.

Where are you doing anything with this target.debuffDmg property?
Well...your code is a bit overly convoluted for what you want to do, but it looks functional to me.

Where are you doing anything with this target.debuffDmg property?
Here's how it's supposed to work:
  1. Creating the new property at the top of the note page to initialize it to 1 (if an enemy doesn't have a debuff or negative state, the code keeps it at this number)
    target.debuffDmg = 1;
  2. If an enemy does have a debuff or negative state, increases that number to 1.45 or something
    if (target.hasNegEffect){ target.debuffDmg = 1.45; }
  3. The resulting value of the property goes into the damage formula
    6000 + b.debuffDmg
But when I tested it out, the skill didn't deal any damage regardless of whether any enemies had a debuff.

BTW, I want the calculation to apply to EACH enemy, so that it only deals the extra damage to enemies that have a negative effect or debuff.
The resulting value of the property goes into the damage formula
6000 + b.debuffDmg
1707926089008.png


You're doing all of this three phases after damage is dealt to the target, so no...referencing it in the damage formula won't do anything.

You would need to do it in the Pre-Damage phase. Or, for what you're doing, you can just put it in the damage formula and no plugins are needed.

The code you have above can be made more compact as such:
Code:
target.hasNegEffect = (target._buffs.some(buff => buff < 0)
                                      || [4, 5, 6, 7, 8, 8, 19, 11, 12, 13, 14].some(state => target.isStateAffected(state)))
                                      ? 1.45 : 1;

You could put that into a Pre-Damage Eval and reference it in the damage formula, or you can just put it directly into the damage formula.
Code:
let negEffect = (b._buffs.some(buff => buff < 0) || [4, 5, 6, 7, 8, 8, 19, 11, 12, 13, 14].some(state => b.isStateAffected(state))) ? 1.45 : 1; (your damage formula here) * negEffect
I just tried both the methods you suggested, and neither of them worked. The skill's still not dealing any damage
When a skill is not dealing any damage, oftentimes the cause is some undefined value getting used in the damage formula. Did you change your notetag to one that gets evaluated pre-damage? Which one?

Try putting console.log(b.debuffDmg); before your actual formula and have a look at the console. Does it say "undefined" or does it output an actual value?
When a skill is not dealing any damage, oftentimes the cause is some undefined value getting used in the damage formula. Did you change your notetag to one that gets evaluated pre-damage? Which one?

Try putting console.log(b.debuffDmg); before your actual formula and have a look at the console. Does it say "undefined" or does it output an actual value?
OK, so I just tried it again, and when I used the first method, which is:
Code:
target.hasNegEffect = (target._buffs.some(buff => buff < 0)
                                      || [4, 5, 6, 7, 8, 8, 19, 11, 12, 13, 14].some(state => target.isStateAffected(state)))
                                      ? 1.45 : 1;
and put 6000 * b.hasNegEffect in the damage formula, that value was undefined.
Then I tried the second method, on the other hand, which is:
Code:
let negEffect = (target._buffs.some(buff => buff < 0) || [4, 5, 6, 7, 8, 8, 19, 11, 12, 13, 14].some(state => target.isStateAffected(state))) ? 1.45 : 1; 6000 * negEffect
And that works just fine.

My question now is: why does this happen? Is there something about target.hasNegEffect vs. b.hasNegEffect that the editor doesn't like?
It's not clear from your posts where you're putting these things, you didn't answer @eomereolsson's question about what notetag you're using.

However, I did have a typo in my version for the damage formula - there's no such thing as "target" there, so all instances of "target" should be replaced by "b" if you're putting it directly into the damage formula.
It's not clear from your posts where you're putting these things, you didn't answer @eomereolsson's question about what notetag you're using.

However, I did have a typo in my version for the damage formula - there's no such thing as "target" there, so all instances of "target" should be replaced by "b" if you're putting it directly into the damage formula.
Sorry, I changed my notetag to do the calculations pre-damage

Original thread: https://forums.rpgmakerweb.com/threads/increase-damage-if-enemy-has-a-debuff-or-status-ailment.165742/