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.

Show HP bar above enemies (RTAB/zoom compatible)

Well I'm looking for something that would be compatible with RTAB, and possibly work with the zooming camera function of it. I would want something that would show an HP bar for enemies, but not show numbers values. Kinda like...in Breath of Fire 1. It would show a bar that would go down when you would hit an enemy, but not show you a number. I dunno if I would want it to be above their heads all the time, or just when they are being hit.

I think there was a script like this, but I didn't like it cuz I think it showed it for allies too, and also it showed MP as well...and I think it might have showed numbers too. If anyone knows of something that is similar to what I want (doesn't have to be exactly...I'm not THAT picky), let me know. Also, it would be a nice bonus if it WOULD show numbers as long as a certain party member was in the party, or if a certain accessory was equipped or something.
 
Don't have one that is compatible with the ZOOM feature. That's a little difficult to control. What I have below is by Raziel, with a couple minor changes (allowing for RTAB). I also included a comment which shows you where I commented out the text from the Enemy bars.

If you don't like the position, edit the @enemy.screen_y - 10 value (the 10 anyway) to change the height of the bar.

Code:
class Window_Base < Window  
  #--------------------------------------------------------------------------
  # * Draw Slant Bar(by SephirothSpawn)
  #--------------------------------------------------------------------------
  def draw_slant_bar(x, y, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    # Draw Border
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
    end
    # Draw Background
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    # Draws Bar
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 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 + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
end


class Window_EnemyHP < Window_Base
  
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    refresh
  end
  
  def refresh
    self.contents.clear
    for i in 0...$game_troop.enemies.size
      @enemy = $game_troop.enemies[i]
      @percent = (@enemy.hp * 100) / @enemy.maxhp
      unless @enemy.hp == 0
        draw_slant_bar(@enemy.screen_x - 55, @enemy.screen_y - 10, @enemy.hp, @enemy.maxhp, width = 75, height = 6, bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
        # I Commented the next line as you didn't want text
        # self.contents.draw_text(@enemy.screen_x - 39, @enemy.screen_y - 22, 100, 32, "#{@percent}" + "%")
      end
    end
  end
end

class Scene_Battle
  
  alias raz_update update
  alias raz_update_phase5 update_phase5
  alias raz_update_phase4_step1 update_phase4_step1
  alias raz_update_phase4_step5 update_phase4_step5
  alias raz_enemy_hp_main main
  
   def main
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    @enemy_window = Window_EnemyHP.new
    @enemy_window.z = 95
    raz_enemy_hp_main
    @enemy_window.dispose
  end
  
  def update
    @enemy_window.update
    raz_update
  end

  def update_phase5
    # If wait count is larger than 0
    if @phase5_wait_count > 0
      # Decrease wait count
      @phase5_wait_count -= 1
      # If wait count reaches 0
      if @phase5_wait_count == 0
        @enemy_window.visible = false
        # Show result window
        @result_window.visible = true
        # Clear main phase flag
        $game_temp.battle_main_phase = false
        # Refresh status window
        @status_window.refresh
        @enemy_window.refresh
      end
      return
    end
    raz_update_phase5
  end

  def update_phase4_step1(battler=@active_battler)
    raz_update_phase4_step1(battler)
    @enemy_window.refresh
  end

  def update_phase4_step5(battler=@active_battler)
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    @enemy_window.refresh
    raz_update_phase4_step5(battler)
  end
end
Note: The inclusion of the (battler) conditions to the phase4 defs in Scene_Battle was all that was necessary for this (non-zooming) edit.
 
Hmm okay, I think that would be fine if it doesn't work with zoom. Cuz I'm eventually going to switch to side view battlers when I can find a big enough collection, and I wouldn't want zoom then, so yeah.
 
Sorry, but when I used this it worked fine, except the bar decreases AFTER the damage pops up. I guess this is something to do with RTAB. Would there be a way to make it so the bar goes down like right when the animation for the attack happens?
 
Actually, the default battlesystem shows the 'Pop-Up' before it subtracts the damage from the enemy, so it's not RTAB related. Just a standard practice as (in the default script and classes) it calculates the damage when it performs the 'pop'. It won't do it in reversed order.
 
Y'know I do recall a script that displayed the enemy HP on the left upper hand corner of the screen made by that one guy who was working on the Breath of Fire Battle System. I'm at work right now so I cant look it up, but I can once I get home. That might work for ya....
 
@DerVV: Is there a way to change that? It seems like all you'd have to do was switch a few things.

@J.D.: I'll look at it if you find it. The one I got is fine, but I'm just having a problem with the thing DerVV was talking about. But yeah, thx, I'll look at it.
 
Change it? Nope. The RGSS BITMAP class does the work of making the pop-up as part of the RMXP Battle Animation system itself.

If you look in the RMXP Editor... Go into the Database an hit the [Animation] tab itself. If you look at the editor, you can set which frame in the animation has a 'HIT' or not. It is that actual 'HIT' that creates the pop-up that shows the damage. And if you use a system that can tap into the Battle Animation routine to create multiple hits... you REALLY don't want to mess with it.

And as it is the Battle Animation and BITMAP that generates the hits (and subsequently) the damage, it is performed before the damage is applied to the enemy... thus before the Enemy Bar is drawn.
 
Wow, I understood approximately 3 words of that lol. Actually I know what you mean (sorta :P) so I understand. It's fine, the players will just have to deal with it. Thx ^_^.

Edit: I also noticed that when I kill an enemy it takes a pretty long time for the bar to disappear for them. It seems like it takes longer than how long it takes for the bar to go down when you hit them...so I dunno if THIS is something that could be fixed or not.
 
It has to deal with the additional BITMAP condition of the 'collapse' (or death fade) routine.

It's nothing more than the system adding another delay based on the time it takes for a battler to fade away. Can't remove that delay either, as it would mean keeping the battler on the screen after killing it.
 

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