Change color of MP Bar mid-battle based on State

Okay so, since this is a complicated and weird question that I was unable to find ANYWHERE I'm going to explain it as simply as possible with pictures.

So, you know the MP bar, mid battle? The blue bar on the right of the HP.
1f6fb4825d815b792ff130d2b3b8432a.png

I want to know if it is possible to change this bar mid-battle to a different color whenever a state is activated/deactivated.
I want to change it to yellow when a state is inflicted upon my character. So it would be something like this:
mpyellow.png

So when the state is deactivated/removed, it is changed back to blue.
Is this possible on RPG Maker VX Ace? If not, is it even possible on ANY RPG Maker? Maybe MZ or MV? Please let me know and thank you.
Set the states that will cause the colour change and set the colours used in the text_color part
Ruby:
module R2_MP_Colour_Change
  CHANGE_STATE = [2,5]
end
class Window_Base < Window
  def mp_gauge_color_state1; text_color(10);  end;    # MP gauge 1
  def mp_gauge_color_state2; text_color(10);  end;    # MP gauge 2
  def draw_actor_mp(actor, x, y, width = 124)
    draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
    actor.states.each do |state|
      if R2_MP_Colour_Change::CHANGE_STATE.include?(state.id)
        draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color_state1, mp_gauge_color_state2)
      end
    end
    change_color(system_color)
    draw_text(x, y, 30, line_height, Vocab::mp_a)
    draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
      mp_color(actor), normal_color)
  end
end
Moved to: RGSS3 Script Requests

You would need a script/plugin no matter what engine you wanted to use.
Moved to: RGSS3 Script Requests

You would need a script/plugin no matter what engine you wanted to use.
I apologize. I was unaware that this should've been in the Script Requests forum. It will not happen again. Sorry about that. I'm going to try Rominator's script and see if it works.

Set the states that will cause the colour change and set the colours used in the text_color part
Ruby:
module R2_MP_Colour_Change
  CHANGE_STATE = [2,5]
end
class Window_Base < Window
  def mp_gauge_color_state1; text_color(10);  end;    # MP gauge 1
  def mp_gauge_color_state2; text_color(10);  end;    # MP gauge 2
  def draw_actor_mp(actor, x, y, width = 124)
    draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
    actor.states.each do |state|
      if R2_MP_Colour_Change::CHANGE_STATE.include?(state.id)
        draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color_state1, mp_gauge_color_state2)
      end
    end
    change_color(system_color)
    draw_text(x, y, 30, line_height, Vocab::mp_a)
    draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
      mp_color(actor), normal_color)
  end
end
It works but I'm unable to change the color from Red. I'm aware of the color codes in RPG Maker VX Ace (18 is yellow.) I changed the two color codes in MP gauge 1 and 2 to 18 and nothing changed. I'm also putting it under Materials (i'm not sure if I should put it there or not.) It is stuck on Red no matter what I change the "def mp_gauge_color-state; text_color(number);" number variable to.
color codes.png

yellow is 17
Thank you, it worked! But I want to know if it is possible to have multiple different states with different colors. I'm only able to have 1 state have a color. I tried changing the "MP Gauge 2" to be a different color for the 2nd state ID, as I'm guessing that is what that is for, but it did not work. I also tried copy-pasting the module with a different state ID and color but it did not work either.

I want to know if it is possible to change the color for the text "MP" above the MP bar as well as the number above the bar displaying your MP. If it is not, this is not a problem, the most important thing is the MP Bar.
multiple different states with different colors.
The best way for that would be to use note tags. Then you can specify in each state what color the bar will be.
Do you want the letters to change colour for each state as well? will they be the same colour or different colour for each state or just a different colour when a state is applied?

The script, as is, is designed to allow changing the bar to the colours specified for all of the states that are listed.
[2,5] = both states will change the bar colour when the state is applied.

def mp_gauge_color_state1; text_color(10); end; # MP gauge 1
def mp_gauge_color_state2; text_color(10); end; # MP gauge 2

These are used together for the one bar. They are not separate bars or allow two colours. instead they are a colour range. mp colour 1 is the start of the bar and mp colour 2 is the end of the bar.
The best way for that would be to use note tags. Then you can specify in each state what color the bar will be.
Do you want the letters to change colour for each state as well? will they be the same colour or different colour for each state or just a different colour when a state is applied?

The script, as is, is designed to allow changing the bar to the colours specified for all of the states that are listed.
[2,5] = both states will change the bar colour when the state is applied.

def mp_gauge_color_state1; text_color(10); end; # MP gauge 1
def mp_gauge_color_state2; text_color(10); end; # MP gauge 2

