New account registration is temporarily disabled.

HP/MP GAUGES IN BATTLE AND MENU IN RMXP?

Posts

Pages: 1
Okay, so I tried monkeying around a bit in the RMXP default script but couldn't get a window, viewbox, or ANYTHING to use as a guage :/
Is it possible for me to just use an imported bitmap of blue and red rectangles and have them fill proportionately to the ratio of currenthp/maxhp, currentmp/maxmp?

If so... How would I go about adding those to the menu and batlle menu?

any help would be appreciated! :)
You'll probably want to edit the script that draws the menu/battle window. There's a script function for bitmaps that draws a gradient bar that you can use. Unfortunately I don't remember what it's called or where'd you put it but I can take a look when I get home and take a peek at the XP editor.
Sorry for being such a bitch about this, I kinda forgot about looking this up.

I still haven't, but I can at least post something relevant!

If you check the RMXP help file and look under the RGSS/Ruby stuff and find the Bitmap class (you could probably just search for "Bitmap class"), it will give a list of functions. There will be something similar to "draw_bar" where the parameters are something like "x, y, width, height, color1, color2, ". This will draw the gradient bar (and the last argument is if you want the gradient horizontal or vertical, I'll assume you want it horizontal for now).

Now in the script editor, find the Window_Base class. There should be a function called "draw_hp". You can add the 'draw_bar' call there so every time the HP is drawn it will also draw a bar. If you add it before the draw_text, the text appears on top of the bar (and the other way around if you draw the bar after draw_text).

Two bars will have to be drawn: The current HP gauge and the black part to represent missing HP. The best way to do this is to draw a full gauge first and then draw the missing black bar on top of it. Here's some pseudo-code (it won't work, I don't remember enough about the draw_hp function) to give an idea of how this will be done:

def draw_hp(hp, max_hp)
# Define colors for the gauges and the empty part of the gauge
health_gauge_color_1 = Color.new(255, 255, 64)
health_gauge_color_2 = Color.new(128, 255, 64)
black_color = Color.new(0, 0, 0)
# Define the dimensions of the gauge in pixels
width = 120
height = 20
# Draw the full gauge first
draw_bar(x, y, width, height, health_gauge_color_1, health_gauge_color_2)
# If HP isn't maxed out, we'll have to draw the empty part of the gauge
if hp < max_hp
# Calculate how long the empty part of thegauge is (it will be at least one pixel wide and it won't be as long as the health gauge)
empty_width = [[(width * (1 - hp / max_hp)).to_i, 1].max, width - 1].min
# Now draw the empty part of the bar using this width
draw_bar(width - empty_width + x, y, empty_width, height, black_color, black_color)
end

# Original draw_hp code would go here
end

Repeat for draw_mp.

(this is from memory, I'll have to update this after work to make sure all my references are correct)
Any chance you can upload a script like this that displays gradient bars in battle? I have one in the menu, but I can't get this script or the script I'm using to work in the battles.
Like, a gradient bar whenever a HP/MaxHP is shown? Where do you want the bars to show up and when?
On the battle screen, where the number of current HP is usually shown. If there is a way to get the bars to show up there that would be awesome!
Sorry I've been busy and lazy

Here's a quick and dirty health/SP bars wherever Actor HP/SP is drawn! Like battles or the menu. Insert this into a new script above others (since I had to overwrite a function because Fuck RMXP)

Let me know if there's any issues


# Changes to the bitmap class to add a function which can draw gradient bars
class Bitmap

# Draw a rectangle with a gradient color shift from color1 to color2
# Goes from left to right, or top to bottom if vertical is set
def draw_gradient_rect(x, y, width, height, color1, color2, vertical=false)
# Determine what will limit the draw
limit = vertical ? height: width
for i in 0..limit
# Calculate the color1 multiplier for its color
mul = (limit - i).to_f / limit
# Calculate the new color for this part of the gradient
color = Color.new(
mul * (color1.red - color2.red) + color2.red,
mul * (color1.green - color2.green) + color2.green,
mul * (color1.blue - color2.blue) + color2.blue
)
# Draw the portion of the rectangle with the new color
if vertical
self.fill_rect(x, y+i, width,1, color)
else
self.fill_rect(x+i, y, 1, height, color)
end
end
end

end

#---------------------
# Changes to the Window_Base class where Draw_Actor_HP/SP reside

class Window_Base < Window
# --------
# Change the Draw_Actor_HP function so a gradient bar appears to show how
# much HP the actor has left
alias draw_actor_hp_healthgauges draw_actor_hp unless $@
def draw_actor_hp(actor, x, y, width = 144)
# First create the health gauge!

# Define colors for the gauges and the empty part of the gauge
# Color1 is the left of the gauge, Color2 is the right
health_gauge_color_1 = Color.new(128, 64, 32)
health_gauge_color_2 = Color.new(255, 128, 64)
black_color = Color.new(0, 0, 0)

# Define the dimensions of the gauge in pixels
height = 12
x_offset = 0
y_offset = 20

# If the actor has HP left...
if actor.hp > 0

# Draw the full gauge first
self.contents.draw_gradient_rect(
x + x_offset,
y + y_offset,
width,
height,
health_gauge_color_1,
health_gauge_color_2
)
# If HP isn't maxed out, we'll have to draw the empty part of the gauge
if actor.hp < actor.maxhp
# Calculate how long the empty part of thegauge is (it will be at least one pixel wide and it won't be as long as the health gauge)
empty_width = [[(width * (1 - actor.hp.to_f / actor.maxhp)).to_i, 1].max, width - 1].min
# Now draw the empty part of the bar using this width
self.contents.fill_rect(
width - empty_width + x + x_offset + 1,
y+y_offset,
empty_width,
height,
black_color
)
end

else
# The actor has no HP, just show a big black bar
self.contents.fill_rect(x+x_offset, y+y_offset, width, height, black_color)
end

# Now draw the HP value by calling the original method
draw_actor_hp_healthgauges(actor, x, y, width)
end

# ------------
# Change the Draw_Actor_SP function so it draws a gradient bar to show the
# amount of SP the actor has left
alias draw_actor_sp_healthgauges draw_actor_sp unless $@
def draw_actor_sp(actor, x, y, width = 144)
# First create the SP gauge!

# Define colors for the gauges and the empty part of the gauge
# Color1 is the left of the gauge, Color2 is the right
sp_gauge_color_1 = Color.new(32, 32, 128)
sp_gauge_color_2 = Color.new(64, 64, 255)
black_color = Color.new(0, 0, 0)

# Define the dimensions of the gauge in pixels
height = 12
x_offset = 0
y_offset = 20

# If the actor has SP left...
if actor.sp > 0

# Draw the full gauge first
self.contents.draw_gradient_rect(
x + x_offset,
y + y_offset,
width,
height,
sp_gauge_color_1,
sp_gauge_color_2
)
# If SP isn't maxed out, we'll have to draw the empty part of the gauge
if actor.sp < actor.maxsp
# Calculate how long the empty part of thegauge is (it will be at least one pixel wide and it won't be as long as the health gauge)
empty_width = [[(width * (1 - actor.sp.to_f / actor.maxsp)).to_i, 1].max, width - 1].min
# Now draw the empty part of the bar using this width
self.contents.fill_rect(
width - empty_width + x + x_offset + 1,
y+y_offset,
empty_width,
height,
black_color
)
end

else
# Just draw a big black empty bar
self.contents.fill_rect(x+x_offset, y+y_offset, width, height, black_color)
end

# Now draw the SP value by calling the original method
draw_actor_sp_healthgauges(actor, x, y, width)
end
end

#-------------------
# Change the RPG::Sprite class so it doesn't force it's viewport
# Overwrite required since you can't change the viewport of a created image
module RPG
class Sprite < ::Sprite
def damage(value, critical)
dispose_damage
if value.is_a?(Numeric)
damage_string = value.abs.to_s
else
damage_string = value.to_s
end
bitmap = Bitmap.new(160, 48)
bitmap.font.name = "Arial Black"
bitmap.font.size = 32
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
if value.is_a?(Numeric) and value < 0
bitmap.font.color.set(176, 255, 144)
else
bitmap.font.color.set(255, 255, 255)
end
bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
if critical
bitmap.font.size = 20
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
end
@_damage_sprite = ::Sprite.new#(self.viewport)
@_damage_sprite.bitmap = bitmap
@_damage_sprite.ox = 80
@_damage_sprite.oy = 20
@_damage_sprite.x = self.x
@_damage_sprite.y = self.y - self.oy / 2
@_damage_sprite.z = 3000
@_damage_duration = 40
end
end
end
Oh, I'd suggest removing the menu-HP-bar script (just cut-paste ti below the 'Main' script, ti won't execute but you can easily move it back above Main and have it work), this script will do that for now and they'll clash otherwise.
Cool TY!
New question:( sorry to bug you, you've been a great help GreatRedSpirit!
Is there any way to have the SP bars not show up in the menu if a character doesn't use SP?
Puddor
if squallbutts was a misao category i'd win every damn year
5702
I think that'd be a rather different code since first you'd have to process the fact the the actor in question question doesn't have an SP display. IIRC stat gauges are drawn per actor so you'd have to get a code to separate those specific actors from the rest and draw their display...

Since I'm not a coder I wouldn't know how this would exactly work but I think it'd be fairly complicated, form what knowledge I have of RGSS.

Just for the record I'm a n00b at RGSS but I do have a very basic understanding >3<
Slap a "return if actor.maxsp == 0" in draw_actor_sp, make sure it's the first thing that happens. (assuming a character that doesn't use SP has zero max sp)
Ooo, you're smart in the ways of scripting (Unlike me) Thank you so much!
Edit: If I insert that, then as soon as it comes to a character who doesn't use sp, the rest of the characters don't appear
example: the second character down (in the menu) doesn't use sp. His sp won't appear, but neither will the third or fourth characters.
I punched this into RMXP and it works fine, download here. Copy+Paste the script there into your game and see if it works. If it is still acting up there's a script incompatibility with your game. PM it to me and I can see if I can fix it.
Cool script! I was wanting to have something like this in my game, so I'd like to use it in my project if that's okay with you :)

I'd like to also have a guage for EXP. I tried copy/pasting the chunk of code and replacing all the 'hp' to 'exp', but that doesn't seem to work because I can't seem to figure out what the right "function call" (or whatever it's called) for exp to next lvl. I tried "exp_next" and "exp_rest_next", the two I found in other parts of the code. But those all just gave me errors when I opened the menu in-game.

I'm sure it's something stupid I'm leaving out, or miss-typing, or something. It's been WAAY too long since I've done any real programing, and my skills are practically nil by now.
Yeah, thanks GreatRedSpirit! I figured out what the problem was though, but it now works fine :)
Nines, I agree with you. I've been looking for a way to get exp to show, but it will just make the menu look messy with all those gradient bars(unless you have a great cms!)
Pages: 1