MV YEP State Stack/Counters Help

Hi all, I could use some assistance. I'm trying to use state counters as a skill resource similar to TP but I'm running into some issues. If possible, for the Warrior state, I would like the counter to increase proportional to the damage the actor is dealing. This is the code I'm using:

Code:
<Custom Apply Effect>
user._warriorStacks = user._warriorStacks || 0;
var stacks = user._warriorStacks.clamp(0, 100);
user.setStateCounter(21, 'x' + stacks);
</Custom Apply Effect>

<Custom Remove Effect>
user._warriorStacks = 0;
var stacks = user._warriorStacks.clamp(0, 100);
user.setStateCounter(21, 'x' + stacks);
</Custom Remove Effect>

<Custom Establish Effect>
if (this.isPhysical() && value > 0) {
  user._warriorStacks = user._warriorStacks || 0;
  var stacks = user._warriorStacks.clamp(0, 100);
  stacks += Math.ceil(value * 100 / target.mhp) * user.tcr;
  stacks = stacks.clamp(0, 100);
  user.setStateCounter(21, 'x' + stacks);
  user._warriorStacks = stacks;
}
</Custom Establish Effect>

This is working just as it should! If the enemy's HP is 200, and the warrior deals 63 damage, his counter is increasing by 32. If the enemy's HP is 2000, and the warrior deals 63 damage, his counter is increasing by 4.

I wanted to throw in a Math.min to ensure it always increase by at least 16
Code:
stacks += Math.min(16, Math.ceil(value * 100 / target.mhp)) * user.tcr;
but now it only increases by 16, no matter how much damage I deal. I tried changing it to
Code:
stacks += Math.min(16, value) * user.tcr;
and same thing, it's always defaulting to 16. Am I using Math.min wrong? Should I be setting a minimum another way?
my guess is you dont have a max stacks to it.

like stacks = 0;
maxStacks = 5;

than you want to check if stacks > 0 to give +16
and increases untill max stacks is hit.

or a conditional to increase the stacks++.
but I dont know lunatic codes or messes with it 🙂
Hope you know what I mean.
my guess is you dont have a max stacks to it.

isn't that what clamp does, set the min and max stacks?

Code:
var stacks = user._warriorStacks.clamp(0, 100);
  stacks += Math.ceil(value * 100 / target.mhp) * user.tcr;
  stacks = stacks.clamp(0, 100);
For a lower bound, you want to return the larger value. I.e. if the input is less than 16, return 16. Try Math.max instead. 👋
For a lower bound, you want to return the larger value. I.e. if the input is less than 16, return 16. Try Math.max instead. 👋

Oh my god. 😅

Thank you so much! Warrior state is working perfect now. Additionally, so are my Mage and Healer states.

Original thread: https://forums.rpgmakerweb.com/threads/yep-state-stack-counters-help.148249/