[RMXP] If a status is applied to an ally with an incompatible status (i.e. both statuses are set to remove the other), keep the old, previous status?

I have a project where (due to the limitations of RPGmaker XP showing only one status at a time), I want to ensure only one status can be applied to a given character at any time so information isn't hidden from the player. So all statuses are generally set to either remove each other or be replaced by a higher-rated status.

However, this means it's very easy to remove a status just by applying a new one and I want to make that harder to do - so by default, I'd like to make new statuses unable to be applied when someone is already afflicted with a status. As-is, it looks like statuses overwrite each other and I can't find a way to undo that.

Alternatively, if there's a script that can make multiple statuses show per character (such as alternating every second between which status is shown), that would work fantastic as well.
This simplified re-define of Game_Battler#add_state should do it, state-inflicts should be refused if there's already one. Please also test if knockout is still working properly since states with ZeroHP-setting still have to overwrite any state that was previously there instead.

Ruby:
#==============================================================================
# ** Limit Battler States to 1
#------------------------------------------------------------------------------
#  All incoming states will be blocked if there is already one.
#  Applying a ZeroHP-state (like Knockout) will vaporize previous state.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Add State
  #--------------------------------------------------------------------------
  def add_state(si, sf=false)
    return unless $data_states[si]
    unless sf
      @states.each do |i|
        next unless $data_states[i].minus_state_set.include?(si)
        return unless $data_states[si].minus_state_set.include?(i)
      end
    end
    unless state?(si)
      return unless @states.empty? || $data_states[si].zero_hp
      @states.clear
      @states_turn.clear
      @states.push(si)
      @hp = 0 if $data_states[si].zero_hp
    end
    @states_turn[si] = -1 if sf
    unless @states_turn[si] == -1
      @states_turn[si] = $data_states[si].hold_turn
    end
    @current_action.clear unless movable?
    @hp = [@hp, maxhp].min
    @sp = [@sp, maxsp].min
  end
end

~炬燵あ
Unfortunately it crashed and gave me this error when a second status was applied:
1681126463352.png
Oups. I accidentally did a wrong type of iteration there, it's "each", not "each_index".

~炬燵あ
It's working great now, thank you!
Would it be alright if I could ask you to add in an exception for states with a rating of 0? I only realized after I asked for this script that this would interrupt a lot of hidden states I use for eventing that the player doesn't see.
Would it be alright if I could ask you to add in an exception for states with a rating of 0? I only realized after I asked for this script that this would interrupt a lot of hidden states I use for eventing that the player doesn't see.
Late answer because I didn't see it before. This might do it, I'm not fully sure about.

Ruby:
#==============================================================================
# ** Limit Battler States to 1 (Zero Exceptor Edition)
#------------------------------------------------------------------------------
#  All incoming states will be blocked if there is already one.
#  Applying a ZeroHP-state (like Knockout) will vaporize previous state.
#  Invisible states (those with rating set to 0) will not block anything.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Add State
  #--------------------------------------------------------------------------
  def add_state(si, sf=false)
    return unless $data_states[si]
    unless sf || $data_states[si].rating == 0
      @states.each do |i|
        next unless $data_states[i].minus_state_set.include?(si)
        return unless $data_states[si].minus_state_set.include?(i)
      end
    end
    unless state?(si)
      unless $data_states[si].zero_hp
        if $data_states[si].rating > 0
          return if @states.any? {|i| $data_states[i].rating > 0 }
        end
        @states.dup.each do |i|
          next if $data_states[i].rating == 0
          @states.delete(i)
          @states_turn.delete(i)
        end
      else
        @states.clear
        @states_turn.clear
      end
      @states.push(si)
      @hp = 0 if $data_states[si].zero_hp
    end
    @states_turn[si] = -1 if sf
    unless @states_turn[si] == -1
      @states_turn[si] = $data_states[si].hold_turn
    end
    @current_action.clear unless movable?
    @hp = [@hp, maxhp].min
    @sp = [@sp, maxsp].min
  end
end

~炬燵あ
Oh, thank you! I notice it just mentions 0-rating statuses won't block anything; do they still get blocked if the target already has a status?
Seems I had forgotten to properly add that case.

Have added a condition that only will reject a new state if not only any of states present has rating 1 or above, but also the new one. So inflicting something with rating 0 should be fine now.

A state with ZeroHP like [Knockout] will still wipe everything what's there, but theoretically it might not prevent inflicts of new rating-0-states while the character is knocked out.

~炬燵あ

Original thread: https://forums.rpgmakerweb.com/threads/rmxp-if-a-status-is-applied-to-an-ally-with-an-incompatible-status-i-e-both-statuses-are-set-to-remove-the-other-keep-the-old-previous-status.156548/