How to create a stun rate like in fighting games?

I'm actually not sure where to post this as I've posted this here before, but that was AGES ago and I didn't think it'd be a good idea to necro post on that. the other issue is the solution given while working, has a couple of flaws. I wasn't sure tho if that made it a plugin support issue tho or not because it's not an actual "problem" with the said plugin.

basically I wanted a stun rate in my game where once it hits a certain threshold, the actor becomes stunned. this is possible through Yanfly's Buff & States Core + Auto Passive States. here's the info for that...

<Custom React Effect>
if (value > 0 && this.isPhysical() && user.enemy()) {
target.addStateCounter(20, 20);
target.clampStateCounter(20, 0, 100);
}
</Custom React Effect>

<Custom React Effect>
if (value > 0 && this.isMagical() && user.enemy()) {
target.addStateCounter(20, 20);
target.clampStateCounter(20, 0, 100);
}
</Custom React Effect>

<Custom Deselect Effect>
if (target.getStateCounter(20) >= 100) {
target.removeStateCounter(20);
target.addState(4);
}
</Custom Deselect Effect>

but I was wondering a few things... 1. is there a way have it where say after the stun state, the counter can't go up for a few turns? to give the player a breather/chance to heal... 2. is there a way to lessen how much is added to the threshold when guarding? 3. is there a way to either heal or lower the threshold either naturally or by item? and lastly, is there a way to reset the threshold every fight? I thought removing the state would do it, but it doesn't.

Again, sorry if I've posted this in the wrong place. I only decided here in because it's where I initially posted this about a year ago.
I'd say we'd still want this in plug-in support as you are using a plug-in to accomplish those conditions. Also you can necro a thread you started, there is no rules against that. But since you opened this I'll keep it open.

Moved to Plug-in Support

Does this actually work in your game? I see functions in there but no definitions.
If it does work then you can fix your other issues easily. One thing at a time tho.

Links to the plugins mentioned will help.
actually yeah it works. I'm not ENTIRELY sure how as I'm not that great with Yanfly's Lunatic coding... but yeah, in game, the counter will start at 0 and each hit physical or magical adds 20 to it and once 100 is reached, the actor enters a stunned state. I was given the code when I made a thread initially over a year ago. but then I took a break from my game and now recently I realized a few things I wanted to change about the system so to speak. but as seen above, I didn't know I could repost in that thread after a set amount of time.

here's the link to the plugins tho...
https://yanflyengineplugins.itch.io/buffs-states-core/purchase?popup=1 for the Buff and States Core
https://yanflyengineplugins.itch.io/auto-passive-states/purchase?popup=1 for the Auto Passive States

if there's anything else you need from me, let me know and thanks!
Ok. I checked the buff & states core and found the function I was looking for.
So with that, it's fairly easy to do both.
So, first, to block the stun for a while, it's best to make a stun block state.
(It probably should NOT have an icon so it will be mostly invisible)
It doesn't have to do anything but should end after battle and last a turn or so.
Then you'll need to update your code about to reflect the state and how it will affect things.

<Custom React Effect>
if (value > 0 && this.isPhysical() && user.enemy()) {
if (!target.isStateAffected("put your block stun state's ID here") target.addStateCounter(20, 20);
target.clampStateCounter(20, 0, 100);
}
< /Custom React Effect>

Now, to change how much stun "damage" is taken, you can put a conditional to watch for a guard.
This one is a tiny but complicated, but still fairly simple:

<Custom React Effect>
var num = 20;
if (target.isStateAffected(2)) num / 2; //2 is the default guard state
if (value > 0 && this.isPhysical() && user.enemy()) {
if (!target.isStateAffected("put your block stun state's ID here")) target.addStateCounter(20, num);
target.clampStateCounter(20, 0, 100);
}
< /Custom React Effect>

Finally, in order to heal stun damage, you just have to use the addStateCounter call with a negative number.
so target.addStateCounter(20, -20) will reduce the total stun damage by 20.
The issue with this one is where will you place the script call.
You'll have to dig a little bit as you might need to apply it on the healing skill/item.

But this info should point you in the right direction.

Ask if you need any more clarification.

Good Luck!
the block stun rate skill works just as I had hoped! the only issue I'm having with what you've given me is getting the guard to work. BUT, thinking about it, I had it where the block stun state was tied to a character's guard (each one has a different guard due to different properties of the guard), and it blocking the stun that way is actually a good thing. more accurate to a fighting game that way as in the gauge/threshold usually doesn't increase if you're guarding. I still need to figure out the healing tho as I need to find a way to tie it to a skill or something first. thanks for all of your help tho!
There was a small typo in the formula for the guard one.

Try this:

<Custom React Effect>
var num = 20;
if (target.isStateAffected(2)) num /= 2; //2 is the default guard state
if (value > 0 && this.isPhysical() && user.enemy()) {
if (!target.isStateAffected("put your block stun state's ID here")) target.addStateCounter(20, num);
target.clampStateCounter(20, 0, 100);
}
< /Custom React Effect>

And you can add an if statement for each guard state.

As for the healing skill, if it uses the damage formula box, you can just put it in there.

Example:
b.addStateCounter(20, -20); 100
(With 100 being the healing amount.)
Just make sure the damage formula ALWAYS ends with the number of damage/healing.
everything works perfectly now! guarding reduces the amount of stun and the healing formula works as well. thanks a lot!
No prob.
hey I was wondering, and I'm not sure why I didn't ask this before... but is there a way to make this work on enemies as well? I feel it comes down to changing something within the react effect maybe? but if so, I'm unsure as to what...
I couldn't say.
Just try it out and post if it doesn't work.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-create-a-stun-rate-like-in-fighting-games.108353/