How To Make A Skill That Does Increased Damage For Every State Applied To The Target?

Hi, I wanted to make a skill that does 30% increased damage per state that the target. Ex. If the target has 1 state applied, it does 30% more damage and if they have 3 states applied it does 90% more damage.
I'm not sure if it's a hard ask but I'm not familiar with coding or damage formulas myself.
Could I get some help please?
(If it helps I have most Yanfly Plugins downloaded)
Something like this in the damage formula might do it:

JavaScript:
const states = b.states().length; const bonus = 1 + (0.3 * states); (a.atk) * bonus

Replace
JavaScript:
a.atk
with your base damage formula.

It's generally not great to check this sort of stuff in the damage formula because it could technically cause problems elsewhere if some external method tries to run eval() on the formula outside of the action loop. I don't think this case would be much of an issue, but my quick replies like this sometimes turn out to be shortsighted.

If you're using Yanfly's plugins, it'd be better to implement this using them. However, I'm not familiar with the library enough to give you advice on how to do it.
It's generally not great to check this sort of stuff in the damage formula because it could technically cause problems elsewhere if some external method tries to run eval() on the formula outside of the action loop. I don't think this case would be much of an issue, but my quick replies like this sometimes turn out to be shortsighted.
You're not being shortsighted, I don't see how counting the length of an array can change the state of anything in the game.
If you want to go the slightly safer route of doing this via notetags, I think it goes something like this?

JavaScript:
<Custom React Effect>
if (target.isStateAffected(386)) {
value *= 1.3;
value = Math.round(value);
}

if (target.isStateAffected(387)) {
value *= 1.3;
value = Math.round(value);
}
</Custom React Effect>

That example shows two states; you'd have to copy/paste for any additional states you'd want to account for. For each one you'd just replace the number in parentheses (386 and 387 in mine) with the state ID you want to use.

(Disclaimer: I use MZ/VisuStella, so I'm not as familiar with the MV/Yanfly nomenclature. Also, my coding skills are probably worse than yours haha)
If you want to go the slightly safer route of doing this via notetags, I think it goes something like this?
Listing every state that could possibly be on the target is a very inefficient method - you can use the exact same code that Kenen did.
Code:
value *= 1+(.3*target.states().length);

However, as previously noted, this is perfectly safe to just put in the damage formula.

The only reason it's a bad thing to have code in there is when that code changes something, because then enemy AI/the auto battle trait will cause it to be changed even if the skill isn't used. Counting doesn't change anything.
I guess I was assuming there'd be certain states they didn't want accounted for (i.e. positive states), thus the separate entries. But I'm not intellectually qualified to extrapolate what each part of that formula code means, haha
I guess I was assuming there'd be certain states they didn't want accounted for
Well, the OP didn't ask that - I try not to assume more than is said 😉

But if you did want that, it's a minor change.
Code:
value *= 1+(.3*target.states().filter(state => state.meta.multiplier).length);

That will only cause states with the notetag <multiplier> to multiply the damage.
Well, the OP didn't ask that - I try not to assume more than is said 😉

But if you did want that, it's a minor change.
Code:
value *= 1+(.3*target.states().filter(state => state.meta.multiplier).length);

That will only cause states with the notetag <multiplier> to multiply the damage.
That's actually something I wanted accounted for, but thought it would be to tall of an ask so didn't bother, so thanks actually. Also for this formula, where would I put the damage formula?
If you're putting it in the damage formula, you would follow the format that @Kenen already gave you in the first reply. Just replace the multiplier with the line I supplied.

Code:
const bonus = 1+(.3*target.states().filter(state => state.meta.multiplier).length); (your formula here) * bonus
If you're putting it in the damage formula, you would follow the format that @Kenen already gave you in the first reply. Just replace the multiplier with the line I supplied.

Code:
const bonus = 1+(.3*target.states().filter(state => state.meta.multiplier).length); (your formula here) * bonus
Oh alright, also did I need to have a certain plugin for the <multiplier> notetag to work? It sounds like it would be under yanfly's state categories plugin which I have installed, but just making sure-

Edit : Nevermind, appears to work fine.
I guess I was assuming there'd be certain states they didn't want accounted for (i.e. positive states), thus the separate entries. But I'm not intellectually qualified to extrapolate what each part of that formula code means, haha
Thanks, you helped enough as is.
If you're putting it in the damage formula, you would follow the format that @Kenen already gave you in the first reply. Just replace the multiplier with the line I supplied.

Code:
const bonus = 1+(.3*target.states().filter(state => state.meta.multiplier).length); (your formula here) * bonus
Just an additional question if I changed the formula to something like this
Code:
const bonus = 1+(.3*user.states().filter(state => state.meta.buff).length); (your formula here) * bonus
would it read states with the notetag <buff> on the user and multiply the damage by the same percentage? Asking because I want a similar skill that deals extra damage per buff on the user (ex. evasion, critical rate).

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-skill-that-does-increased-damage-for-every-state-applied-to-the-target.162405/