Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

pictoral HP/SP indicators? Do-able?

Mea

Member

Basically, what I want to do is have some way to indicate HP or SP without using the traditional gradient bar.

For the record, these screen shots were made while running Trickster's CTB Battle System. The blue bar at the bottom is the time indicator.

http://www.stkp.com/rpgmxp/interface/normal.png[/img]

http://www.stkp.com/rpgmxp/interface/mockup.png[/img]
(minus the watermark of course)

In general terms, each indicator, HP or SP, is made of two images - a "full" image and an "empty" image as background - and some form of masking on the "full" image, sort of what's done with some grad bar scripts as they are now, I think. (warning: This is being spoken by a scripting illiterate)

For example, the HP indicator is made up of:
http://www.stkp.com/rpgmxp/interface/vial_red.png[/img] and http://www.stkp.com/rpgmxp/interface/vial_empty.png[/img]

When the character is at full HP/SP, the topmost image that indicates "full" is fully visible. As the character receives damage, the "full" image is masked off to indicate the percentage of HP/SP left. Thus is a character had 100 HP and took 25 damage, the top 25% of the "full" image would be masked off, revealing the "empty" image underneath. The character's current HP/SP appear beneath their respective indicators. I considered putting both the current and the max, but honestly I don't think there's room, but I could be wrong.

The final script should "hopefully" have someplace near the top to define the source (preferably using the "gradient" directory as the target directory), height, and width of the graphics. It'll allow for more versatility in the long run. The ability to set the X & Y placement would be nice too, but not required - there are ways to fake it with the graphic itself to some degree.

Theoretically, this should be simple, but then again, what do I know. :blushanim02:

The three vial graphics I whipped together for testing purposes are here:
http://www.stkp.com/rpgmxp/interface/vial_blue.png
http://www.stkp.com/rpgmxp/interface/vial_red.png
http://www.stkp.com/rpgmxp/interface/vial_empty.png

NOTE: I imagine this would modification would be for the Battle display only. Honestly, I'm not sure how it would work in the regular menu system, if it'd be too unwieldy or what.

Anyway, thanks in advance anyone who takes up the challenge.
 
Great idea!!
Try this
Code:
class Window_BattleStatus
  #-------------------------------------
  EMPTY_VIAL = "vial_empty"
  HP_VIAL    = "vial_red"
  SP_VIAL    = "vial_blue"
  def draw_vial(picture, percent, x, y)
    return if percent == 0
    src_bitmap = RPG::Cache.picture(picture)
    wid, hei = src_bitmap.width, percent * src_bitmap.height / 100
    dif = src_bitmap.height - hei
    src_rect = Rect.new(0, dif, wid, hei)
    dest_rect = Rect.new(x, y + dif, wid, hei)
    self.contents.stretch_blt(dest_rect, src_bitmap, src_rect)
    src_bitmap.dispose
  end
  def draw_actor_hpvial(actor, x, y)
    if actor.maxhp > 0
      draw_vial(EMPTY_VIAL, 100, x, y)
      percent = 100 * actor.hp / actor.maxhp
      draw_vial(HP_VIAL, percent, x, y)
      self.contents.draw_text(x, y + 40, 60, 32, actor.hp.to_s)
    end
  end
  def draw_actor_spvial(actor, x, y)
    if actor.maxsp > 0
      draw_vial(EMPTY_VIAL, 100, x, y)
      percent = 100 * actor.sp / actor.maxsp
      draw_vial(SP_VIAL, percent, x, y)
      self.contents.draw_text(x, y + 40, 60, 32, actor.sp.to_s)
    end
  end
  #-------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      actor_x = i * 160 + 4
      draw_actor_name(actor, actor_x, 0)
      #-------------------------------------
      # This is the part i've edited
      draw_actor_hpvial(actor, actor_x, 24)
      draw_actor_spvial(actor, actor_x + 80, 24)
      #-------------------------------------
      if @level_up_flags[i]
        self.contents.font.color = normal_color
        self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
      else
        draw_actor_state(actor, actor_x, 96)
      end
    end
  end
end
Add it before main and after the default scripts. If you got any script that changes Window_BattleStatus (i'm sure for looking at your screenie's ATB bar) replace the draw_actor_hp and draw_actor_sp methods for the following and remove the refresh method from my script.
Code:
      draw_actor_hpvial(actor, actor_x, 24)
      draw_actor_spvial(actor, actor_x + 80, 24)
 

