Vlue

Basic Enemy HP Bars Lite

Apr 3rd, 2014
7,776
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #--# Basic Enemy HP Bars Lite v 1.1c
  2. #
  3. # Adds options for hp/mp bars, enemy name, state icons, and even targetting icon
  4. #  to appear over the enemy in battle.
  5. #
  6. # Usage: Plug and play, customize as needed.
  7. #       New Notetag: <BOSS> determines if enemy is a boss or not.
  8. #                    <HIDE NAME> name displays as ???
  9. #
  10. #------#
  11. #-- Script by: V.M of D.T
  12. #
  13. #- Questions or comments can be:
  14. #    posted on the thread for the script
  15. #    given by email: sumptuaryspade@live.ca
  16. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  17. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  18. #
  19. #--- Free to use in any project, commercial or non-commercial, with credit given
  20. #--Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  21.  
  22. module DTP_HP
  23.   #Whether to include the hp bar or not
  24.   USE_HP_BAR = true
  25.   #Whether to include an mp bar or not
  26.   USE_MP_BAR = false
  27.   #Whether or not to include state icons
  28.   USE_STATES = false
  29.   #Whether to display enemy name or not
  30.   USE_TEXT = false
  31.   #Display HP numbers
  32.   USE_HP_TEXT = false
  33.   #Icon to be displayed over current target, set to 0 to disable
  34.   DISPLAY_ICON = 325
  35.  
  36.   #Display hp bar above the enemy, false for below
  37.   ABOVE_MONSTER = true
  38.   #Offset the hp bar along the x-axis(left,right)
  39.   BAR_OFFSET_X = 0
  40.   #Offset the hp bar along the y-axis(up,down)
  41.   BAR_OFFSET_Y = 0
  42.  
  43.   #First color for the mp bar gradient
  44.   MP_COLOR_BAR_1 = Color.new(0,175,255)
  45.   #Second color fot the mp bar gradient
  46.   MP_COLOR_BAR_2 = Color.new(0,0,255)
  47.  
  48.   #Show bars only when specific actor in party. Array format. Example: [8,7]
  49.   #Set to [] to not use actor only
  50.   SPECIFIC_ACTOR = []
  51.   #Show enemy hp bar only if certain state is applied (like a scan state)
  52.   #Set to 0 to not use state only
  53.   SCAN_STATE = 0
  54.   #Enemies will show hp bar as long as they have been affected by scan state
  55.   #at least once before
  56.   SCAN_ONCE = false
  57.   #Hp bars will only show when you are targetting a monster
  58.   ONLY_ON_TARGET = false
  59. end
  60.  
  61. class Sprite_Battler
  62.   alias hpbar_update update
  63.   alias hpbar_dispose dispose
  64.   def update
  65.     hpbar_update
  66.     return unless @battler.is_a?(Game_Enemy)
  67.     if @battler
  68.       update_hp_bar
  69.     end
  70.   end
  71.   def update_hp_bar
  72.     setup_bar if @hp_bar.nil?
  73.     determine_visible
  74.     return unless @hp_bar.visible
  75.     @hp_bar.update
  76.     if @hp_bar.contents_opacity != self.opacity
  77.       @hp_bar.contents_opacity = self.opacity
  78.     end
  79.     @hp_bar.y = self.y + DTP_HP::BAR_OFFSET_Y - self.height - @hp_bar.height
  80.     @hp_bar.y = self.y + DTP_HP::BAR_OFFSET_Y unless DTP_HP::ABOVE_MONSTER
  81.     @hp_bar.y = 0 if @hp_bar.y < 0
  82.     @hp_bar.y = -12 if @battler.boss?
  83.     @hp_bar.contents.clear
  84.     width = @hp_bar.contents.width - @hp_bar.padding
  85.     hp_width = @battler.hp_rate
  86.     yy = 0
  87.     if DTP_HP::DISPLAY_ICON > 0
  88.       if SceneManager.scene.is_a?(Scene_Battle) &&
  89.         SceneManager.scene.enemy_window &&
  90.         SceneManager.scene.enemy_window.active &&
  91.         SceneManager.scene.target_window_index == @battler.index
  92.           @hp_bar.draw_icon(DTP_HP::DISPLAY_ICON,@hp_bar.contents.width/2,yy)
  93.       end
  94.       yy += 24
  95.     end
  96.     if DTP_HP::USE_TEXT and !@battler.boss?
  97.       if @battler.hide_name
  98.         @hp_bar.draw_text(0,yy,width,24,"???",2)
  99.       else
  100.         @hp_bar.draw_text(0,yy,width,24,@battler.name,2)
  101.       end
  102.       yy += 24
  103.     end
  104.     if DTP_HP::USE_HP_BAR
  105.       height = @battler.boss? ? 16 : 8
  106.       yy -= 12 if !DTP_HP::USE_HP_TEXT
  107.       if @special
  108.         @hp_bar.draw_actor_hp(@battler, @hp_bar.padding/2, yy, width, height, @battler.boss? || !DTP_HP::USE_HP_TEXT)
  109.       else
  110.         if !DTP_HP::USE_HP_TEXT
  111.           @hp_bar.draw_actor_hp_notext(@battler, @hp_bar.padding/2, yy, width)
  112.         else
  113.           @hp_bar.draw_actor_hp(@battler, @hp_bar.padding/2, yy, width)
  114.         end
  115.       end
  116.       yy += 12
  117.     end
  118.     if DTP_HP::USE_TEXT and @battler.boss?
  119.       if @battler.hide_name
  120.         @hp_bar.draw_text(0,12,width,24,"???",2)
  121.       else
  122.         @hp_bar.draw_text(0,12,width,24,@battler.name,2)
  123.       end
  124.       if @special
  125.         @hp_bar.change_color(@hp_bar.system_color)
  126.         @hp_bar.draw_text(0,24,width,24,Vocab::hp_a)
  127.         @hp_bar.change_color(@hp_bar.normal_color)
  128.       end
  129.     end
  130.     if DTP_HP::USE_MP_BAR and !@battler.boss?
  131.       mp_width = @battler.mp_rate * width
  132.       @gauge_hp_y_for_nothing_at_all = yy
  133.       @hp_bar.draw_gauge(@hp_bar.padding/2,yy,width,@battler.mp_rate,DTP_HP::MP_COLOR_BAR_1,DTP_HP::MP_COLOR_BAR_2)
  134.       yy += 24
  135.     end
  136.     if DTP_HP::USE_STATES
  137.       xx = 2
  138.       yy += 12 if @battler.boss?
  139.       @battler.states.each do |state|
  140.         @hp_bar.draw_icon(state.icon_index,xx,yy)
  141.         xx += 24
  142.       end
  143.     end
  144.   end
  145.   def setup_bar
  146.     @special = Module.const_defined?(:SPECIAL_GAUGES)
  147.     if @battler.boss?
  148.       @hp_bar = Window_Base.new(0,-12,Graphics.width,96)
  149.     else
  150.       height = 24
  151.       height += 24 if DTP_HP::DISPLAY_ICON > 0
  152.       height += 24 if DTP_HP::USE_TEXT
  153.       height += 24 if DTP_HP::USE_HP_BAR
  154.       height += 24 if DTP_HP::USE_MP_BAR
  155.       height += 24 if DTP_HP::USE_STATES
  156.       @hp_bar = Window_Base.new(0,0,120,height)
  157.       @hp_bar.x = self.x - @hp_bar.width / 2 + DTP_HP::BAR_OFFSET_X
  158.       @hp_bar.y = self.y + DTP_HP::BAR_OFFSET_Y - self.height - @hp_bar.height
  159.       @hp_bar.y = self.y + DTP_HP::BAR_OFFSET_Y unless DTP_HP::ABOVE_MONSTER
  160.       @hp_bar.x = 0 if @hp_bar.x < 0
  161.       @hp_bar.y = 0 if @hp_bar.y < 0
  162.     end
  163.     @hp_bar.opacity = 0
  164.     @hp_bar.z = self.z + 1
  165.     @hp_bar.viewport = self.viewport
  166.   end
  167.   def determine_visible
  168.     if !@battler.alive? && !@battler.hidden?
  169.       if @special
  170.         if @hp_bar.gauges[[@hp_bar.padding/2,@gauge_hp_y_for_nothing_at_all]]
  171.           @hp_bar.visible = false if @hp_bar.gauges[[@hp_bar.padding/2,@gauge_hp_y_for_nothing_at_all]].cur_val == 0
  172.         end
  173.       else
  174.         @hp_bar.visible = false
  175.       end
  176.       if DTP_HP::SCAN_ONCE and DTP_HP::SCAN_STATE == 1
  177.         $game_party.monster_scans[@battler.enemy_id] = true
  178.       end
  179.       return if !@battler.alive?
  180.     end
  181.     @hp_bar.visible = true
  182.     if DTP_HP::SCAN_STATE != 0
  183.       @hp_bar.visible = false
  184.       @hp_bar.visible = true if @battler.state?(DTP_HP::SCAN_STATE)
  185.       if DTP_HP::SCAN_ONCE
  186.         @hp_bar.visible = true if $game_party.monster_scans[@battler.enemy_id] == true
  187.         $game_party.monster_scans[@battler.enemy_id] = true if @hp_bar.visible
  188.       end
  189.     end
  190.     if !DTP_HP::SPECIFIC_ACTOR.empty?
  191.       @hp_bar.visible = false unless DTP_HP::SCAN_STATE != 0
  192.       DTP_HP::SPECIFIC_ACTOR.each do |i|
  193.         next unless $game_party.battle_members.include?($game_actors[i])
  194.         @hp_bar.visible = true
  195.       end
  196.     end
  197.     if DTP_HP::ONLY_ON_TARGET
  198.       return unless SceneManager.scene.is_a?(Scene_Battle)
  199.       return unless SceneManager.scene.enemy_window
  200.       @hp_bar.visible = SceneManager.scene.target_window_index == @battler.index
  201.       @hp_bar.visible = false if !SceneManager.scene.enemy_window.active
  202.     end
  203.   end
  204.   def dispose
  205.     @hp_bar.dispose if @hp_bar
  206.     hpbar_dispose
  207.   end
  208. end
  209.  
  210. class Window_Base
  211.   def draw_actor_hp_notext(actor, x, y, width = 124)
  212.     draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  213.     change_color(system_color)
  214.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  215.     change_color(normal_color)
  216.   end
  217. end
  218.  
  219. class Scene_Battle
  220.   attr_reader  :enemy_window
  221.   def target_window_index
  222.     begin
  223.     @enemy_window.enemy.index
  224.     rescue
  225.       return -1
  226.     end
  227.   end
  228. end
  229.  
  230. class Game_Party
  231.   alias hp_bar_init initialize
  232.   attr_accessor  :monster_scans
  233.   def initialize
  234.     hp_bar_init
  235.     @monster_scans = []
  236.   end
  237. end
  238.  
  239. class Game_Enemy
  240.   def boss?
  241.     self.enemy.note =~ /<BOSS>/
  242.   end
  243.   def hide_name
  244.     self.enemy.note =~ /<HIDE NAME>/
  245.   end
  246. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×