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)
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
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.
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?
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 - NR
This post has been edited by Night_Runner: Sep 27 2010, 03:02 AM
#============================================================================== # ** 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
__________________________
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.
#============================================================================== # ** 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
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!
Group: +Gold Member
Posts: 1,522
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.
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?