Mea

Member

Tibuda that's great! I made on minor modification to the script to allow for vastly different meters for HP and SP though, shown here:

Code:
# Tibuda's Pictoral Indicators
class Window_BattleStatus
  #-------------------------------------
  EMPTY_HP_VIAL = "vial_empty"
  EMPTY_SP_VIAL = "vial_empty"
  HP_VIAL    = "vial_red"
  SP_VIAL    = "vial_blue"
  def draw_vial(picture, percent, x, y)
    return if percent == 0
    src_bitmap = RPG::Cache.picture(picture)
    wid, hei = src_bitmap.width, percent * src_bitmap.height / 100
    dif = src_bitmap.height - hei
    src_rect = Rect.new(0, dif, wid, hei)
    dest_rect = Rect.new(x, y + dif, wid, hei)
    self.contents.stretch_blt(dest_rect, src_bitmap, src_rect)
    src_bitmap.dispose
  end
  def draw_actor_hpvial(actor, x, y)
    if actor.maxhp > 0
      draw_vial(EMPTY_HP_VIAL, 100, x, y)
      percent = 100 * actor.hp / actor.maxhp
      draw_vial(HP_VIAL, percent, x, y)
      self.contents.draw_text(x, y + 40, 60, 32, actor.hp.to_s)
    end
  end
  def draw_actor_spvial(actor, x, y)
    if actor.maxsp > 0
      draw_vial(EMPTY_SP_VIAL, 100, x, y)
      percent = 100 * actor.sp / actor.maxsp
      draw_vial(SP_VIAL, percent, x, y)
      self.contents.draw_text(x, y + 40, 60, 32, actor.sp.to_s)
    end
  end
  #-------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      actor_x = i * 160 + 4
      draw_actor_name(actor, actor_x, 0)
      #-------------------------------------
      # This is the part i've edited
      draw_actor_hpvial(actor, actor_x, 24)
      draw_actor_spvial(actor, actor_x + 80, 24)
      #-------------------------------------
      if @level_up_flags[i]
        self.contents.font.color = normal_color
        self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
      else
        draw_actor_state(actor, actor_x, 96)
      end
    end
  end
end

The downside is it's completely overwriting the battle display in Trickster's CTB Battle System so I can't see the Active time bar. Haven't been able to work that out yet, but considering that the BS is kinda buggy so far so I'm not sure I'm going to stick with it so modifying this to fit with that BS might be a bit premature.

Thank you so muc though. This is so cool!
 
very well,
that's because i've writed the script for the DBS. just downloaded CTB demo now. if you still plan to use it, you can add the following code.
Code:
draw_actor_at(actor, actor_x, 96, 120)
after line
Code:
draw_actor_spvial(actor, actor_x + 80, 24)
and before line
Code:
if @level_up_flags[i]
 
but considering that the BS is kinda buggy so far
But of course it's buggy its only version 1.0.1, of course some of the bugs that are present going to slip through the cracks, as you can already see. though I have throughly ran through fixing bugs. would you rather have a script with few to no bugs yet no scripter to support it or a script with few to many (and there were like only 3 bugs with my script) but a scripter who actively supports it

As for the bugs I have eliminated two of them (the ones you and Raven informed me about) there is a bug with the Escape option not taking the correct amount from the Time Bar as I'm working on that right now

As for this request if tibuda doesn't mind I'll rescript his work to "fit" a bit nicer with this system, that is if you choose to still use it

EDIT and elimated the final bug
 

Mea

Member

Sorry Trickster, I didn't me any offense. I'm still kind of feelign my way around how I want my battlesystem to work and I wasn't sure of you were getting back to this one for a while. Still getting a feel for this place.

Gonna grab the new version now, but probably won't get a chance to work on it much until tomorrow night.
 
