khanhdu

XS - Actor Hud

Oct 4th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.78 KB | None | 0 0
  1. #==============================================================================
  2. #   XS - Actor Hud
  3. #   Author: Nicke
  4. #   Created: 13/08/2012
  5. #   Edited: 13/01/2013
  6. #   Version: 1.0c
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ? Materials but above ? Main. Remember to save.
  12. #==============================================================================
  13. # Requires: XS - Core Script.
  14. #==============================================================================
  15. # An actor hud that will be displayed on the map showing the current HP, MP and
  16. # TP for the party leader.
  17. #
  18. # Note: Make sure the switch is on to enable the actor hud. (Default is id 1)
  19. #
  20. # If you wish to remove a actor bar simply remove one of the :hp, :mp, :tp lines
  21. # in the settings. You may want to remove the icon for that as well.
  22. #
  23. # *** Only for RPG Maker VX Ace. ***
  24. #==============================================================================
  25. ($imported ||= {})["XAIL-ACTOR-HUD"] = true
  26.  
  27. module XAIL
  28.   module ACTOR_HUD
  29.   #--------------------------------------------------------------------------#
  30.   # * Settings
  31.   #--------------------------------------------------------------------------#
  32.       # FONT = [name, size, color, bold, shadow]
  33.       FONT = [["Shark Random Funnyness"], 15, Color.new(-225,255,255), true, true]
  34.      
  35.       # HUD = [width, height, x, y, z, opacity, contents_opacity, skin]
  36.       HUD = [150, 200, -6, -15,  200, 0, 200, nil]
  37.          
  38.       # Visbility switch.
  39.       # HUD_SWITCH = switch_id
  40.       HUD_SWITCH = 25
  41.      
  42.       # actor_bars = [vocab, width, height, value, color1, color2]
  43.       def self.actor_bars(actor)
  44.         actor_bars = {
  45.         :hp  => ["MP", 110, 14, actor.hp_rate, Color.new(255,30,30,75), Color.new(255,10,10,225)],
  46.         :mp  => ["HP", 110, 14, actor.mp_rate, Color.new(30,30,255,130), Color.new(10,10,255,225)],
  47.         :tp  => ["TP", 110, 14, actor.tp_rate, Color.new(30,255,30,130), Color.new(10,255,10,225)]
  48.         } # Don't remove this line!
  49.       end
  50.      
  51.       # ICONS[id] = icon_id
  52.       # Set the icons. (optional)
  53.       ICONS = []
  54.       ICONS[0] = 117 # HP
  55.       ICONS[1] = 103 # MP
  56.       ICONS[2] = 122 # TP
  57.      
  58.   end
  59. end
  60. # *** Don't edit below unless you know what you are doing. ***
  61. #==============================================================================#
  62. # ** Error Handler
  63. #==============================================================================#
  64.   unless $imported["XAIL-XS-CORE"]
  65.     # // Error handler when XS - Core is not installed.
  66.     msg = "The script %s requires the latest version of XS - Core in order to function properly."
  67.     name = "XS - Actor Hud"
  68.     msgbox(sprintf(msg, name))
  69.     exit
  70.   end
  71. #==============================================================================#
  72. # ** Window_Actor_Hud
  73. #==============================================================================#
  74. class Window_Actor_Hud < Window_Base
  75.  
  76.   def initialize
  77.     # // Method to initialize the window.
  78.     super(0, 0, window_width, window_height)
  79.     @actor = $game_party.leader
  80.     @refresh_ok = false
  81.     @last_hp = @actor.hp
  82.     @last_mp = @actor.mp
  83.     @last_tp = @actor.tp
  84.     refresh
  85.   end
  86.  
  87.   def window_width
  88.     # // Method to return the width.
  89.     return XAIL::ACTOR_HUD::HUD[0]
  90.   end
  91.  
  92.   def window_height
  93.     # // Method to return the height.
  94.     return XAIL::ACTOR_HUD::HUD[1]
  95.   end
  96.  
  97.   def refresh
  98.     # // Method to refresh the hud.
  99.     contents.clear
  100.     draw_actor_hud
  101.   end
  102.  
  103.   def draw_actor_hud
  104.     # // Method to draw the actor hud.
  105.     y = line_height
  106.     # // Draw actor name and level. (size is hard coded)
  107.     draw_font_text(@actor.name, 6, 12, contents.width, 0, XAIL::ACTOR_HUD::FONT[0], 18, XAIL::ACTOR_HUD::FONT[2], XAIL::ACTOR_HUD::FONT[3], XAIL::ACTOR_HUD::FONT[4])
  108.     draw_font_text("#{Vocab::level}: #{@actor.level}", 0, 12, contents.width, 2, XAIL::ACTOR_HUD::FONT[0], 18, XAIL::ACTOR_HUD::FONT[2], XAIL::ACTOR_HUD::FONT[3], XAIL::ACTOR_HUD::FONT[4])
  109.     for i in XAIL::ACTOR_HUD.actor_bars(@actor).values
  110.       # // Draw hp, mp and tp gauges and icons.
  111.       draw_gauge_ex(20, y, i[1], i[2], i[3], i[4], i[5])
  112.       draw_icons(XAIL::ACTOR_HUD::ICONS, :vertical, 0, line_height + 12)
  113.       draw_font_text(i[0], 26, y + 12, i[1], 0, XAIL::ACTOR_HUD::FONT[0], XAIL::ACTOR_HUD::FONT[1], XAIL::ACTOR_HUD::FONT[2], XAIL::ACTOR_HUD::FONT[3], XAIL::ACTOR_HUD::FONT[4])
  114.       y += line_height
  115.     end
  116.   end
  117.  
  118.   def update
  119.     # // Method to update the actor hud if a value has been changed.
  120.     super
  121.     check_actor_stats
  122.     if @refresh_ok
  123.       @refresh_ok = false
  124.       refresh
  125.     end
  126.   end
  127.  
  128.   def check_actor_stats
  129.     # // Method to check if a stat has been changed.
  130.     @refresh_ok = true ; @last_hp = @actor.hp if @last_hp != @actor.hp
  131.     @refresh_ok = true ; @last_mp = @actor.mp if @last_mp != @actor.mp
  132.     @refresh_ok = true ; @last_tp = @actor.tp if @last_tp != @actor.tp
  133.   end
  134.  
  135. end
  136. #==============================================================================
  137. # ** Scene_Map
  138. #==============================================================================
  139. class Scene_Map < Scene_Base
  140.  
  141.   alias xail_actor_hud_start start
  142.   def start(*args, &block)
  143.     # // Method to start the actor hud on the map.
  144.     xail_actor_hud_start(*args, &block)
  145.     create_actor_hud
  146.     check_actor_hud
  147.   end
  148.  
  149.   def create_actor_hud
  150.     # // Method to create the actor hud.
  151.     @actor_window = Window_Actor_Hud.new
  152.     @actor_window.x = XAIL::ACTOR_HUD::HUD[2]
  153.     @actor_window.y = XAIL::ACTOR_HUD::HUD[3]
  154.     @actor_window.z = XAIL::ACTOR_HUD::HUD[4]
  155.     @actor_window.opacity = XAIL::ACTOR_HUD::HUD[5]
  156.     @actor_window.contents_opacity = XAIL::ACTOR_HUD::HUD[6]
  157.     @actor_window.windowskin = Cache.system(XAIL::ACTOR_HUD::HUD[7]) unless XAIL::ACTOR_HUD::HUD[7].nil?
  158.   end
  159.  
  160.   alias xail_actor_hud_update update
  161.   def update(*args, &block)
  162.     # // Method to update the actor hud.
  163.     xail_actor_hud_update(*args, &block)
  164.     check_actor_hud
  165.   end
  166.  
  167.   def check_actor_hud
  168.     # // Method to check actor hud if it is enabled/disabled.
  169.     if $game_switches[XAIL::ACTOR_HUD::HUD_SWITCH]
  170.       create_actor_hud if @actor_window.nil?
  171.     else
  172.       dispose_actor_hud
  173.     end
  174.   end
  175.  
  176.   def dispose_actor_hud
  177.     # // Method to dipose actor hud.
  178.     @actor_window.dispose unless @actor_window.nil?
  179.     @actor_window = nil
  180.   end
  181.  
  182. end # END OF FILE
  183.  
  184. #=*==========================================================================*=#
  185. # ** END OF FILE
  186. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment