Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Super Simple Gradient Bars
amaranth
post Dec 21 2008, 07:13 PM
Post #1


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




I'm moving all of my scripts from rmxp.org to this site. I like it here better.

Introduction
I made this script because I wanted a gradient bar that didn't require a huge chunk of code to implement. This script creates a gradient bar that starts at a color and fades into white (or another color). You can call it from anywhere in your game where you want to display a gradient bar. From battle, from the menu, wherever. All you have to do is call the following function, draw_bar.



Create draw_bar

In this section, we will create the gradient bar.

1. Open your game and script editor.

2. Add the following script at the end of Window_Base.

CODE
  #--------------------------------------------------------------------------
  # ● Draw a gradient bar
  #     actor : actor assigned to the bar
  #     x          : X coordinate of the upper-left pixel of the bar
  #     y          : Y coordinate of the upper-left pixel of the bar
  #     bar_width  : width of the bar
  #     bar_height : height of the bar
  #     current    : current value to compare (eg. hp, sp, exp)
  #     max        : max value to compare (eg. max hp, max sp, max exp)
  #     color      : base color to use (eg. text_color(5))
  #--------------------------------------------------------------------------  
  def draw_bar(actor, x, y, bar_width, bar_height, current, max, color)
    
    adj_width = bar_width - 4
    adj_height = bar_height - 4
    
    # outline of bar
    border_color = Color.new(255, 255, 255, 255)
    self.contents.fill_rect(x + 3, y + 8, bar_width, bar_height, border_color)
    
    # background of bar
    background_color = Color.new(0, 0, 0, 255)
    self.contents.fill_rect(x + 5, y + 10, adj_width, adj_height, background_color)
    
    # current bar
    if max != 0

      percent = (current * 100) / max
      adj_width = (adj_width * percent) / 100  
      
      for i in 1..adj_width
        color.red += 1
        color.blue += 1
        color.green += 1
        self.contents.fill_rect(x + 5, y + 10, adj_width, adj_height, color)
        x += 1
        adj_width -= 1
      end      
            
    end    
    
  end



Example
Now that you have created your gradient bar function, you need to call it in your script. A good place to call it could be from Window_MenuStatus, which draws the HP/MAX HP and SP/MAX SP for each character in the main menu.

The following example is from Window_MenuStatus in the refresh function. There are several examples in here that show you how to call draw_bar:
CODE
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      @leader = ""
      x = 40
      y = i * 80
      actor = $game_party.actors[i]
      draw_actor_graphic(actor, x-25, y + 60)
      
      draw_actor_name(actor, x, y)
      draw_actor_class(actor, x, y + 15)
  
      draw_bar(actor, x + 140, y, 120, 16, actor.hp, actor.maxhp, text_color(3))      
      draw_actor_hp(actor, x + 115, y)
      
      draw_bar(actor, x + 140, y + 20, 120, 16, actor.sp, actor.maxsp, text_color(4))            
      draw_actor_sp(actor, x + 115, y + 20)  
      
      draw_actor_state(actor, x + 280, y + 20)  
      draw_actor_level(actor, x + 280, y + 40)      
      
    end


Change Gradient
By default, the code I provided makes a gradient that fades to a lighter color. Alternatively, you could have the gradient bar fade into a different color. To make this change, play around with color.red, color.blue, and color.green in the first section of code I provided. (Or just comment one or two of them out.)

This post has been edited by amaranth: Dec 21 2008, 07:27 PM


__________________________
Go to the top of the page
 
+Quote Post
   
cupski
post Jan 15 2010, 12:14 AM
Post #2


Level 1
Group Icon

Group: Member
Posts: 13
Type: Event Designer
RM Skill: Beginner




Thx Amaranth!


__________________________
The XxXX
:P
Go to the top of the page
 
+Quote Post
   
Redd
post Jan 15 2010, 03:09 PM
Post #3


:<
Group Icon

Group: Revolutionary
Posts: 2,314
Type: Developer
RM Skill: Advanced




REALLY BIG BUMP cupski. This topic is more than a year old, and has been long forgotten. I don't think amaranth even comes here anymore.
Good script though. It's true it is really simple.


__________________________
Go to the top of the page
 
+Quote Post
   
Kinerex Shiomi
post Sep 25 2010, 12:48 PM
Post #4


Level 3
Group Icon

Group: Member
Posts: 39
Type: Event Designer
RM Skill: Advanced




I don't understand how to do this....i copied the script into Window_Base, but u lost with me that whole "refresh function" thing. How do i make this work man?


__________________________
[Show/Hide] Read at your own despair

Life=Honor
Honor=God
God=Life

Soldier of John 3:16 XD






~spoiler'd by Hyla

GSORBY FOR LIFE!!!
Go to the top of the page
 
+Quote Post
   
Taiine
post Sep 25 2010, 07:03 PM
Post #5


Level 17
Group Icon

Group: Revolutionary
Posts: 333
Type: Mapper
RM Skill: Advanced




Read it closely. The example shows going into Window_MenuStatus in the refresh function.

Notice in the example it shows the * refresh at the top. Now look at the code, it has

draw_bar(actor, x + 140, y, 120, 16, actor.hp, actor.maxhp, text_color(3))

added above the code to draw the player HP for that window, and there is another for SP. a little lower. That is how you add the bars.


__________________________

an RMXP Game utilizing Blizz-ABS


Concept Projects: DASH! The Masters Game | Finny Adventures (temp title)
My first RMXP Script: Taiine's Solo Player Custom Menu System v0.6 (UPDATED 13th of Nov 10)

Go to the top of the page
 
+Quote Post
   
Kinerex Shiomi
post Sep 25 2010, 09:34 PM
Post #6


Level 3
Group Icon

Group: Member
Posts: 39
Type: Event Designer
RM Skill: Advanced




QUOTE (Taiine @ Sep 25 2010, 08:03 PM) *
Read it closely. The example shows going into Window_MenuStatus in the refresh function.

Notice in the example it shows the * refresh at the top. Now look at the code, it has

draw_bar(actor, x + 140, y, 120, 16, actor.hp, actor.maxhp, text_color(3))

added above the code to draw the player HP for that window, and there is another for SP. a little lower. That is how you add the bars.



ok, i got it in my menu and stuff, but i can't get it into my battle system. I'm using minkoff's battle system, and i would really like to have these HP/SP bars in them. Any advice?

plus i've played around with the colors. Any tips on how to get them like star ocean 2? (The green to yellow to orange hp)

Please don't double post, just edit your old one - Night_Runner


ok, no problem Night_Runner, sorry for the screw up!

It's ok tongue.gif - NR

This post has been edited by Night_Runner: Sep 27 2010, 03:02 AM


__________________________
[Show/Hide] Read at your own despair

Life=Honor
Honor=God
God=Life

Soldier of John 3:16 XD






~spoiler'd by Hyla

GSORBY FOR LIFE!!!
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Sep 27 2010, 05:14 AM
Post #7


Level 50
Group Icon

Group: +Gold Member
Posts: 1,525
Type: Scripter
RM Skill: Undisclosed




@> Kinerex Shiomi: I've given it a go with Minkoff's Battlers, I've edited it (a lot!) and it looks something like a picture I found of star ocean 2

CODE
#==============================================================================
# ** Amaranth's Gradient Bars Script.
#------------------------------------------------------------------------------
# History:
#  Date Created: 22/Dec/2008
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=24983
#  Edited by: Night_Runner
#  Date Edited: 27/Sept/2010
#
# Description:
#  This script has been edited to allow the bar colour to change to a
#  second color, and to have slanted bars.
#==============================================================================