Ok, Make sure you get the file from the new version of the DLM not the older version I just noticed that the download link linked to an older version (This just isn't my week for bugs)

Okay Give me a few days at least shouldn't take very long
 

Mea

Member

Well, if Tibuda has no problem with it, I sure don't. I figure a script like this could be useful and versatile to a lot of folks who want something other than the same old HP bars.
 
All I can do for now is rewrite what tibuda wrote (If you want it animated, I'll have to create a Vertical Gradient Bar Class, which will have to wait until I finish MACL 2.0)

the original
Code:
=begin
#==============================================================================
# ● Tibuda's Pictoral Indicators 
#==============================================================================
=end
#--------------------------------------------------------------------------
# ● Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Pictoral Indicators', 'Tibuda', 1.0, '3/13/07')
#--------------------------------------------------------------------------
# ● Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])
#--------------------------------------------------------------------------
# ● Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Pictoral Indicators')
  
class Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  EMPTY_HP_VIAL = 'vial_empty'
  EMPTY_SP_VIAL = 'vial_empty'
  HP_VIAL    = 'vial_red'
  SP_VIAL    = 'vial_blue'
  #--------------------------------------------------------------------------
  # * Draw Vial
  #--------------------------------------------------------------------------
  def draw_vial(empty, full, percent, x, y)
    # Get Empty Bitmap
    empty_bitmap = RPG::Cache.picture(empty)
    # Create Destination Rect
    dest_rect = Rect.new(x, y, empty_bitmap.width, empty_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, empty_bitmap, empty_bitmap.rect)
    # Get full Bitmap
    full_bitmap = RPG::Cache.picture(full)
    # Get Width and Height
    width, height = full_bitmap.width, percent * full_bitmap.height / 100
    # Get Difference in height
    diff = full_bitmap.height - height
    # Create Source Rect
    src_rect = Rect.new(0, diff, full_bitmap.width, full_bitmap.height)
    # Create Destination Rect
    dest_rect = Rect.new(x, y + diff, full_bitmap.width, full_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, full_bitmap, src_rect)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw Vial
    draw_vial(EMPTY_HP_VIAL, HP_VIAL, actor.hp / actor.maxhp, x, y)
    # Draw Hp Text
    self.contents.draw_text(x, y + 40, width, 32, actor.hp.to_s)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # If Actor Maxsp is greater than 0
    if actor.maxsp > 0
      # Draw Vial
      draw_vial(EMPTY_SP_VIAL, SP_VIAL, actor.sp / actor.maxsp, x, y)
      # Draw Sp Text
      self.contents.draw_text(x, y + 40, width, 32, actor.sp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Clear Contents
    self.contents.clear
    # Run Through Each Actor With index
    $game_party.actors.each_with_index do |actor, index|
      # Get X coordinate
      actor_x = index * 160 + 4
      # Draws Name
      draw_actor_name(actor, actor_x, 0)
      # Draws Hp
      draw_actor_hp(actor, actor_x, 24)
      # Draws Sp
      draw_actor_sp(actor, actor_x + 80, 24)
      # If Level Up Flags
      if @level_up_flags[index]
        # Normal Color
        self.contents.font.color = normal_color
        # Draw Level Up
        self.contents.draw_text(actor_x, 96, 120, 32, 'LEVEL UP!')
      else
        # Draws State
        draw_actor_state(actor, actor_x, 96)
      end
    end
  end
end
#--------------------------------------------------------------------------
#  End SDK Enabled Check
#--------------------------------------------------------------------------
end

For MY CTB System
Code:
=begin
#==============================================================================
# ● Tibuda's Pictoral Indicators 
#==============================================================================
=end
#--------------------------------------------------------------------------
# ● Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Pictoral Indicators', 'Tibuda', 1.0, '3/13/07')
#--------------------------------------------------------------------------
# ● Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])
#--------------------------------------------------------------------------
# ● Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Pictoral Indicators')
  
class Window_BattleStatus
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  EMPTY_HP_VIAL = 'vial_empty'
  EMPTY_SP_VIAL = 'vial_empty'
  HP_VIAL    = 'vial_red'
  SP_VIAL    = 'vial_blue'
  #--------------------------------------------------------------------------
  # * Draw Vial
  #--------------------------------------------------------------------------
  def draw_vial(empty, full, percent, x, y)
    # Get Empty Bitmap
    empty_bitmap = RPG::Cache.picture(empty)
    # Create Destination Rect
    dest_rect = Rect.new(x, y, empty_bitmap.width, empty_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, empty_bitmap, empty_bitmap.rect)
    # Get full Bitmap
    full_bitmap = RPG::Cache.picture(full)
    # Get Width and Height
    width, height = full_bitmap.width, percent * full_bitmap.height / 100
    # Get Difference in height
    diff = full_bitmap.height - height
    # Create Source Rect
    src_rect = Rect.new(0, diff, full_bitmap.width, full_bitmap.height)
    # Create Destination Rect
    dest_rect = Rect.new(x, y + diff, full_bitmap.width, full_bitmap.height)
    # Stretch Blt 
    self.contents.stretch_blt(dest_rect, full_bitmap, src_rect)
  end
  #--------------------------------------------------------------------------
  # * Draw HP
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw Vial
    draw_vial(EMPTY_HP_VIAL, HP_VIAL, actor.hp / actor.maxhp, x, y)
    # Draw Hp Text
    self.contents.draw_text(x, y + 40, width, 32, actor.hp.to_s)
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # If Actor Maxsp is greater than 0
    if actor.maxsp > 0
      # Draw Vial
      draw_vial(EMPTY_SP_VIAL, SP_VIAL, actor.sp / actor.maxsp, x, y)
      # Draw Sp Text
      self.contents.draw_text(x, y + 40, width, 32, actor.sp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Clear Contents
    self.contents.clear
    # Run Through Each Actor With index
    $game_party.actors.each_with_index do |actor, index|
      # Get X coordinate
      actor_x = index * 160 + 4
      # Draws Name
      draw_actor_name(actor, actor_x, 0)
      # Draws Hp
      draw_actor_hp(actor, actor_x, 24)
      # Draws Sp
      draw_actor_sp(actor, actor_x + 80, 24)
      # Draw At
      draw_actor_at(actor, actor_x, 96, 120)
      # If Level Up Flags
      if @level_up_flags[i]
        # Normal Color
        self.contents.font.color = normal_color
        # Level Up
        self.contents.draw_text(actor_x, 120, 120, 32, 'LEVEL UP!')
      end
    end
  end
end
#--------------------------------------------------------------------------
#  End SDK Enabled Check
#--------------------------------------------------------------------------
end

I did change a few things in tibuda's coding the most important one was where he disposed the bitmap after drawing it, which isn't very efficient since when you goto draw again It has to be loaded again (see RPG::Cache in the help file)

Change the method names to draw_actor_(hp|sp)

Changed it so that you don't have to call the draw_vial method once with the empty and again for the full (added a full parameter to the method)

but other than those nothing really big

so if you want the vials to be animated give me a few more days (I seem to be saying this alot lately :-/)

Also tibuda consider posting this script :D
 
I did change a few things in tibuda's coding the most important one was where he disposed the bitmap after drawing it, which isn't very efficient since when you goto draw again It has to be loaded again (see RPG::Cache in the help file)
I remember that bitmap issue in the SDK thread. Just got used to dispose it.
so if you want the vials to be animated give me a few more days (I seem to be saying this alot lately )
This kind of indicator will look really better animated, but we can wait for you.
Also tibuda consider posting this script
Posted here.
I just edited one thing before posting, so we have a unique script working with or without your CBS. I just added the following to the window refresh method.
Code:
      if self.respond_to?(:draw_actor_at)
        # Draw At
        draw_actor_at(actor, actor_x, 96, 120)
      elsif !@level_up_flags[i]
        # Draws State
        draw_actor_state(actor, actor_x, 96)
      end
 

Mea

Member

Actually, I'm having a few problems.

I'm running SDK 1.5 because stuff started breaking when I tried to upgrade to SDK 2.0. Unforunately, I'm getting errors with the new script so I'm going to try to transition to SDK and see if I can fix the scripts that do break. Until then I won't be able to really test it.

Animated would be cool though.

ADDENDUM: Ugh, I'm glad I backed this project up because TONS of key stuff is breaking. Trickster, your Multi-Attack script, Seph's EIS, Raziel's Character select... The Steal script at least had an update. @_@

Anyhoo... Now I'm running SDK 2.1, the current version of the Conditional Turns CBS, but when I use the script I get this error:
Script 'Pictoral Indicators' line 90: NameError occured
undefined local variable or method 'i' for #<Window_BattleStatus:0x39f23b0>
I tried using the original version, but while it gave me no error, it also gave me empty bottles and no timing bar. oy...
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top