Ventwig

VTS-Enemy HP Bars (NEW)

Aug 13th, 2013
5,862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #============================================================================
  2. #VTS Enemy HP Bars
  3. #By Ventwig
  4. #Version 2.02 - Jul 15 2014
  5. #For RPGMaker VX Ace
  6. #=============================================================================
  7. #=============================================================================
  8. # Description:
  9. # This script adds HP bars that display the name, mp, and states of
  10. # enemies, with longer bars for up to two bosses.
  11. # Many other features are also included!
  12. #===============================================================================
  13. # Compatability:
  14. #  Works with Neo Gauge Ultimate Ace (Recommended)
  15. #===============================================================================
  16. # Instructions: Put in materials, above main.
  17. # Put below Neo Gauge Ultimate Ace if used
  18. #===============================================================================
  19. # Please give credit to Ventwig if you would like to use one of my scripts!
  20. # Use it commericial or non-commercial, and feel free to tell me if you're using
  21. # it commercially!
  22. # You may edit my scripts, just don't claim as your own!
  23. #===============================================================================
  24. #Notetags
  25. #===============================================================================
  26. #<hide_hp>
  27. #<show_mp>/<hide_mp>
  28. #<boss_bar>
  29. #<personal_y x>
  30. #===============================================================================
  31. #Mix and match the three notetags! They're pretty much self-explanatory.
  32. #<hide_hp> stops hp from being shown
  33. #<show_mp> shows an mp bar, if REVERSE_MP below is set to false.
  34. #<hide_mp> hides the mp bar, if REVERSE_MP is true.
  35. #          If reverse_mp is false, enemies have hidden mp by default. If true,
  36. #          then they normally have mp shown. Please use the right one.
  37. #<boss_bar> sets the enemy to a boss, using the long bar (A BOSS MUST BE THE
  38. #           FIRST ENEMY IN THE TROOP OR ELSE EVERYTHING GOES WHACK)
  39. #<personal_y x> set x to any number (positive or negative)
  40. #            determines how much to raise/lower the info for that enemy
  41. #            + numbers raise, and - numbers lower
  42. #===============================================================================
  43.  
  44. module EHUD
  45.  
  46.   #Determines how much to raise/lower the info
  47.   #Same as <personal_y x>, except this affects all enemies
  48.   Y_MOVE = 0
  49.  
  50.   #Are you using Neo Guage Ultimate Ace?
  51.   #Set true if yes, false if no
  52.   NEO_ULTIMATE_ACE = false
  53.  
  54.   #Want to show mp for most enemies but don't want to bother putting all the
  55.   #noteatags? Turn this to true and show_mp turns into hide_mp and will actually
  56.   #HIDE the mp. MP then shows by default
  57.   REVERSE_MP = false
  58.  
  59.   #Determines how to draw HP info
  60.   #true shows the current HP amount, where as false only displays the bar
  61.   DRAW_HP_NUMBERS = false
  62.  
  63.   #true displays the abbreviation for HP set in the "Vocab" section
  64.   #of the database, false does not
  65.   DRAW_HP_VOCAB = true
  66.  
  67.   #These settings make it compatible with my "Nova Battle Display" system!
  68.   #Play around with the numbers, but I've provided recommended "Nova" settings
  69.   #Change the X value of the bar. Def: 0  Nova:150
  70.   BOSS_GAUGEX = 10
  71.   #How long the boss gauge should be.  Def: 475  Nova:325
  72.   BOSS_GAUGEW = 475
  73.  
  74.   #Determines whether or not the minions' HP will still be shown in a boss battle!
  75.   #This is determined via a switch, so you can toggle per boss!
  76.   #ON=HIDE OFF=SHOW
  77.   #The thing about this switch, though, is that you have to toggle it MANUALLY
  78.   #everytime you want to change it. So before a boss fight, turn it on.
  79.   #After, turn it back off.
  80.   #THIS DOES NOT HAVE TO BE USED WITH JUST BOSSES
  81.   #Set to 0 if you don't want this.
  82.   HIDE_MINIONS = 0
  83.  
  84. end
  85.  
  86.  
  87. class RPG::BaseItem
  88.   def show_mp
  89.     if @show_mp.nil?
  90.       if EHUD::REVERSE_MP == false
  91.         if @note =~ /<show_mp>/i
  92.           @show_mp = true
  93.         else
  94.           @show_mp = false
  95.         end
  96.       else
  97.         if @note =~ /<hide_mp>/i
  98.           @show_mp= false
  99.         else
  100.           @show_mp = true
  101.         end
  102.       end
  103.     end
  104.     @show_mp
  105.   end
  106.   def hide_hp
  107.     if @hide_hp.nil?
  108.       if @note =~ /<hide_hp>/i
  109.         @hide_hp = true
  110.       else
  111.         @hide_hp = false
  112.       end
  113.     end
  114.     @hide_hp
  115.   end
  116.   def boss_bar
  117.     if @boss_bar.nil?
  118.       if @note =~ /<boss_bar>/i
  119.         @boss_bar= true
  120.       else
  121.         @boss_bar = false
  122.       end
  123.     end
  124.     @boss_bar
  125.   end
  126.   def personal_y
  127.     if @personal_y.nil?
  128.       if @note =~ /<personal_y (.*)>/i
  129.         @personal_y= $1.to_i
  130.       else
  131.         @personal_y = 0
  132.       end
  133.     end
  134.     @personal_y
  135.   end
  136. end
  137.  
  138. class Game_Enemy < Game_Battler
  139.  
  140.   alias shaz_enemyhud_initialize initialize
  141.  
  142.   attr_accessor :old_hp
  143.   attr_accessor :old_mp
  144.  
  145.   def initialize(index, enemy_id)
  146.         shaz_enemyhud_initialize(index, enemy_id)
  147.         @old_hp = mhp
  148.         @old_mp = mmp
  149.   end
  150.   def boss_bar
  151.      return enemy.boss_bar
  152.   end
  153.   def show_mp
  154.      return enemy.show_mp
  155.   end
  156.   def hide_hp
  157.      return enemy.hide_hp
  158.   end
  159.   def personal_y
  160.      return enemy.personal_y
  161.   end
  162. end
  163.  
  164. class Window_Enemy_Hud < Window_Base
  165.   def initialize
  166.     super(0,0,545,400)
  167.     self.opacity = 0
  168.     self.arrows_visible = false
  169.     self.z = 0
  170.     @enemy = []  
  171.     @boss_enemy = []
  172.     troop_fix
  173.     boss_check
  174.     enemy_hud
  175.     refresh
  176.   end
  177.  
  178. if EHUD::NEO_ULTIMATE_ACE == false
  179.   def draw_actor_mp(actor, x, y, width = 124)
  180.     draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  181.     change_color(system_color)
  182.   end
  183. else
  184.   def draw_actor_mp(actor, x, y, width = 124)
  185.     gwidth = width * actor.mp / [actor.mmp, 1].max
  186.     cg = neo_gauge_back_color
  187.     c1, c2, c3 = cg[0], cg[1], cg[2]
  188.     draw_neo_gauge(x + HPMP_GAUGE_X_PLUS, y + line_height - 8 +
  189.       HPMP_GAUGE_Y_PLUS, width, HPMP_GAUGE_HEIGHT, c1, c2, c3)
  190.     (1..3).each {|i| eval("c#{i} = MP_GCOLOR_#{i}")}
  191.     draw_neo_gauge(x + HPMP_GAUGE_X_PLUS, y + line_height - 8 +
  192.       HPMP_GAUGE_Y_PLUS, gwidth, HPMP_GAUGE_HEIGHT, c1, c2, c3, false, false,
  193.       width, 40)
  194.     change_color(system_color)
  195.   end
  196. end
  197.  
  198. if EHUD::NEO_ULTIMATE_ACE == false
  199.   def draw_actor_hp(actor, x, y, width = 124)
  200.     draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  201.     change_color(system_color)
  202.     draw_text(x, y, 30, line_height, Vocab::hp_a) if EHUD::DRAW_HP_VOCAB == true
  203.     change_color(hp_color(actor))
  204.     draw_text(x+width/4*3, y, 100, line_height, actor.hp) if EHUD::DRAW_HP_NUMBERS == true
  205.     change_color(system_color)
  206.   end
  207. else
  208.   def draw_actor_hp(actor, x, y, width = 124)
  209.     gwidth = width * actor.hp / actor.mhp
  210.     cg = neo_gauge_back_color
  211.     c1, c2, c3 = cg[0], cg[1], cg[2]
  212.     draw_neo_gauge(x + HPMP_GAUGE_X_PLUS, y + line_height - 8 +
  213.       HPMP_GAUGE_Y_PLUS, width, HPMP_GAUGE_HEIGHT, c1, c2, c3)
  214.     (1..3).each {|i| eval("c#{i} = HP_GCOLOR_#{i}")}
  215.     draw_neo_gauge(x + HPMP_GAUGE_X_PLUS, y + line_height - 8 +
  216.       HPMP_GAUGE_Y_PLUS, gwidth, HPMP_GAUGE_HEIGHT, c1, c2, c3, false, false,
  217.       width, 30)
  218.       change_color(system_color)
  219.     draw_text(x, y, 30, line_height, Vocab::hp_a) if EHUD::DRAW_HP_VOCAB == true
  220.        change_color(hp_color(actor))
  221.     draw_text(x+width/4*3, y, 100, line_height, actor.hp) if EHUD::DRAW_HP_NUMBERS == true
  222.        change_color(system_color)
  223.   end
  224. end
  225.  
  226.   def troop_fix
  227.     @etroop = $game_troop
  228.     return if @etroop.alive_members.size <= 0
  229.     for i in 0..@etroop.alive_members.size-1
  230.       @enemy[i] = @etroop.alive_members[i]
  231.     end
  232.   end
  233.  
  234.   def enemy_hud
  235.     troop_fix    
  236.     for i in 0..@etroop.alive_members.size-1
  237.       e = @enemy[i]
  238.       if i <= 1 and e.boss_bar == true and e == @boss_enemy[i]
  239.         draw_actor_name(e,EHUD::BOSS_GAUGEX,5+50*i)
  240.         draw_actor_hp(e,EHUD::BOSS_GAUGEX,20+50*i,width=EHUD::BOSS_GAUGEW) unless e.hide_hp == true
  241.         draw_actor_mp(e,EHUD::BOSS_GAUGEX,30+50*i,width=EHUD::BOSS_GAUGEW) unless e.show_mp == false
  242.         draw_actor_icons(e,EHUD::BOSS_GAUGEX+200,5+50*i, width = 96)
  243.       elsif $game_switches[EHUD::HIDE_MINIONS] != true
  244.         draw_actor_hp(e,e.screen_x-50,e.screen_y+EHUD::Y_MOVE-50+e.personal_y,width=96) unless e.hide_hp == true
  245.         draw_actor_mp(e,e.screen_x-50,e.screen_y+EHUD::Y_MOVE-40+e.personal_y,width=96) unless e.show_mp == false
  246.         draw_actor_icons(e,e.screen_x-50,e.screen_y+EHUD::Y_MOVE-70+e.personal_y,width=96)
  247.       end
  248.     end
  249.   end
  250.    
  251.   def refresh
  252.     contents.clear
  253.     enemy_hud
  254.     boss_check if @boss_enemy !=nil
  255.   end
  256.  
  257.   def boss_check
  258.     if @enemy[0].boss_bar == true
  259.       @boss_enemy[0] = @enemy[0]
  260.       if @enemy[1] != nil
  261.         if @enemy[1].boss_bar == true
  262.           @boss_enemy[1] = @enemy[1]
  263.         else
  264.           @boss_enemy[1] = nil
  265.         end
  266.       end
  267.     else
  268.       @boss_enemy[0] = nil
  269.       @boss_enemy[1]= nil
  270.     end
  271.   end
  272.  
  273.  
  274.   def update
  275.     refresh_okay = false
  276.     $game_troop.alive_members.each do |enemy|
  277.       if enemy.hp != enemy.old_hp || enemy.mp != enemy.old_mp
  278.         refresh_okay = true
  279.         enemy.old_hp = enemy.hp
  280.         enemy.old_mp = enemy.mp
  281.       end
  282.     end
  283.    
  284.     if $game_troop.alive_members.size != @old_size
  285.       refresh_okay = true
  286.     end
  287.    
  288.     if refresh_okay
  289.       refresh
  290.     end
  291.   end
  292. end
  293.  
  294. class Scene_Battle < Scene_Base
  295.   alias hpbars_create_all_windows create_all_windows
  296.   def create_all_windows
  297.     hpbars_create_all_windows
  298.     create_enemy_hud_window
  299.   end
  300.   def create_enemy_hud_window
  301.     @enemy_hud_window = Window_Enemy_Hud.new
  302.   end
  303. end
  304.   #########################################################################
  305.   #End Of Script                                                          #
  306.   #########################################################################
RAW Paste Data