class Window_Base
  #--------------------------------------------------------------------------
  # — Draw a gradient bar
  #     actor : actor assigned to the bar
  #     x          : X coordinate of the upper-left pixel of the bar
  #     y          : Y coordinate of the upper-left pixel of the bar
  #     bar_width  : width of the bar
  #     bar_height : height of the bar
  #     current    : current value to compare (eg. hp, sp, exp)
  #     max        : max value to compare (eg. max hp, max sp, max exp)
  #     sc         : starting color to use (eg. text_color(5))
  #     ec         : ending color of the bar (defaults white)
  #     slanted    : gives the bars a slant (true false)
  #--------------------------------------------------------------------------  
  def draw_bar(actor, x, y, bar_width, bar_height, current, max, sc, ec = Color.new(255, 255, 255), slanted = false)
    # Set the outline
    adj_width = bar_width - 4
    adj_height = bar_height - 4
    # Cannot slant if the width is less than twice the height
    slanted &&= adj_width > 2 * adj_height
    # background of bar
    background_color = Color.new(0, 0, 0, 255)
    if slanted
      rect = Rect.new(x - 1, y + bar_height, bar_width - bar_height, 1)
      (bar_height).times do
        rect.x += 1; rect.y -= 1
        self.contents.fill_rect(rect, background_color)
      end
    else
      self.contents.fill_rect(x, y, bar_width, bar_height, background_color)
    end
    # current bar
    if max != 0
      # Check percent of bar full
      percent = (current * 100) / max
      adj_width = (adj_width * percent) / 100
      # Change in colours per value across
      dr = Float((ec.red - sc.red) / adj_width)
      dg = Float((ec.green - sc.green) / adj_width)
      db = Float((ec.blue - sc.blue) / adj_width)
      # Set the height at the start
      draw_height = slanted ? 0 : adj_height
      # Set the height
      draw_y = slanted ? y + adj_height + 2 : y + 2
      x += slanted ? 5 : 2
      # Across the entire width
      for i in (0...adj_width + (slanted ? 5 : 0))
        # Increment the bar colour
        sc.red += dr
        sc.green += dg
        sc.blue += db
        # If it's not at the end portion
        if adj_width - 5 > adj_height
          # Try to level out the bar (slanted...)
          draw_height = [draw_height + 1, adj_height].min
          draw_y = [draw_y - 1, y + 2].max
        # If it is at the end portion
        else
          # Decrement the height
          draw_height -= slanted ? 1 : 0
        end
        # Draw the bar
        self.contents.fill_rect(x, draw_y, 1, draw_height, sc)
        # Increment the counters
        x += 1
        adj_width -= 1
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_exp  draw_actor_exp  unless $@
  def draw_actor_exp(actor, x, y)
    # Draw Bar
    draw_bar(actor, x + 25, y + 16, 120, 8, actor.sp, actor.maxsp, Color.new(0,128,0), Color.new(0, 128, 0))
    # Run the normal draw_actor_exp
    return nr_gradBars_draw_actor_exp(actor, x, y)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_hp  draw_actor_hp  unless $@
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, 120, 16, actor.hp, actor.maxhp, Color.new(255, 128, 0), Color.new(255, 255, 0), true)
    # Run the normal draw_actor_hp
    return nr_gradBars_draw_actor_hp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_sp  draw_actor_sp  unless $@
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, 120, 16, actor.sp, actor.maxsp, Color.new(0, 0, 255), Color.new(0, 255, 255), true)
    # Run the normal draw_actor_sp
    return nr_gradBars_draw_actor_sp(actor, x, y, width)
  end
end


I would look into SephirothSpawn's slanted bars though, this is more of a simple gradient bar, and those edits I did made it far from simple tongue.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Kinerex Shiomi
post Sep 27 2010, 01:48 PM
Post #8


Level 3
Group Icon

Group: Member
Posts: 39
Type: Event Designer
RM Skill: Advanced




QUOTE (Night_Runner @ Sep 27 2010, 06:14 AM) *
@> Kinerex Shiomi: I've given it a go with Minkoff's Battlers, I've edited it (a lot!) and it looks something like a picture I found of star ocean 2

CODE
#==============================================================================
# ** Amaranth's Gradient Bars Script.
#------------------------------------------------------------------------------
# History:
#  Date Created: 22/Dec/2008
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=24983
#  Edited by: Night_Runner
#  Date Edited: 27/Sept/2010
#
# Description:
#  This script has been edited to allow the bar colour to change to a
#  second color, and to have slanted bars.
#==============================================================================



