Limiting number of states to a battler

Hi everyone,

Does anyone know of a way to limit the number of states that can affect a single battler at any one time? I want battlers to have a max of three states, any other states that are applied while three are active will fail and not be applied. A plugin that does this will also be appreciated.
This might be possible with Yanfly's Buffs & States. You can also put this code into a plugin and states will not be applied if the battler is already affected by 3 states. Change the 3 where it says this.states().length < 3 to allow a different number of states. Alternately you could put $gameVariables.value(VARIABLE# OF YOUR CHOICE) in place of the 3 which would allow you to change the number of states that could be applied whenever you want by changing the value of the variable.

Game_Battler.prototype.addState = function(stateId) {
if (this.isStateAddable(stateId) && this.states().length < 3) {
if (!this.isStateAffected(stateId)) {
this.addNewState(stateId);
this.refresh();
}
this.resetStateCounts(stateId);
this._result.pushAddedState(stateId);
}
};
Thanks! I'll try/check that out.

Original thread: https://forums.rpgmakerweb.com/threads/limiting-number-of-states-to-a-battler.97421/