Need help with a passive state/skill using variables

I need to make a passive state named spellslinger.
Every time the character uses a magic spell it adds 1 to a variable to a max of 5.
i want to make the Attack command consume the variable to do 20% more damage based on how much the variable is, then,
Afterwards, i want the character to gain mp = the variable consumed * 10%
What plugin are you using for passive states?
While this can be done by damage formula coding, it would be very tedious to do so and have several limitations (like only counting successfull skill uses, not magic spells that miss).

So it's better to do this by plugin.
Moved to: Plugin Requests
What plugin are you using for passive states?
Im using YEP passive States and buff states core
So if I'm understanding you correctly here, you want a passive state that applies a post-action effect which adds 1 to a variable if the skill was a magic type (max of 5) and then you want to apply a pre-damage effect to the normal attack skill which consumes that variable to increase damage?
So if I'm understanding you correctly here, you want a passive state that applies a post-action effect which adds 1 to a variable if the skill was a magic type (max of 5) and then you want to apply a pre-damage effect to the normal attack skill which consumes that variable to increase damage?
That is correct. But I also want the character to heal for 10% of their maximum Mana for each stack.

[Update]
still no luck on my side 🙁 this is so hard lol

[Update]
I think it finally clicked today at work. Gonna test when i get home, but here is what i got so far:

First I made a common event that adds one to the spellslinger variable every time they use that spell.
I modify the damage formula to include the variable adding damage to the attack command.
In the attack command, as a confirm effect, I'll have user. Gain MP equal to variable x by 10%.
In the attack command, as I conclude effect, I'll set the game variable to zero.
I'm not sure if this will work how I intend but it seems to be the closest thing that makes sense to me. Let me know if I'm right or wrong I'm still going to wait till I get home from work to test it. The only thing that I am missing is setting the maximum of the variable to 5
@kuroshinne Well I think I can help you out, you will need other Yanfly scripts tough, you'll need the Acton Sequence packs the three of them.

However this code will NOT work correctly if you have more than one spellslinger in the party

Then well in your spell slinger state you should add this code.

Code:
<Custom Battle Effect>
user._spellsStacks = $gameVariables.value(X) || 0;
var stacks = user._spellsStacks.clamp(0, 5)
user.setStateCounter(Y, stacks);
user.refresh();
</Custom Battle Effect>

<Custom Action End Effect>
user._spellsStacks = $gameVariables.value(X) || 0;
var stacks = user._spellsStacks.clamp(0, 5)
user.setStateCounter(Y, stacks);
user.refresh();
</Custom Action End Effect>

Where X is the variable you want to work with and Y is the state ID. After that, you need to add this piece of code in each of the spells you want the spellslinger to have.

Code:
<setup action>
change variable X += 1
perform start
</setup action>

Where X is the same as above.

Then you need to add this to the Attack damage formula.

Code:
if (a.isStateAffected(Y) && $gameVariables.value(X) > 0) {(Damage Formula) * (1 + (v[X] * 0.20)); a.gainMp(Math.floor((a.mmp * 0.10) * v[X]));} else {Damage Formula;}

Where again X and Y are the same as above X is the variable and Y is the state.

Then you need to add this into the Attack note tags.

Code:
<finish action>
if (user.isStateAffected(17) && $gameVariables.value(19) > 0)
change variable 19 = 0
else
end
perform finish
</finish action>

This should make everything work I belive.
hey thanks for the help friend... I actually figured it out. and I did it a little bit different. It works great BTW. I just haven't added the state counter thing... so thank you for that.
This is what I did:
Code:
made an entirely new attack function and used YEP weapon unleash to have this set as the characters attack:

<Pre-Damage Eval>
var x = $gameVariables.value(13);
</Pre-Damage Eval>

<Damage Formula>
if (this._calculatedBaseDmg) {
   value = this._calculatedBaseDmg;
} else {
   if (target.isStateAffected(66) && v[13] >= 1) {
     target.removeState(66); this._calculatedBaseDmg = user.atk * 8 + user.mat * v[13] * 1.20;
   } else if (v[13] >= 1) {
     this._calculatedBaseDmg = user.atk * 4 + user.mat * v[13] * 1.20;
   } else if (target.isStateAffected(66)) {
     target.removeState(66); this._calculatedBaseDmg = user.atk * 8;
   } else {
     this._calculatedBaseDmg = user.atk * 4;
   }
   value = this._calculatedBaseDmg;
}
</Damage Formula>

^^*I had to do this because I had to account for another state

<Post-Damage Eval>
var x = $gameVariables.value(13);
var mpRecover = Math.floor(user.mmp * x * .10);
user.gainMp(mpRecover);
</Post-Damage Eval>


<After Eval>
$gameVariables.setValue(13, 0);
</After Eval>

And I had the Spellslinger spells that i Chose have a common event that adds 1 to the variable. That's it. nothing special.
Thank you for the counter thing... I was figuring out how to do that.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-passive-state-skill-using-variables.75196/