class Window_Base
  #--------------------------------------------------------------------------
  # �—� Draw a gradient bar
  #     actor : actor assigned to the bar
  #     x          : X coordinate of the upper-left pixel of the bar
  #     y          : Y coordinate of the upper-left pixel of the bar
  #     bar_width  : width of the bar
  #     bar_height : height of the bar
  #     current    : current value to compare (eg. hp, sp, exp)
  #     max        : max value to compare (eg. max hp, max sp, max exp)
  #     sc         : starting color to use (eg. text_color(5))
  #     ec         : ending color of the bar (defaults white)
  #     slanted    : gives the bars a slant (true false)
  #--------------------------------------------------------------------------  
  def draw_bar(actor, x, y, bar_width, bar_height, current, max, sc, ec = Color.new(255, 255, 255), slanted = false)
    # Set the outline
    adj_width = bar_width - 4
    adj_height = bar_height - 4
    # Cannot slant if the width is less than twice the height
    slanted &&= adj_width > 2 * adj_height
    # background of bar
    background_color = Color.new(0, 0, 0, 255)
    if slanted
      rect = Rect.new(x - 1, y + bar_height, bar_width - bar_height, 1)
      (bar_height).times do
        rect.x += 1; rect.y -= 1
        self.contents.fill_rect(rect, background_color)
      end
    else
      self.contents.fill_rect(x, y, bar_width, bar_height, background_color)
    end
    # current bar
    if max != 0
      # Check percent of bar full
      percent = (current * 100) / max
      adj_width = (adj_width * percent) / 100
      # Change in colours per value across
      dr = Float((ec.red - sc.red) / adj_width)
      dg = Float((ec.green - sc.green) / adj_width)
      db = Float((ec.blue - sc.blue) / adj_width)
      # Set the height at the start
      draw_height = slanted ? 0 : adj_height
      # Set the height
      draw_y = slanted ? y + adj_height + 2 : y + 2
      x += slanted ? 5 : 2
      # Across the entire width
      for i in (0...adj_width + (slanted ? 5 : 0))
        # Increment the bar colour
        sc.red += dr
        sc.green += dg
        sc.blue += db
        # If it's not at the end portion
        if adj_width - 5 > adj_height
          # Try to level out the bar (slanted...)
          draw_height = [draw_height + 1, adj_height].min
          draw_y = [draw_y - 1, y + 2].max
        # If it is at the end portion
        else
          # Decrement the height
          draw_height -= slanted ? 1 : 0
        end
        # Draw the bar
        self.contents.fill_rect(x, draw_y, 1, draw_height, sc)
        # Increment the counters
        x += 1
        adj_width -= 1
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_exp  draw_actor_exp  unless $@
  def draw_actor_exp(actor, x, y)
    # Draw Bar
    draw_bar(actor, x + 25, y + 16, 120, 8, actor.sp, actor.maxsp, Color.new(0,128,0), Color.new(0, 128, 0))
    # Run the normal draw_actor_exp
    return nr_gradBars_draw_actor_exp(actor, x, y)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_hp  draw_actor_hp  unless $@
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, 120, 16, actor.hp, actor.maxhp, Color.new(255, 128, 0), Color.new(255, 255, 0), true)
    # Run the normal draw_actor_hp
    return nr_gradBars_draw_actor_hp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_sp  draw_actor_sp  unless $@
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, 120, 16, actor.sp, actor.maxsp, Color.new(0, 0, 255), Color.new(0, 255, 255), true)
    # Run the normal draw_actor_sp
    return nr_gradBars_draw_actor_sp(actor, x, y, width)
  end
end


I would look into SephirothSpawn's slanted bars though, this is more of a simple gradient bar, and those edits I did made it far from simple tongue.gif



dude, thats frickin genius! I love it! But in battle my fourth persons HP and SP are cut off. any way to fix it? Thanks a lot man!


__________________________
[Show/Hide] Read at your own despair

Life=Honor
Honor=God
God=Life

Soldier of John 3:16 XD






~spoiler'd by Hyla

GSORBY FOR LIFE!!!
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Sep 28 2010, 04:55 AM
Post #9


Level 50
Group Icon

Group: +Gold Member
Posts: 1,525
Type: Scripter
RM Skill: Undisclosed




Not only can I do that for you, but I can also fix a bug where the EXP bars show the SP instead of EXP *yay!*

Code
CODE
#==============================================================================
# ** Amaranth's Gradient Bars Script.
#------------------------------------------------------------------------------
# History:
#  Date Created: 22/Dec/2008
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=24983
#  Edited by: Night_Runner
#  Date Edited: 27/Sept/2010
#
# Description:
#  This script has been edited to allow the bar colour to change to a
#  second color, and to have slanted bars.
#==============================================================================



