dsiver144

Dark's Survival Hud v1.1

Mar 17th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.69 KB | None | 0 0
  1. #===============================================================================
  2. #                     ╔══════════════════════════════════╗
  3. #                     ║ ▼ Dark's Survival Hud            ║  
  4. #                     ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. #                     ║ ▼ Release Date: March 14th 2016  ║
  6. #                     ║ ▼ Forum: TaoTroChoi.com          ║
  7. #                     ╚══════════════════════════════════╝
  8. #-------------------------------------------------------------------------------
  9. #                        Version 1.0: Release!
  10. #                        Version 1.1: Add new function!
  11. #-------------------------------------------------------------------------------
  12. #                           Writen for mr.rpg.700.
  13. #-------------------------------------------------------------------------------
  14. # Notetag: [Items]
  15. # <dark_hud_energy_add: x> Tăng giá trị của Energy thêm x.
  16. # <dark_hud_energy_add_percent: x> Tăng giá trị của Energy thêm x%.
  17. # <dark_hud_hydra_add: x> Tăng giá trị của Hydration thêm x.
  18. # <dark_hud_hydra_add_percent: x> Tăng giá trị của Hydration thêm x%.
  19. #===============================================================================
  20.   $imported = {} if $imported.nil?
  21.   $imported["DRKS-Survival_Hud"] = true
  22.   module DRKS_HUD
  23.     HUD_X         = -10
  24.     HUD_Y         = -10
  25.     BAR1_TEXT     = "Energy"
  26.     BAR2_TEXT     = "Hydration"
  27.     BAR1_COLOR    = Color.new(238,182,0)
  28.     BAR2_COLOR    = Color.new(0,166,238)
  29.     HUD_SWITCH    = 5 # Switch bật tắt HUD
  30.     BAR1_VAR      = 5 # VAR ID value của thanh 1
  31.     BAR2_VAR      = 6 # VAR ID value của thanh 2
  32.     BAR1_MAX_VAR  = 7 # VAR ID max value chỉ số của thanh 1.
  33.     BAR2_MAX_VAR  = 8 # VAR ID max value chỉ số của thanh 2.
  34.     #--------------------------------------------------------
  35.     REGEX_ADD_ENERGY_VAR          = /<dark_hud_energy_add:\s*(\w+)>/i
  36.     REGEX_ADD_PERCENT_ENERGY_VAR  = /<dark_hud_energy_add_percent:\s*(\w+)>/i
  37.     REGEX_ADD_PERCENT_HYDRA_VAR   = /<dark_hud_hydra_add_percent:\s*(\w+)>/i
  38.     REGEX_ADD_HYDRATION_VAR       = /<dark_hud_hydra_add:\s*(\w+)>/i
  39.   end
  40.   include DRKS_HUD
  41.   class Scene_Map < Scene_Base
  42.     alias dark_survivalhud_start_scene_map  start
  43.     alias dark_survivalhud_update_scene_map update
  44.     def start
  45.       dark_survivalhud_start_scene_map
  46.       @window_drks_survival_hud = DRKS_SurvivalHud.new(HUD_X,HUD_Y)
  47.     end
  48.     def update
  49.       dark_survivalhud_update_scene_map
  50.       if $game_switches[HUD_SWITCH] == true
  51.         @window_drks_survival_hud.refresh
  52.       else
  53.         @window_drks_survival_hud.clear_hud if !@window_drks_survival_hud.hud_cleared?
  54.       end
  55.     end
  56.   end
  57.  
  58.   class DRKS_SurvivalHud < Window_Base
  59.     include DRKS_HUD
  60.     #-------------------------------------------------------------------------
  61.     # * Initialize
  62.     #-------------------------------------------------------------------------
  63.     def initialize(x,y)
  64.       super(x,y,190,80)
  65.       self.opacity = 0
  66.       self.back_opacity = 0
  67.       @cleared = false
  68.     end
  69.     #-------------------------------------------------------------------------
  70.     # * Clear?
  71.     #-------------------------------------------------------------------------
  72.     def hud_cleared?
  73.       @cleared
  74.     end
  75.     #-------------------------------------------------------------------------
  76.     # * Clear Hud
  77.     #-------------------------------------------------------------------------
  78.     def clear_hud
  79.       contents.clear
  80.       @cleared = true
  81.     end
  82.     #-------------------------------------------------------------------------
  83.     # * Refresh
  84.     #-------------------------------------------------------------------------
  85.     def refresh
  86.       contents.clear
  87.       @cleared = false
  88.       black  = Color.new(0,0,0,200) #Black Color
  89.       color1 = BAR1_COLOR
  90.       color2 = BAR2_COLOR
  91.       x = 2
  92.       y = 13
  93.       if $game_variables[BAR1_MAX_VAR] != 0 && $game_variables[BAR1_MAX_VAR] != 0
  94.         rate1 = ($game_variables[BAR1_VAR].to_f / [$game_variables[BAR1_MAX_VAR].to_f,0.01].max)
  95.         rate2 = ($game_variables[BAR2_VAR].to_f / [$game_variables[BAR2_MAX_VAR].to_f,1].max)
  96.       else
  97.         rate1 = 0 if $game_variables[BAR1_MAX_VAR] == 0
  98.         rate2 = 0 if $game_variables[BAR2_MAX_VAR] == 0
  99.       end
  100.       if $game_variables[BAR1_VAR] > $game_variables[BAR1_MAX_VAR]
  101.         $game_variables[BAR1_VAR] = $game_variables[BAR1_MAX_VAR]
  102.         rate1 = 1.0
  103.       end
  104.       if $game_variables[BAR2_VAR] > $game_variables[BAR2_MAX_VAR]
  105.         $game_variables[BAR2_VAR] = $game_variables[BAR2_MAX_VAR]
  106.         rate2 = 1.0
  107.       end
  108.       #Draw Bolder
  109.         contents.fill_rect(x,y,130,5,black)
  110.         contents.fill_rect(x,y+5,130,5,black)
  111.       #Draw Bars
  112.         contents.fill_rect(x+1,y+1,rate1*128,5-2,color1)
  113.         contents.fill_rect(x+1,y+1+5,rate2*128,5-2,color2)
  114.       #Draw Texts
  115.         contents.font.size = 15
  116.         contents.font.bold = true
  117.         percent_1 = sprintf("%2d%",rate1*100.to_i)
  118.         x_off = real_st_size(percent_1)
  119.         draw_text(x+128-x_off,y-17,170,line_height,percent_1)
  120.         draw_text(x,y-17,170,line_height,BAR1_TEXT.upcase)
  121.         percent_2 = sprintf("%2d%",rate2*100.to_i)
  122.         x_off = real_st_size(percent_2)
  123.         draw_text(x+128-x_off,y+7.5*2-5*2+1,170,line_height,percent_2)
  124.         draw_text(x,y+7.5*2-5*2+1,170,line_height,BAR2_TEXT.upcase)
  125.       end
  126.     #-------------------------------------------------------------------------
  127.     # * Get String Width
  128.     #-------------------------------------------------------------------------
  129.     def real_st_size(st)
  130.       size = 0
  131.       for i in 0..(st.size-1)
  132.         size += contents.text_size(st[i]).width
  133.       end
  134.       return size
  135.     end
  136.   end
  137.  
  138.   class Scene_ItemBase
  139.     alias :dark_survival_hud_scene_itembase_useitem :use_item
  140.     def use_item
  141.       notes = item.note
  142.       notes.split(/[\r\n]+/).each do |line|
  143.         if line =~ REGEX_ADD_ENERGY_VAR
  144.           $game_variables[BAR1_VAR] += $1.to_i
  145.         end
  146.         if line =~ REGEX_ADD_PERCENT_ENERGY_VAR
  147.           value = ($1.to_f / 100)*$game_variables[BAR1_MAX_VAR]
  148.           $game_variables[BAR1_VAR] += value
  149.         end
  150.         if line =~ REGEX_ADD_HYDRATION_VAR
  151.           $game_variables[BAR2_VAR] += $1.to_i
  152.         end
  153.         if line =~ REGEX_ADD_PERCENT_HYDRA_VAR
  154.           value = ($1.to_f / 100)*$game_variables[BAR2_MAX_VAR]
  155.           $game_variables[BAR2_VAR] += value
  156.         end
  157.       end
  158.       dark_survival_hud_scene_itembase_useitem
  159.     end
  160.   end
Advertisement
Add Comment
Please, Sign In to add comment