These are used together for the one bar. They are not separate bars or allow two colours. instead they are a colour range. mp colour 1 is the start of the bar and mp colour 2 is the end of the bar.
Oh, I see. And yes, I would like to have the letters change to be a different color for each state. 5 states to be orange-yellowish bar and letters, 1 state to be light yellow, 2 states to be dark red, 1 state to be blue, 4 states to be white, and 1 state to be pink. I know, a lot of states. I'm willing to use note tags. Maybe use a notetag on a state like <statecolor:17> to be yellow, and <statecolor:18> to be dark red on another state, which would change the color of the bar and letters with the MP number.
Unless you want to use a note tag for the MP text colour then this should do what you want.
I added a tag for colour priority. So if you use it on all the states, you can set an order for which state takes priority for changing the mp bar.
Spoiler: Roninator2 - MP Colour Bar Change
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Change MP Bar Colour         ║  Version: 1.1      ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Display different colours by state  ║    13 May 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Displays the MP bar in another colour when the           ║
# ║ battler is inflicted with a state note tagged.           ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Place the following note tag on the state that will      ║
# ║ change the MP bar colour                                 ║
# ║ <state color: 0, 0>                                      ║
# ║ This will make the MP bar show as white                  ║
# ║ The numbers are from the VX Ace colour wheel             ║
# ║                                                          ║
# ║ The first number is for the state of the bar,            ║
# ║ The second number is for the end of the bar.             ║
# ║ By default the mp bar colours are 22, 23                 ║
# ║                                                          ║
# ║  0 - white,         1 - medium blue,   2 - red-orange    ║
# ║  3 - light green,   4 - light blue,    5 - light purple  ║
# ║  6 - yellow-orange, 7 - medium grey,   8 - light grey    ║
# ║  9 - deep blue.    10 - red,          11 - deep green    ║
# ║ 12 - blue,         13 - purple-blue,  14 - orange-yellow ║
# ║ 15 - black,        16 - blue-purple,  17 - yellow        ║
# ║ 18 - deep red,     19 - dark grey,    20 - orange        ║
# ║ 21 - light orange, 22 - dark blue,    23 - bright blue   ║
# ║ 24 - bright green, 25 - brown,       26 - blue-purple-red║
# ║ 27 - pink,         28 - deep green,   29 - green         ║
# ║ 30 - deep purple,  31 - purple                           ║
# ║                                                          ║
# ║ The second value to use is optional                      ║
# ║    <state color order: 3>                                ║
# ║ This will make the priority of this state colour change  ║
# ║ take third priority. So if state 2 is applied and is     ║
# ║ priority 4, then state 6 is applied and is priority 3,   ║
# ║ state 2 will stay the colour and it will not change to   ║
# ║ state 6. Without this state 6 would take over and apply  ║
# ║ it's colour change as it is further down in order.       ║
# ║ NOTE*                                                    ║
# ║ If you use the second note tag in only a few states,     ║
# ║ you may not get the desired results.                     ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ This was as best my eye and monitor could see the colours║
# ║ You can search for VX ACE color codes for a second look. ║
# ╚══════════════════════════════════════════════════════════╝
# ╔═════════════════════════════════════╗
# ║ Terms of use:                       ║
# ║ Free for all uses in RPG Maker      ║
# ╚═════════════════════════════════════╝

module R2_MP_Colour_Change
  MP_STATE_COLOUR = /<state[-_ ]color:[ ](\d+),[ ](\d+)>/i
  MP_COLOUR_ORDER = /<state[-_ ]color[-_ ]order:[ ](\d+)>/i
end
# Color.new(255, 255, 255, 255)
module DataManager
 
  class <<self; alias load_database_original_state_colour load_database; end
  def self.load_database
    load_database_original_state_colour
    load_notetags_mp_colour
  end
 
  def self.load_notetags_mp_colour
    for state in $data_states
      next if state.nil?
      state.load_notetags_mp_colour
    end
  end
 
end # DataManager

class RPG::State < RPG::BaseItem
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :state_mp_colour
  attr_accessor :state_mp_colour_order
 
  #--------------------------------------------------------------------------
  # common cache: load_notetags_sani
  #--------------------------------------------------------------------------
  def load_notetags_mp_colour
    @state_mp_colour = []
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when R2_MP_Colour_Change::MP_STATE_COLOUR
        @state_mp_colour = [$1.to_i, $2.to_i]
      when R2_MP_Colour_Change::MP_COLOUR_ORDER
        @state_mp_colour_order = $1.to_i
      end
    } # self.note.split
    #---
  end
 
end # RPG::State

class Window_Base < Window
  def draw_actor_mp(actor, x, y, width = 124)
    @colour_order = 0
    @previous_colour = []
    draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
    change_color(system_color)
    draw_text(x, y, 30, line_height, Vocab::mp_a)
    actor.states.each do |state|
      if !state.state_mp_colour.empty?
        if !state.state_mp_colour_order.nil? && @colour_order < state.state_mp_colour_order
          draw_gauge(x, y, width, actor.mp_rate, text_color(state.state_mp_colour[0]), text_color(state.state_mp_colour[1]))
          change_color(text_color(state.state_mp_colour[1]))
          draw_text(x, y, 30, line_height, Vocab::mp_a)
        else
          state.state_mp_colour = @previous_colour if !@previous_colour.empty?
          draw_gauge(x, y, width, actor.mp_rate, text_color(state.state_mp_colour[0]), text_color(state.state_mp_colour[1]))
          change_color(text_color(state.state_mp_colour[1]))
          draw_text(x, y, 30, line_height, Vocab::mp_a)
        end
      end
      @colour_order = state.state_mp_colour_order
      @previous_colour = state.state_mp_colour
    end
    draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
      mp_color(actor), normal_color)
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/change-color-of-mp-bar-mid-battle-based-on-state.137876/