class Window_Base
  #--------------------------------------------------------------------------
  # �—� Draw a gradient bar
  #     actor : actor assigned to the bar
  #     x          : X coordinate of the upper-left pixel of the bar
  #     y          : Y coordinate of the upper-left pixel of the bar
  #     bar_width  : width of the bar
  #     bar_height : height of the bar
  #     current    : current value to compare (eg. hp, sp, exp)
  #     max        : max value to compare (eg. max hp, max sp, max exp)
  #     sc         : starting color to use (eg. text_color(5))
  #     ec         : ending color of the bar (defaults white)
  #     slanted    : gives the bars a slant (true false)
  #--------------------------------------------------------------------------  
  def draw_bar(actor, x, y, bar_width, bar_height, current, max, sc, ec = Color.new(255, 255, 255), slanted = false)
    # Set the outline
    adj_width = bar_width - 4
    adj_height = bar_height - 4
    # Cannot slant if the width is less than twice the height
    slanted &&= adj_width > 2 * adj_height
    # background of bar
    background_color = Color.new(0, 0, 0, 255)
    if slanted
      rect = Rect.new(x - 1, y + bar_height, bar_width - bar_height, 1)
      (bar_height).times do
        rect.x += 1; rect.y -= 1
        self.contents.fill_rect(rect, background_color)
      end
    else
      self.contents.fill_rect(x, y, bar_width, bar_height, background_color)
    end
    # current bar
    if max != 0
      # Check percent of bar full
      percent = (current * 100) / max
      adj_width = (adj_width * percent) / 100
      # Change in colours per value across
      dr = Float((ec.red - sc.red) / adj_width)
      dg = Float((ec.green - sc.green) / adj_width)
      db = Float((ec.blue - sc.blue) / adj_width)
      # Set the height at the start
      draw_height = slanted ? 0 : adj_height
      # Set the height
      draw_y = slanted ? y + adj_height + 2 : y + 2
      x += slanted ? 5 : 2
      # Across the entire width
      for i in (0...adj_width + (slanted ? 5 : 0))
        # Increment the bar colour
        sc.red += dr
        sc.green += dg
        sc.blue += db
        # If it's not at the end portion
        if adj_width - 5 > adj_height
          # Try to level out the bar (slanted...)
          draw_height = [draw_height + 1, adj_height].min
          draw_y = [draw_y - 1, y + 2].max
        # If it is at the end portion
        else
          # Decrement the height
          draw_height -= slanted ? 1 : 0
        end
        # Draw the bar
        self.contents.fill_rect(x, draw_y, 1, draw_height, sc)
        # Increment the counters
        x += 1
        adj_width -= 1
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_exp  draw_actor_exp  unless $@
  def draw_actor_exp(actor, x, y)
    next_exp = actor.next_exp_s
    next_exp = actor.exp if next_exp == "-------"
    # Draw Bar
    draw_bar(actor, x + 25, y + 16, 120, 8, actor.exp, next_exp.to_i, Color.new(0,128,0), Color.new(0, 128, 0))
    # Run the normal draw_actor_exp
    return nr_gradBars_draw_actor_exp(actor, x, y)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_hp  draw_actor_hp  unless $@
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, width - 16, 16, actor.hp, actor.maxhp, Color.new(255, 128, 0), Color.new(255, 255, 0), true)
    # Run the normal draw_actor_hp
    return nr_gradBars_draw_actor_hp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_sp  draw_actor_sp  unless $@
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, width - 16, 16, actor.sp, actor.maxsp, Color.new(0, 0, 255), Color.new(0, 255, 255), true)
    # Run the normal draw_actor_sp
    return nr_gradBars_draw_actor_sp(actor, x, y, width)
  end
end


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Kinerex Shiomi
post Sep 28 2010, 05:16 PM
Post #10


Level 3
Group Icon

Group: Member
Posts: 39
Type: Event Designer
RM Skill: Advanced




QUOTE (Night_Runner @ Sep 28 2010, 05:55 AM) *
Not only can I do that for you, but I can also fix a bug where the EXP bars show the SP instead of EXP *yay!*

Code
CODE
#==============================================================================
# ** Amaranth's Gradient Bars Script.
#------------------------------------------------------------------------------
# History:
#  Date Created: 22/Dec/2008
#   @> http://www.rpgrevolution.com/forums/index.php?showtopic=24983
#  Edited by: Night_Runner
#  Date Edited: 27/Sept/2010
#
# Description:
#  This script has been edited to allow the bar colour to change to a
#  second color, and to have slanted bars.
#==============================================================================



