[XP] changing the colors of the HP/SP bars script

MarioWidjaya123

Veteran
Veteran
Joined
May 16, 2020
Messages
187
Reaction score
6
First Language
English
Primarily Uses
RMXP
i have this script about adding HP/SP/EXP bars

Code:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Blizz-Art Gradient Styler with HP/SP/EXP bars by Blizzard
# Version: 4.51b
# Type: Game Playability Improvement
# Date v4.0: 13.11.2006
# Date v4.11: 12.1.2007
# Date v4.2b: 12.3.2007
# Date v4.4b: 14.7.2007
# Date v4.41b: 23.10.2007
# Date v4.5b: 25.10.2007
# Date v4.51b: 28.1.2008
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# new in v2.x:
#   - 2 styles, better code
#
# new in v3.x:
#   - 6 styles, far better code
#
# new in v4.0:
#   - 6 styles, overworked and extremely delagged, enjoy the most lagless
#     gradient/slant bar code ever
#
# new in v4.11:
#   - added instructions and a recognition constant for plugins
#
# new in v4.2b:
#   - improved code
#
# new in v4.4b:
#   - improved code, now 7 styles
#
# new in v4.41b:
#   - resolved issue
#
# new in v4.5b:
#   - improved coding
#   - removed drawing glitch that was caused by using a variable name shorter
#     than 4 letters
#
# new in v4.51b:
#   - fixed glitch with StormTronics CMS
#
#
# Instructions:
#
#   You can change style and opacity by using the "Call script" event command.
#   Use one of of these syntaxes:
#
#     $game_system.bar_style = X
#     $game_system.bar_opacity = Y
#
#   X - number from 0 to 6 and is the ID number of the style
#   Y - number from 0 to 255 and indicates the opacity
#   
#   Values out of range will be corrected.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

$Blizz_Art = true

#==============================================================================
# Game_System
#==============================================================================

class Game_System
 
  attr_accessor :bar_style
  attr_reader   :bar_opacity
  #----------------------------------------------------------------------------
  # initialize
  #  Added bar style variables.
  #----------------------------------------------------------------------------
  alias init_blizzart_later initialize
  def initialize
    init_blizzart_later
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#
#   Configure this part manually if you have no "Options" controller for the
#   styles and the opacity. (style: 0~6, opacity: 0~255)
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @bar_style = 0
    self.bar_opacity = 255
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  end
  #----------------------------------------------------------------------------
  # bar_opacity=
  #  alpha - opacity
  #  Encapsulation and range limitation of opacity.
  #----------------------------------------------------------------------------
  def bar_opacity=(alpha)
    @bar_opacity = [[alpha, 0].max, 255].min
  end
 
end

#==============================================================================
# Game_Actor
#==============================================================================

class Game_Actor
 
  #----------------------------------------------------------------------------
  # now_exp
  #  Returns the EXP collected in this level.
  #----------------------------------------------------------------------------
  def now_exp
    return @exp - @exp_list[@level]
  end
  #----------------------------------------------------------------------------
  # next_exp
  #  Returns the EXP needed to level up as number.
  #----------------------------------------------------------------------------
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
 
end

#==============================================================================
# Bitmap
#==============================================================================

