Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
Spence607

Need help making HP and SP bars in battle.

Recommended Posts

I want to make a script to display HP and SP bars in battle. That actually decrease when HP or SP is lost and increase when HP or SP is gained.

 

Here's what I basically want it to look like:

 

Preview.jpg

 

I have no clue where to start, any help would be much appreciated.

 

Note: This is not a script, the bars were added with GIMP.

 

Thanks,

 

Spence

Share this post


Link to post
Share on other sites

Try this code snippet, and use the method in the draw_actor_hp/sp methods:

 

class Window_Base
 def draw_bar(x, y, min, max, width, height, bar_color = Color.new(120, 120, 50, 255))
  self.contents.fill_rect(x, y, width, height, Color.new(50, 50, 50, 255))
  for i in 1..( (min.to_f / max.to_f) * width -1)
	r = bar_color.red * (width - i) / width + end_color.red * i / width
	g = bar_color.green * (width - i) / width + end_color.green * i / width
	b = bar_color.blue * (width - i) / width + end_color.blue * i / width
	a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
	self.contents.fill_rect(x + 1 + i, y + 1, 1, height - 2, Color.new(r, g, b, a))
  end
 end
end

To use it, call it using: draw_bar(x, y, min, max, width, height, color)

Now, x and y are the placements, min is the current number, max is the maximum number, width is the width of the ba, and height is the height of the bar. Color is self explainatory, but to set it, use Color.new(r, g, b, a)

 

So, for hitpoints, use: draw_bar(x, y, actor.hp, actor.maxhp, 120, 10, Color.new(200, 20, 0, 255))

Not exact, but an example, no less.

 

To use this method, use draw_bar(

Share this post


Link to post
Share on other sites

Sorry man, I couldn't understand it. Ended up using Cogwheel's HP/SP/EXP Gauge Script. Just edited it a bit.

 

Output:

 

Game.jpg

 

Thanks for the help anyways man. Although I do need help centering some text. I'd like to have the numbers in the middle of the bar, both in the menu and battles.

Share this post


Link to post
Share on other sites

#--------------------------------------------------------------------------

# * 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 = normal_color

self.contents.draw_text(x, y, 34, 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

self.contents.font.color = actor.hp == 0 ? knockout_color :

actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color

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

 

What x value exactly?

 

Never mind man, I figured it out. Thanks for all the help.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...