MZ Limit on States

Hi! I was wondering if it´d be possible to have a plugin to limit the amount of States to only 1 based on priority (so maybe a higher priority state can´t be override by a lower priority state) so if an enemy/actor has already poison and you cast mute on them the action fails but if you cast death the death state overrides the poison state.

Thanks a mil in advance!!
Try putting this in a plugin:

JavaScript:
(() => {
  const _Game_Battler_addState = Game_Battler.prototype.addState;
  Game_Battler.prototype.addState = function (stateId) {
    const states = this.states();
    if (states.length) {
      const highestStatePriority = Math.max.apply(
        null,
        states.map((it) => it.priority)
      );
      if ($dataStates[stateId].priority > highestStatePriority) {
        this.clearStates();
        _Game_Battler_addState.call(this, stateId);
      }
    } else {
      _Game_Battler_addState.call(this, stateId);
    }
  };
})();

Explanation:
  • whenever a state is applied, it will first check to see if there are any current states on that battler.
  • if there are, it will find the one with the highest priority.
  • then it will check if the new state is higher priority than the highest priority state, clear out all existing states, and apply the new one.
  • if not, it will skip applying the state.
But important caveat: If the new state has equal priority to an old state, it will be skipped too.
Try putting this in a plugin:

JavaScript:
(() => {
  const _Game_Battler_addState = Game_Battler.prototype.addState;
  Game_Battler.prototype.addState = function (stateId) {
    const states = this.states();
    if (states.length) {
      const highestStatePriority = Math.max.apply(
        null,
        states.map((it) => it.priority)
      );
      if ($dataStates[stateId].priority > highestStatePriority) {
        this.clearStates();
        _Game_Battler_addState.call(this, stateId);
      }
    } else {
      _Game_Battler_addState.call(this, stateId);
    }
  };
})();

Explanation:
  • whenever a state is applied, it will first check to see if there are any current states on that battler.
  • if there are, it will find the one with the highest priority.
  • then it will check if the new state is higher priority than the highest priority state, clear out all existing states, and apply the new one.
  • if not, it will skip applying the state.
But important caveat: If the new state has equal priority to an old state, it will be skipped too.
It works perfect!! thanks a million!!
This thread is closed due to being reported as solved. If you need it reopened, report it to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/limit-on-states.178080/