class Bitmap

  #----------------------------------------------------------------------------
  # gradient_bar
  #  x      - x coordinate
  #  y      - y coordinate
  #  w      - width of the bar to be drawn
  #  color1 - primary color
  #  color2 - secondary color
  #  color3 - back color
  #  rate   - fill rate
  #  This special method is able to draw one out of 7 styles.
  #----------------------------------------------------------------------------
  def gradient_bar(x, y, w, color1, color2, color3, rate, flag = false)
    # stop if not active or out of range
    return unless $game_system.BARS || flag
    return if $game_system.bar_style < 0 || $game_system.bar_style > 6
    # styles with "vertical" black borders
    styles = [1, 3, 4, 5, 6]
    # setup of coordinates and offsets depending on style
    offs = 5
    x += offs
    y += 30
    if styles.include?($game_system.bar_style)
      offs += 2
      y -= 1
      [5, 6].include?($game_system.bar_style) ? y -= 2 :  x += 1
      # quantizes the width so it looks better (remove it and see what happens)
      w = w / 8 * 8
    end
    # temporary variable
    a = $game_system.bar_opacity
    if $game_system.bar_style < 5
      # draw black slanted back
      (0...(offs+3)).each {|i| fill_rect(x-i, y+i-2, w+3, 1, Color.new(0, 0, 0))}
      # draw white slanted back onto black, but let black borders stay
      (0...(offs+1)).each {|i| fill_rect(x-i, y+i-1, w+1, 1, Color.new(255, 255, 255))}
      if $game_system.bar_style < 2
        # iterate through each vertical bar
        (0...w+offs).each {|i|
            # calculate color
            r = color3.red * i / (w+offs)
            g = color3.green * i / (w+offs)
            b = color3.blue * i / (w+offs)
            # special offset calculation
            oy = i < offs ? offs-i : 0
            off = i < offs ? i : i > w ? w+offs-i : offs
            # draw this part of the bar
            fill_rect(x+i-offs+1, y+oy-1, 1, off, Color.new(r, g, b, a))}
        # if slanted bar is out of critical area
        if (w*rate).to_i >= offs
          # draw the little triangular part on the left
          (0...((w*rate).to_i+offs)).each {|i|
              r = color1.red + (color2.red-color1.red)*i / ((w+offs)*rate)
              g = color1.green + (color2.green-color1.green)*i / ((w+offs)*rate)
              b = color1.blue + (color2.blue-color1.blue)*i / ((w+offs)*rate)
              oy = i < offs ? offs-i : 0
              off = i < offs ? i : i > w*rate ? (w*rate).to_i+offs-i : offs
              fill_rect(x+i-offs+1, y+oy-1, 1, off, Color.new(r, g, b, a))}
        else
          # draw the little triangular part on the left using special method
          (0...(w * rate).to_i).each {|i| (0...offs).each {|j|
              r = color1.red + (color2.red-color1.red)*i / (w*rate)
              g = color1.green + (color2.green-color1.green)*i / (w*rate)
              b = color1.blue + (color2.blue-color1.blue)*i / (w*rate)
              set_pixel(x+i-j+1, y+j-1, Color.new(r, g, b, a))}}
        end
      else
        # iterate through all horizontal lines
        (0...offs).each {|i|
            # calculate colors
            r = color3.red * i / offs
            g = color3.green * i / offs
            b = color3.blue * i / offs
            # draw background line
            fill_rect(x-i+1, y+i-1, w, 1, Color.new(r, g, b, a))}
        if $game_system.bar_style == 4
          # iterate through half of all horizontal lines
          (0...offs/2+1).each {|i|
              # calculate colors
              r = color2.red * (i+1) / (offs/2)
              g = color2.green * (i+1) / (offs/2)
              b = color2.blue * (i+1) / (offs/2)
              # draw bar line
              fill_rect(x-i+1, y+i-1, w*rate, 1, Color.new(r, g, b, a))
              # draw bar line mirrored vertically
              fill_rect(x-offs+i+2, y+offs-i-2, w*rate, 1, Color.new(r, g, b, a))}
        else
          # iterate through all horizontal lines
          (0...offs).each {|i|
              # calculate colors
              r = color1.red + (color2.red-color1.red)*i / offs
              g = color1.green + (color2.green-color1.green)*i / offs
              b = color1.blue + (color2.blue-color1.blue)*i / offs
              # draw bar line
              fill_rect(x-i+1, y+i-1, w*rate, 1, Color.new(r, g, b, a))}
        end
      end
      # if style with black vertical slanted intersections
      if styles.include?($game_system.bar_style)
        # add black bars on 1st and 8th column every 8 pixels
        (0...w).each {|i| (0...offs).each {|j|
            if styles.include?($game_system.bar_style) && i % 8 < 2
              set_pixel(x+i-j+1, y+j-1, Color.new(0, 0, 0, a))
            end}}
      end
    else
      # fill white background
      fill_rect(x+1, y-3, w+2, 12, Color.new(255, 255, 255, a))
      # iterate through each of 6 lines
      (1...6).each {|i|
          # calculate background color
          color = Color.new(color3.red*i/5, color3.green*i/5, color3.blue*i/5, a)
          # draw background
          fill_rect(x+2, y+i-3, w, 12-i*2, color)
          # calculate bar color
          color = Color.new(color2.red*i/5, color2.green*i/5, color2.blue*i/5, a)
          # draw bar
          fill_rect(x+2, y+i-3, w*rate, 12-i*2, color)}
      # if style 5 (with vertical borders)
      if $game_system.bar_style == 5
        # add black bars on 1st and 8th column every 8 pixels
        (0...w/8).each {|i|
            fill_rect(x+2+i*8, y-2, 1, 10, Color.new(0, 0, 0, a))
            fill_rect(x+2+(i+1)*8-1, y-2, 1, 10, Color.new(0, 0, 0, a))}
      end
    end
  end
 
