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.

Enemy Window Script

I'm making a custom battle system and need some help.

I would like a window that appears at the top of the screen and is called by a switch. It would show a health bar. Two variables would control how full it is. (one variable for max full, the other for current full.)

I hope someone could do this for me. Beelow is what I already have. The window would be like the one on the left, but for the enemy.

http://h1.ripway.com/ScourgeDragon/BattleImage.jpg[/IMG]
 
Yes, only an HP bar.:D But, it has to be controlled by variables. One for the monster's max HP and one for its current HP.

Example: If variable #1 is 100 and Variable #2 is 100, the bar will be full. But, if varible #1 is 50 and Varible #2 is 100, then the bar will appear half full.
 
Just put this below your script:

Code:
ENEMYHP_VARIABLE_ID = 1
ENEMYMAXHP_VARIABLE_ID = 2

class Scene_Map
    
  alias raz_map_battlehud_main main
  alias raz_map_battlehud_update update
  
  def main
    @battle_switch = 1
    @enemy_hud = Enemy_HUD.new
    @enemy_hud.visible = false
    raz_map_battlehud_main
    @enemy_hud.dispose
  end
  
  def update
    @enemy_hud.update
    if $game_switches[@battle_switch]
      unless @hud_visible == true
      @enemy_hud.visible = true
      @hud_visible = true
      end
    end
    raz_map_battlehud_update
  end
  

end

class Enemy_HUD < Window_Base
  def initialize
    super(300, 0, 340, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0,100,32,"Enemy HP")
    min = $game_variables[ENEMYHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYHP_VARIABLE_ID]
    max = $game_variables[ENEMYMAXHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYMAXHP_VARIABLE_ID]
    draw_slant_bar(100, 12, min, max, 200, 9, Color.new(150, 0, 0, 255), Color.new(255, 0, 0, 255))
  end
  
    def update
    super
      if @old_hp_enemy != $game_variables[ENEMYHP_VARIABLE_ID]
        refresh
       @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    end
  end

end

Just exchange the numbers in
Code:
ENEMYHP_VARIABLE_ID = 1
ENEMYMAXHP_VARIABLE_ID = 2
with the variables you want to use.
The upper one is for the current hp and the lower one for the max hp.
You can also change the switch to turn the hud on or off here:
Code:
@battle_switch = 1

Just ask if you have any questions.
 
Exchange the script with this one, it should work now:
Code:
ENEMYHP_VARIABLE_ID = 1
ENEMYMAXHP_VARIABLE_ID = 2

class Scene_Map
    
  alias raz_map_battlehud_main main
  alias raz_map_battlehud_update update
  
  def main
    @battle_switch = 1
    @enemy_hud = Enemy_HUD.new
    @enemy_hud.visible = false
    raz_map_battlehud_main
    @enemy_hud.dispose
  end
  
  def update
    @enemy_hud.update
    unless @hud_visible == true
      if $game_switches[@battle_switch]
      @enemy_hud.visible = true
      @hud_visible = true
      @hud_off = true
      end
    end
    unless @hud_off == false
      if $game_switches[@battle_switch] == false
      @enemy_hud.visible = false
      @hud_visible = false
      @hud_off = false
     end
    end
    raz_map_battlehud_update
  end
  

end

class Enemy_HUD < Window_Base
  def initialize
    super(300, 0, 340, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0,100,32,"Enemy HP")
    min = $game_variables[ENEMYHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYHP_VARIABLE_ID]
    max = $game_variables[ENEMYMAXHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYMAXHP_VARIABLE_ID]
    draw_slant_bar(100, 12, min, max, 200, 9, Color.new(150, 0, 0, 255), Color.new(255, 0, 0, 255))
  end
  
    def update
    super
      if @old_hp_enemy != $game_variables[ENEMYHP_VARIABLE_ID]
        refresh
       @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    end
  end

end
 

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