Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

HP/SP Colour Change

I need a script that changes the colour of the HP and SP displays as HP and SP change in value

While HP/SP is 76% or higher, I want the display color to be green
While HP/SP is 51-75%, I want the display color to be white
While HP/SP is 26-50%, I want the display color to be yellow
While HP/SP is 25% or lower, I want the display color to be red

I hope this request isn't too vague :)
 
Code:
#==============================================================================
# ** Window_Base
# Edit to window base to change the color of hp/sp for Admiral_Stalfos19
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Determines the color to draw hp/sp
  #--------------------------------------------------------------------------
  def determine_color(current, max)
    self.contents.font.color = current == 0 ? knockout_color :
      current <= max / 4 ? text_color(2) : 
      current <= max / 2 ? text_color(6) :
      current <= max / 4 * 3 ? text_color(0) : text_color(3)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw "HP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    # Draw HP
    determine_color(actor.hp, actor.maxhp)
    self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
    # Draw MaxHP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw "SP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      sp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      sp_x = x + width - 48
      flag = false
    end
    # Draw SP
    determine_color(actor.sp, actor.maxsp)
    self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
    # Draw MaxSP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
    end
  end
end
That should work for you. (Add it anywhere below Window_Base and above Main)
 
def determine_color(current, max)
    self.contents.font.color = current == 0 ? knockout_color :
      current <= max / 4 ? text_color(2) :
      current <= max / 2 ? text_color(6) :
      current <= max / 4 * 3 ? text_color(0) : text_color(3)

^Are the question marks supposed to be there?

EDIT: Suppose so... Thanks anyway
 
Sorry, I left for dinner right after posting it.

Yes, the question marks serve as a compressed version of an "if else" statement.
I based it off the original statement for determining the color:
Code:
self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color

Feel free to disregard this reply if you know nothing of scripting and it confuses you ^^;
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top