end

#==============================================================================
# Window_Base
#==============================================================================

class Window_Base

  #----------------------------------------------------------------------------
  # draw_actor_hp
  #  actor - the actor
  #  x      - x coordinate
  #  y      - y coordinate
  #  w      - reserved max width
  #  Added fill rate calculation and bar drawing.
  #----------------------------------------------------------------------------
  alias draw_actor_hp_blizzart_later draw_actor_hp
  def draw_actor_hp(actor, x, y, w = 148)
    if $game_system.BARS
      # RTAB compatibility fix
      if !(defined? Window_DetailsStatus) || !self.is_a?(Window_DetailsStatus)
        w -= 12
      end
      # calculate bar fill rate
      rate = (actor.maxhp > 0 ? actor.hp.to_f / actor.maxhp : 0)
      # create colors depending on rate
      if rate > 0.6
        color1 = Color.new(80 - 150 * (rate-0.6), 80, 50 * (rate-0.6), 192)
        color2 = Color.new(240 - 450 * (rate-0.6), 240, 150 * (rate-0.6), 192)
      elsif rate > 0.2 && rate <= 0.6
        color1 = Color.new(80, 200 * (rate-0.2), 0, 192)
        color2 = Color.new(240, 600 * (rate-0.2), 0, 192)
      elsif rate <= 0.2
        color1 = Color.new(400 * rate, 0, 0, 192)
        color2 = Color.new(240, 0, 0, 192)
      end
      # background color
      color3 = Color.new(0, 80, 0, 192)
      # draw bar with coordinates and colors
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
      if $scene.is_a?(Scene_Battle)
        draw_actor_hp_blizzart_later(actor, x, y, w)
      else
        draw_actor_hp_blizzart_later(actor, x, y)
      end
    else
      draw_actor_hp_blizzart_later(actor, x, y, w)
    end
  end
  #----------------------------------------------------------------------------
  # draw_actor_sp
  #  actor - the actor
  #  x      - x coordinate
  #  y      - y coordinate
  #  w      - reserved max width
  #  Added fill rate calculation and bar drawing.
  #----------------------------------------------------------------------------
  alias draw_actor_sp_blizzart_later draw_actor_sp
  def draw_actor_sp(actor, x, y, w = 148)
    if $game_system.BARS
      # RTAB compatibility fix
      if !(defined? Window_DetailsStatus) || !self.is_a?(Window_DetailsStatus)
        w -= 12
      end
      # calculate bar fill rate
      rate = (actor.maxsp > 0 ? actor.sp.to_f / actor.maxsp : 0)
      # create colors depending on rate
      if rate > 0.4
        color1 = Color.new(60 - 66 * (rate-0.4), 20, 80, 192)
        color2 = Color.new(180 - 200 * (rate-0.4), 60, 240, 192)
      elsif rate <= 0.4
        color1 = Color.new(20 + 100 * rate, 50 * rate, 26 + 166 * rate, 192)
        color2 = Color.new(60 + 300 * rate, 150 * rate, 80 + 400 * rate, 192)
      end
      # background color
      color3 = Color.new(0, 0, 80, 192)
      # draw bar with coordinates and colors
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
      if $scene.is_a?(Scene_Battle)
        draw_actor_sp_blizzart_later(actor, x, y, w)
      else
        draw_actor_sp_blizzart_later(actor, x, y)
      end
    else
      draw_actor_sp_blizzart_later(actor, x, y, w)
    end
  end
  #----------------------------------------------------------------------------
  # draw_actor_exp
  #  actor - the actor
  #  x      - x coordinate
  #  y      - y coordinate
  #  w      - reserved max width
  #  Added fill rate calculation and bar drawing.
  #----------------------------------------------------------------------------
  alias draw_actor_exp_blizzart_later draw_actor_exp
  def draw_actor_exp(actor, x, y, w = 148)
    if $game_system.BARS
      w += 12
      # calculate bar fill rate
      rate = (actor.next_exp != 0 ? actor.now_exp.to_f / actor.next_exp : 1)
      # create colors depending on rate
      if rate < 0.5
        color1 = Color.new(20 * rate, 60, 80, 192)
        color2 = Color.new(60 * rate, 180, 240, 192)
      elsif rate >= 0.5
        color1 = Color.new(20 + 120 * (rate-0.5), 60 + 40 * (rate-0.5), 80, 192)
        color2 = Color.new(60 + 360 * (rate-0.5), 180 + 120 * (rate-0.5), 240, 192)
      end
      # background color
      color3 = Color.new(80, 80, 80, 192)
      # draw bar with coordinates and colors
      self.contents.gradient_bar(x, y, w, color1, color2, color3, rate)
    end
    draw_actor_exp_blizzart_later(actor, x, y)
  end
 
