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.

[Resolved by Kain Nobel] I need HP and SP bars on this please.

I need some help with someone putting  HP and SP bars in this script for me. It really can't be that hard to do I'm just not sure how to.

Code:
#=========================================
#Pathways Date/Time/Health/Mana/Gold Hub.
# Base coded by: Uknown
# Modified by: L0rdPh0enix
# Aided by: khmp
#=========================================
class Window_HUD < Window_Base
  ICON_NAMES = {
    'hp' => 'heart.png',
    'sp' => 'mana.png',
    'gold' => 'gold.png'}
    
  def initialize
    super(464,368,176,112)
    self.z = 8000
    self.contents = Bitmap.new(140,80)
    self.contents.font.size = 12
    self.back_opacity = 160
    
    #Health Icon Start
    @health_ico = RPG::Cache.icon(ICON_NAMES['hp'])
      
    #Mana Icon Start
    @mana_ico = RPG::Cache.icon(ICON_NAMES['sp'])
    
    
    #Gold Icon Start
    @gold_ico = RPG::Cache.icon(ICON_NAMES['gold'])
    
    # Clear color.
    @clear_color = Color.new(0, 0, 0, 0)
    
    # Variables used to determine what needs to be redrawn.
    @gold = @health = @mana = nil
      
    refresh
  end
  
  def refresh
    # Draw the time
    self.contents.fill_rect(Rect.new(@health_ico.width, 1, 132, 20), 
      @clear_color)
    self.contents.draw_text(4, 1, 132, 20, "#{$game_variables[142]}:0#{$game_variables[141]}", 1)
    
    @actor = $game_party.actors[0]
    
    if @health != @actor.hp
      # Save the variable.
      @health = @actor.hp
      self.contents.fill_rect(Rect.new(@health_ico.width, 18, 132, 16), 
        @clear_color)
      draw_actor_hp(@actor, 4, 16)
      self.contents.blt(0, 12, @health_ico, 
        Rect.new(0, 0, @health_ico.width, @health_ico.height))
    end
    
    if @mana != @actor.sp
      @mana = @actor.sp
      self.contents.fill_rect(Rect.new(@health_ico.width, 41, 132, 16), 
        @clear_color)
      draw_actor_sp(@actor, 4, 38)
      self.contents.blt(0, 40, @mana_ico, 
        Rect.new(0, 0, @mana_ico.width, @mana_ico.height))
    end
    
    if @gold != $game_party.gold
      @gold = $game_party.gold
      self.contents.fill_rect(Rect.new(@health_ico.width, 64, 132, 16), 
        @clear_color)
      self.contents.draw_text(4, 64, 132, 20, $game_party.gold.to_s, 2)
      self.contents.blt(50, 58, @gold_ico, 
        Rect.new(0, 0, @gold_ico.width, @gold_ico.height))
    end
  end
end
  
class Scene_Map
  #=========================================
  # * Constant Variables
  #=========================================
  HUD_SWITCH = 2

  alias hud_main main
  alias hud_update update

  def main
    @timer = 0
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  #=========================================
  # * Frame Update
  #=========================================
  def update
    @timer += 1
    @hud.visible = $game_switches[HUD_SWITCH]
    if @timer >= 30 && @hud.visible
      @timer = 0
      @hud.refresh
    end
    hud_update
  end
end

Thanks in advance.
 

Zeriab

Sponsor

It looks there has been used a code tag.
The problem lies in that the script is too big.

Can you upload the script as a text file hosted a separate place? (Preferable a direct link)

*hugs*
- Zeriab
 
Is it just slant bars you're needing with this? That appears to be the only major problem when I tested the script, the bars seemed to cut out at about 15 % of the bar or so, which I am assuming was what you needed to fix.

I tried to code it into your HUD but I ended up just re-writting the thing from scratch with a couple of my private 'MACL' scripts. Instead of it refreshing the entire window every few frames (even if it really doesn't need it), I made it real-time update and repositioned the text/icon a little bit and made a settings module for you.

The main change is instead of refreshing an entire window, it clears parts of the rect which a changed stat is drawn and refreshes just that part by iteself only on a as-needed basis. I'd assume a little HUD like this shouldn't cause any lag, but when testing the 'refresh' frames, I broke down refresh into 3 seperate methods that each handle their own stat (gold, hp, sp), which already increased frame rate by 5 frames. Anything that was coded into Window_Hud#refresh or Scene_Map#update is basically called through Window_HUD#update now.

http://www.mediafire.com/download.php?tynmtyhjmmm

I forgot about the timer though, I can throw something in for that too though if you'd like. You use variables to control your timer, or whats up with that? Hope you enjoy! :thumb:
 
WOW thank you Kain Nobel, you really helped me here thats just what I needed. don't worry about the time i'm using a different time system then before and gonna have it in a seperate window at the top right of the screen. But yeah the code looks great. You're getting credited under the scripts section of my credits and the special thanks section :wink:
 

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