[help]Skill that gets stronger from an amount of buffs the actor has

Hello! I need help of making 2 skills:

- Skill 1: gets stronger when the user has 2 or more buffs.
- Skill 2: gets stronger when the target has 2 or more buffs.

I know I need to use variables on my buffs, but I just could not figure how to make it work..

Thanks for your time!
Using Yanfly's Skill Core and Buffs & States Core, I wrote this in an attempt to answer your question:

Code:
<Pre-Damage Eval>
// Loop through all parameters
for (var i = 0; i < 8; i++) {
  if (target._buffs[i] > 0) {
  // Increase the skill's damage for every buff
    value += a.atk * 6;
  }
}
</Pre-Damage Eval>

(If you want the user's buffs, replace target._buffs with user._buffs.)

------

...And then I realized I misread the question and have no idea how to check if the target (or user) has at least two buffs of any kind. :hswt:
@JojoLaVache if you use your code, and var i > 2; < x; i++ might do the buff trick?
x being the number, or do I misread that?

but it does lunatic code. but I think you are close with the pre-damage though
@ShadowDragon Sadly, no; (var i = 0; i < 8; i++) is an array used to check all eight base parameters (MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK) with MHP being id 0 and LUK being id 7.
With that function, I can check all base parameters without copypasting what to do when target._buffs[0], target._buffs[1], etc. is true.

If I instead wrote (var i = 2; i < 8; ++i), this would allow me to loop though ATK, DEF, MAT, MDF, AGI and LUK.
I'm still hoping for someone to help me with this.

Would it help if replacing a state instead a buff?
@Acydcross Add b._states.length to your damage formula.
Example:
100 + a.mat * (2 + 2 * b._states.length)
If by buffs, you mean +stat effects only (not counting stacked buffs) you could do something like this without any plugins or fancy variable manipulation:

Code:
c = b._buffs.reduce((acc, cur) => acc + (cur > 0 ? 1 : 0)) || 1; a.atk * 4 * c - b.def * 2

Obviously you'd use your own damage formula, and "c" in this case would be a multiplier you could use as you see fit. It will be 1 if the target has 0 buffs or 1 buff, then increase per buff from there, so 2 at 2 buffs, 3 at 3, etc.

Note: This formula counts the active buffs on the target. To count the active buffs on the user instead, change the b._buffs part to a._buffs

Also note: In this case, a +atk buff stacked once counts for the same amount as a +atk buff stacked twice. If you'd like stacked buffs to count as individual buffs (a +atk stacked twice = 2 buffs) then:

Code:
c = b._buffs.reduce((acc, cur) => acc + (cur > 0 ? cur : 0)) || 1; a.atk * 4 * c - b.def * 2
@Aesica I tried it by slapping the formula on my Skill's damage box and... nothing. It deals zero damage when the target has no buff, or one buff, or even two buffs.

I'm guessing I'm stupid with JavaScript. :hswt:
@Aesica I tried it by slapping the formula on my Skill's damage box and... nothing. It deals zero damage when the target has no buff, or one buff, or even two buffs.

I'm guessing I'm stupid with JavaScript. :hswt:
Zero damage happens when there's an error in the damage formula, so post your damage formula. (I just tried out what I posted in my test project and it works fine)
@Aesica I copied the formula unaltered. I have no idea if I should change c; acc; and cur by anything, and (if yes) by what.
Oh, don't touch anything on the left side of the semicolon. The part you want to change is the stuff on the right. Here's a clearer example:

Code:
c = b._buffs.reduce((acc, cur) => acc + (cur > 0 ? 1 : 0)) || 1; BASE_DAMAGE + BONUS_DAMAGE * c

Oh wait, what version of RMMV are you using? I forgot that arrow functions are a more recent arrival to javascript and thus, require 1.5(?) or higher.

Here's a more compatible version, but it's uglier and bulkier:

Code:
c = b._buffs.reduce(function(acc, cur){ return acc + (cur > 0 ? 1 : 0) }) || 1; BASE_DAMAGE + BONUS_DAMAGE * c

You'd of course change BASE_DAMAGE to whatever you want the base damage to be, and BONUS_DAMAGE to whatever you want the multiplier to be applied to:

50 + 25 * c
75 damage normally, plus 25 additional damage per buff over 2
@Aesica I'm using Version 1.6.2.
For testing purposes, I put the damage variance at 0%, disabled critical hits and used flat numbers for your piece of code:
Code:
c = b._buffs.reduce(function(acc, cur){ return acc + (cur > 0 ? 1 : 0) }) || 1; 50 + 30 * c
It's super late in France, but it looks like it won't behave the way you intended when I changed the buff formula to
Code:
this._buffs[paramId] * 0.20 + 1.0
using YEP_BuffsStatesCore. I deal 80 damage with no enemy buffs, then one buff, then two, all the way until I reach 200% modifier where I end up dealing 96 damage instead.
Code:
this._buffs[paramId] * 0.20 + 1.0
using YEP_BuffsStatesCore. I deal 80 damage with no enemy buffs, then one buff, then two, all the way until I reach 200% modifier where I end up dealing 96 damage instead.
Wait, is that *exactly* what's in the damage formula box? Because that's not valid and will throw errors (hence 0 damage) since "this" in this case (if memory serves) references the Game_Action in progress, not the actor/enemy. The buffs are on the actor/enemy.

If it's not, post everything exactly as it is in your formula box.
No, I meant
Code:
c = b._buffs.reduce(function(acc, cur){ return acc + (cur > 0 ? 1 : 0) }) || 1; 50 + 30 * c
is what I put on my damage box, while
Code:
this._buffs[paramId] * 0.20 + 1.0
is my buff effect calculation on Yanfly's plugin.
@JojoLaVache weird, that damage formula should be working... I mean I didn't test, but code-wise it should...

are you using any plugin that would change it, like yanfly's armor scaling?

could you add something, and check the result on the console? This should give us the current value of c in there
Code:
c = b._buffs.reduce(function(acc, cur){ return acc + (cur > 0 ? 1 : 0) }) || 1; console.log(c); 50 + 30 * c
I disabled YEP_X_ArmorScaling (like before) and YEP_BuffsStatesCore, then set up my testing skill:
1587198688322.png

...and I always deal 80 HP to the target, no matter how many buffs it has. The reason I dealt 96 damage before was because I ALSO have YEP_SkillMasteryLevels active.

So I'm finally using a blank project with all plugins disabled because clearly, I have too many plugins on my main one. Here, I used
Code:
c = b._buffs.reduce((acc, cur) => acc + (cur > 0 ? cur : 0)) || 1; a.atk * 4 * c
All four actors have this skill and the same ATK parameter.
And well, it works! That means there must be a plugin or five that causes conflict with the formula...
If I had to guess, some plugin you're using is changing how buffs are handled. By default, the _buffs array contains a series of integers that correspond to each stat (hp, mp, atk, def, etc). Any value of 0 means no change, any negative value means x number of debuff stacks, while a positive number (what the reduce function is tallying) means x number of buff stacks. It's possible some plugin is storing buff data as something other than an integer, in which case it'd result in NaN (not a number) which falls back on 1. (That's what the || 1 part means)

Besides yanfly's buffs/states plugin, are you using anything else that changes how buffs work?
Besides yanfly's buffs/states plugin, are you using anything else that changes how buffs work?
Aside from anything requiring YEP_BuffsStatesCore, I use YEP_AutoPassiveStates, but neither my battlers not the test enemy have any passive state.
In the game where it doesn't work, load a saved game, go to the dev console, and type

$gameParty.members()[0]._buffs

The result should look something like this:

> (8) [0, 0, 0, 0, 0, 0, 0, 0]

Now, type

$gameParty.members()[0].addBuff(2, 10)

Then finally, a second time:

$gameParty.members()[0]._buffs

And now, it should look like this:

> (8) [0, 0, 1, 0, 0, 0, 0, 0]

If it isn't, post a screenshot of what shows up.

Original thread: https://forums.rpgmakerweb.com/threads/help-skill-that-gets-stronger-from-an-amount-of-buffs-the-actor-has.120218/