end
but i dont know how to change the colors, it all too complicated...what is the simpler way to do that?
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,660
Reaction score
563
First Language
English
Primarily Uses
RMVXA
For each part of the script that has
color#(1, 2 or 3) = Color.new(red, green, blue, opacity)
you can play with adjusting the numbers.
for example
Color.new(20 + 100 * rate, 50 * rate, 26 + 166 * rate, 192)
could be adjusted to give another output.
Color.new(120 + 10 * rate, 150 * rate, 60 + 10 * rate, 220)
Notice that *here* and *here* and *here* and *here* are changed.
They coordinate to the values red, green, blue, opacity.
The values range from 0 to 255.
So change one and see what you get. then change another.
The higher the number gives you more of that color's presence.
If you put the numbers to high (it does calculations) then it will only go to 255, and it can only go to 0 as the low.
I do not know of another script to do what you want as I don't use XP much.
 

MarioWidjaya123

Veteran
Veteran
Joined
May 16, 2020
Messages
187
Reaction score
6
First Language
English
Primarily Uses
RMXP
@Roninator2
actually... i figured out how to connect the Overdrive Script with the HP/SP/ATB/LB Script.
with this

Code:
def draw_actor_overdrive_with_bar(actor, x, y, w = 148)
    w -= 12
    rate = actor.overdrive.to_f / 1000
    color1 = Color.new(80, 0, 0, 192)
    color2 = Color.new(240, 0, 0, 192)
    color3 = Color.new(80, 0, 0, 192)
    if BlizzCFG::RTAB_ACTIVE
      color1.alpha = color2.alpha = 255
      draw_slant_bar(x, y + 12, actor.overdrive, 1000, w, 6, color1, color2)
    else
      self.draw_actor_od(actor, x, y, width = 120)
    end
    if $scene.is_a?(Scene_Battle)
      draw_actor_overdrive(actor, x, y, w)
    else
      draw_actor_overdrive(actor, x, y)
    end
  end

end
connected with this

Code:
  #=========================================================================
  # * Draw Actor Overdrive Bar
  #     actor : Actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #=========================================================================
  def draw_actor_od(actor, x, y, width = 120)
    rate = actor.overdrive.to_f / 1000
    plus_x = 0
    rate_x = 0
    plus_y = 26
    plus_width = 0
    rate_width = 100
    height = 6
    lb = (width + plus_width) * actor.overdrive * rate_width / 100 / 1000
    # Drawing of gauge
    if actor.overdrive == 1000
      # Draw Silver Yellow Bar
      draw_slant_bar(x + plus_x + width * rate_x / 100, y + plus_y, lb, width,
        width, height, od_color1 = Color.new(255,255,0,192),
        od_color2 = Color.new(255,255,150,192))
    else
      # Draw Orange Bar
      draw_slant_bar(x + plus_x + width * rate_x / 100, y + plus_y, lb, width,
        width, height, od_color1 = Color.new(255, 136, 0, 128),
        od_color2 = Color.new(255, 255, 0, 191))
    end
  end
end
i changed from the Limit Break Bar to the Overdrive Bar to replace it.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,090
Members
137,586
Latest member
Usagiis
Top