Help with HP/SP Bars script

I'm trying to make a game where all combat happens on the map and I need hp and sp bars. I'm having trouble trying to get this script to work. The game doesn't spit out any errors when I load the script, but I can't seem to get the bars to appear anywhere in the game.
Does anyone have any idea what I'm doing wrong?

I've moved this to Script Support.


This is for RPG Maker XP, everyone.
Yeah, that script creates methods on Window_Base to draw HP and SP bars (:draw_hp_bar and :draw_sp_bar). It only does that, nothing else. That means you need to call them somewhere for the bars to appear, in this case on the map.

What you have to do is create a window on Scene_Map, and draw those bars there. Also, that window will have to refresh its content when the actor's HP or SP changes.

I made an example, so you can check how it would look (you have to use both scripts)

Spoiler: Example
Ruby:
class Window_Bars < Window_Base
  # Initialize the window
  def initialize
    super(0, 0, 260, 48) # Define here the coords and size of the window
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    self.opacity = 0
    @actor = $game_party.actors[0] # Get the first actor on the party
    @last_hp = @actor.hp
    @last_sp = @actor.sp
    refresh
  end
  
  # Refresh the window (redraw the bars when necessary)
  def refresh
    self.contents.clear
    draw_hp_bar(@actor, 0, 0, 100)
    draw_sp_bar(@actor, 120, 0, 100)
  end
  
  # Update the window (refresh when necessary
  def update
    if @last_hp != @actor.hp || @last_sp != @actor.sp
      @last_hp = @actor.hp
      @last_sp = @actor.sp
      refresh
    end
  end
end

class Scene_Map
  # Start scene (create the window)
  alias bars_window_main main unless $@
  def main
    @bars_window = Window_Bars.new
    @bars_window.z = 99999
    bars_window_main
    @bars_window.dispose
  end
  
  # Update (update the window)
  alias bars_window_upd update unless $@
  def update
    bars_window_upd
    @bars_window.update
  end
end

Spoiler: Side note
I don't know about you, but I'm not a big fan of how those bars look, they're very typical, and their colors are too bright. Good thing is, the only thing you have to do is modify those two methods to draw something else, either a similar bar with other colors (play a bit with that script) or something more complex, for example a bar based on pictures. That's a bit harder to implement, so if you need an example of that, you can ask be about that.

See ya :ahappy:
Yeah, that script creates methods on Window_Base to draw HP and SP bars (:draw_hp_bar and :draw_sp_bar). It only does that, nothing else. That means you need to call them somewhere for the bars to appear, in this case on the map.

What you have to do is create a window on Scene_Map, and draw those bars there. Also, that window will have to refresh its content when the actor's HP or SP changes.

I made an example, so you can check how it would look (you have to use both scripts)

Spoiler: Example
Ruby:
class Window_Bars < Window_Base
  # Initialize the window
  def initialize
    super(0, 0, 260, 48) # Define here the coords and size of the window
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    self.opacity = 0
    @actor = $game_party.actors[0] # Get the first actor on the party
    @last_hp = @actor.hp
    @last_sp = @actor.sp
    refresh
  end
 
  # Refresh the window (redraw the bars when necessary)
  def refresh
    self.contents.clear
    draw_hp_bar(@actor, 0, 0, 100)
    draw_sp_bar(@actor, 120, 0, 100)
  end
 
  # Update the window (refresh when necessary
  def update
    if @last_hp != @actor.hp || @last_sp != @actor.sp
      @last_hp = @actor.hp
      @last_sp = @actor.sp
      refresh
    end
  end
end

class Scene_Map
  # Start scene (create the window)
  alias bars_window_main main unless $@
  def main
    @bars_window = Window_Bars.new
    @bars_window.z = 99999
    bars_window_main
    @bars_window.dispose
  end
 
  # Update (update the window)
  alias bars_window_upd update unless $@
  def update
    bars_window_upd
    @bars_window.update
  end
end

Spoiler: Side note
I don't know about you, but I'm not a big fan of how those bars look, they're very typical, and their colors are too bright. Good thing is, the only thing you have to do is modify those two methods to draw something else, either a similar bar with other colors (play a bit with that script) or something more complex, for example a bar based on pictures. That's a bit harder to implement, so if you need an example of that, you can ask be about that.

See ya :ahappy:
Thanks for the help! I see what you mean when you say that the bars are a bit bland and generic. Do you have an example of what a bar based on a picture would look like?
On my game I use a very basic "plane color" bar but with a static back graphic, so they look a bit better.

bars.png


If you want a bar that works like that, using something like the original script but including the back first is the easier choice, even if the bar changes color based on the value or things like that.

The picture bar is for controlling each possible step graphically, so you can make a bar with that like here, but it's particularly useful when things don't look much like a bar, like here. You can make hearts like in Zelda, curvy bars like in Kingdom Hearts, you name it.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-hp-sp-bars-script.138571/