MV [SOLVED] Detect state

I am looking for how to know when a state is added to a player, basically I want to make a state that detects when the states of the same category were to be added to the same user. I use the majority of yep plugins.
The default function to check for a state on a battler is:

Game_BattlerBase.prototype.isStateAffected = function(stateId)

You can use that to check for a state on any battler, such as:

target.isStateAffected(x) $gameActors.actor(1).isStateAffected(x)

I'm not sure what you mean by "category." Is that a parameter added by a plugin you're using? Or just a mechanic you have in mind?

If it's the former, checking the state's category would depend on how the plugin handles that.

If it's the latter and you wanted to just handle it manually, you could add a notetag to your state like so:

<Category:Debuff>

And then check the if the battler both has the state and if it's a specific category:

var state = x; if (target.isStateAffected(x) && $dataStates[x].meta.Category === 'Debuff') { console.log('Do something.'); }

In terms of doing all of this stuff at the moment that a state is added to a battler versus at any arbitrary time, there's a function for that too.

Game_Battler.prototype.addState = function(stateId) { if (this.isStateAddable(stateId)) { if (!this.isStateAffected(stateId)) { this.addNewState(stateId); this.refresh(); } this.resetStateCounts(stateId); this._result.pushAddedState(stateId); } };

Which you can alias. Here's a quick example:

_Game_Battler_addState = Game_Battler.prototype.addState; Game_Battler.prototype.addState = function(stateId) { _Game_Battler_addState.call(this, stateId); console.log('Do something.'); }

I do know that the YEP plugins will allow you to perform some of these checks via notetags, so you may want to reference that if you would prefer to do it that way.

Not sure if that answers your question, but maybe it'll get you started.
that was absolutely wonderful and useful, you have opened a world of possibilities for me.
Just a couple of other things, in case they're helpful. Since you have the Yanfly plugins, you can give a state a <Custom Apply Effect> per the Buffs and State core, to give it code that will execute when it's applied to a battler.

That plugin also has a "counter" function, so if you're looking for some kind of stacking effect (you were non-specific as to what exactly you want to do), you can use that to track and manipulate how many times someone has received a given state.
I managed to do something combining your advice, thanks

Original thread: https://forums.rpgmakerweb.com/threads/solved-detect-state.134139/