class Window_Base
  #--------------------------------------------------------------------------
  # �—� Draw a gradient bar
  #     actor : actor assigned to the bar
  #     x          : X coordinate of the upper-left pixel of the bar
  #     y          : Y coordinate of the upper-left pixel of the bar
  #     bar_width  : width of the bar
  #     bar_height : height of the bar
  #     current    : current value to compare (eg. hp, sp, exp)
  #     max        : max value to compare (eg. max hp, max sp, max exp)
  #     sc         : starting color to use (eg. text_color(5))
  #     ec         : ending color of the bar (defaults white)
  #     slanted    : gives the bars a slant (true false)
  #--------------------------------------------------------------------------  
  def draw_bar(actor, x, y, bar_width, bar_height, current, max, sc, ec = Color.new(255, 255, 255), slanted = false)
    # Set the outline
    adj_width = bar_width - 4
    adj_height = bar_height - 4
    # Cannot slant if the width is less than twice the height
    slanted &&= adj_width > 2 * adj_height
    # background of bar
    background_color = Color.new(0, 0, 0, 255)
    if slanted
      rect = Rect.new(x - 1, y + bar_height, bar_width - bar_height, 1)
      (bar_height).times do
        rect.x += 1; rect.y -= 1
        self.contents.fill_rect(rect, background_color)
      end
    else
      self.contents.fill_rect(x, y, bar_width, bar_height, background_color)
    end
    # current bar
    if max != 0
      # Check percent of bar full
      percent = (current * 100) / max
      adj_width = (adj_width * percent) / 100
      # Change in colours per value across
      dr = Float((ec.red - sc.red) / adj_width)
      dg = Float((ec.green - sc.green) / adj_width)
      db = Float((ec.blue - sc.blue) / adj_width)
      # Set the height at the start
      draw_height = slanted ? 0 : adj_height
      # Set the height
      draw_y = slanted ? y + adj_height + 2 : y + 2
      x += slanted ? 5 : 2
      # Across the entire width
      for i in (0...adj_width + (slanted ? 5 : 0))
        # Increment the bar colour
        sc.red += dr
        sc.green += dg
        sc.blue += db
        # If it's not at the end portion
        if adj_width - 5 > adj_height
          # Try to level out the bar (slanted...)
          draw_height = [draw_height + 1, adj_height].min
          draw_y = [draw_y - 1, y + 2].max
        # If it is at the end portion
        else
          # Decrement the height
          draw_height -= slanted ? 1 : 0
        end
        # Draw the bar
        self.contents.fill_rect(x, draw_y, 1, draw_height, sc)
        # Increment the counters
        x += 1
        adj_width -= 1
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw EXP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_exp  draw_actor_exp  unless $@
  def draw_actor_exp(actor, x, y)
    next_exp = actor.next_exp_s
    next_exp = actor.exp if next_exp == "-------"
    # Draw Bar
    draw_bar(actor, x + 25, y + 16, 120, 8, actor.exp, next_exp.to_i, Color.new(0,128,0), Color.new(0, 128, 0))
    # Run the normal draw_actor_exp
    return nr_gradBars_draw_actor_exp(actor, x, y)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_hp  draw_actor_hp  unless $@
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, width - 16, 16, actor.hp, actor.maxhp, Color.new(255, 128, 0), Color.new(255, 255, 0), true)
    # Run the normal draw_actor_hp
    return nr_gradBars_draw_actor_hp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias  nr_gradBars_draw_actor_sp  draw_actor_sp  unless $@
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw bar
    draw_bar(actor, x + 25, y + 8, width - 16, 16, actor.sp, actor.maxsp, Color.new(0, 0, 255), Color.new(0, 255, 255), true)
    # Run the normal draw_actor_sp
    return nr_gradBars_draw_actor_sp(actor, x, y, width)
  end
end


I could throw you a parade right now lol but in order for a more simplistic script that i myself could edit (or thought i could lol) i used spawns slanted bar. I was under the impression that when u get hit your hp would slide down, not just break off (Im speaking of the gradient bar script) all i can't seem to do is make the spawn bars shorter for battle, and i cant make the EXP bar shorter in the menu (it overlaps the SP bar slightly) so idk what to do lol i tried editing myself, i just screwed it up more lol any ideas?


__________________________
[Show/Hide] Read at your own despair

Life=Honor
Honor=God
God=Life

Soldier of John 3:16 XD






~spoiler'd by Hyla

GSORBY FOR LIFE!!!
Go to the top of the page
 
+Quote Post
   
Carmen
post Oct 8 2010, 02:10 AM
Post #11



Group Icon

Group: Member
Posts: 2
Type: Developer
RM Skill: Skilled




Soooooooooooooooooper script
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th May 2013 - 04:11 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker