Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # ╔══════════════════════════════════╗
- # ║ ▼ Dark's Survival Hud ║
- # ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
- # ║ ▼ Release Date: March 14th 2016 ║
- # ║ ▼ Forum: TaoTroChoi.com ║
- # ╚══════════════════════════════════╝
- #-------------------------------------------------------------------------------
- # Version 1.0: Release!
- # Version 1.1: Add new function!
- #-------------------------------------------------------------------------------
- # Writen for mr.rpg.700.
- #-------------------------------------------------------------------------------
- # Notetag: [Items]
- # <dark_hud_energy_add: x> Tăng giá trị của Energy thêm x.
- # <dark_hud_energy_add_percent: x> Tăng giá trị của Energy thêm x%.
- # <dark_hud_hydra_add: x> Tăng giá trị của Hydration thêm x.
- # <dark_hud_hydra_add_percent: x> Tăng giá trị của Hydration thêm x%.
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["DRKS-Survival_Hud"] = true
- module DRKS_HUD
- HUD_X = -10
- HUD_Y = -10
- BAR1_TEXT = "Energy"
- BAR2_TEXT = "Hydration"
- BAR1_COLOR = Color.new(238,182,0)
- BAR2_COLOR = Color.new(0,166,238)
- HUD_SWITCH = 5 # Switch bật tắt HUD
- BAR1_VAR = 5 # VAR ID value của thanh 1
- BAR2_VAR = 6 # VAR ID value của thanh 2
- BAR1_MAX_VAR = 7 # VAR ID max value chỉ số của thanh 1.
- BAR2_MAX_VAR = 8 # VAR ID max value chỉ số của thanh 2.
- #--------------------------------------------------------
- REGEX_ADD_ENERGY_VAR = /<dark_hud_energy_add:\s*(\w+)>/i
- REGEX_ADD_PERCENT_ENERGY_VAR = /<dark_hud_energy_add_percent:\s*(\w+)>/i
- REGEX_ADD_PERCENT_HYDRA_VAR = /<dark_hud_hydra_add_percent:\s*(\w+)>/i
- REGEX_ADD_HYDRATION_VAR = /<dark_hud_hydra_add:\s*(\w+)>/i
- end
- include DRKS_HUD
- class Scene_Map < Scene_Base
- alias dark_survivalhud_start_scene_map start
- alias dark_survivalhud_update_scene_map update
- def start
- dark_survivalhud_start_scene_map
- @window_drks_survival_hud = DRKS_SurvivalHud.new(HUD_X,HUD_Y)
- end
- def update
- dark_survivalhud_update_scene_map
- if $game_switches[HUD_SWITCH] == true
- @window_drks_survival_hud.refresh
- else
- @window_drks_survival_hud.clear_hud if !@window_drks_survival_hud.hud_cleared?
- end
- end
- end
- class DRKS_SurvivalHud < Window_Base
- include DRKS_HUD
- #-------------------------------------------------------------------------
- # * Initialize
- #-------------------------------------------------------------------------
- def initialize(x,y)
- super(x,y,190,80)
- self.opacity = 0
- self.back_opacity = 0
- @cleared = false
- end
- #-------------------------------------------------------------------------
- # * Clear?
- #-------------------------------------------------------------------------
- def hud_cleared?
- @cleared
- end
- #-------------------------------------------------------------------------
- # * Clear Hud
- #-------------------------------------------------------------------------
- def clear_hud
- contents.clear
- @cleared = true
- end
- #-------------------------------------------------------------------------
- # * Refresh
- #-------------------------------------------------------------------------
- def refresh
- contents.clear
- @cleared = false
- black = Color.new(0,0,0,200) #Black Color
- color1 = BAR1_COLOR
- color2 = BAR2_COLOR
- x = 2
- y = 13
- if $game_variables[BAR1_MAX_VAR] != 0 && $game_variables[BAR1_MAX_VAR] != 0
- rate1 = ($game_variables[BAR1_VAR].to_f / [$game_variables[BAR1_MAX_VAR].to_f,0.01].max)
- rate2 = ($game_variables[BAR2_VAR].to_f / [$game_variables[BAR2_MAX_VAR].to_f,1].max)
- else
- rate1 = 0 if $game_variables[BAR1_MAX_VAR] == 0
- rate2 = 0 if $game_variables[BAR2_MAX_VAR] == 0
- end
- if $game_variables[BAR1_VAR] > $game_variables[BAR1_MAX_VAR]
- $game_variables[BAR1_VAR] = $game_variables[BAR1_MAX_VAR]
- rate1 = 1.0
- end
- if $game_variables[BAR2_VAR] > $game_variables[BAR2_MAX_VAR]
- $game_variables[BAR2_VAR] = $game_variables[BAR2_MAX_VAR]
- rate2 = 1.0
- end
- #Draw Bolder
- contents.fill_rect(x,y,130,5,black)
- contents.fill_rect(x,y+5,130,5,black)
- #Draw Bars
- contents.fill_rect(x+1,y+1,rate1*128,5-2,color1)
- contents.fill_rect(x+1,y+1+5,rate2*128,5-2,color2)
- #Draw Texts
- contents.font.size = 15
- contents.font.bold = true
- percent_1 = sprintf("%2d%",rate1*100.to_i)
- x_off = real_st_size(percent_1)
- draw_text(x+128-x_off,y-17,170,line_height,percent_1)
- draw_text(x,y-17,170,line_height,BAR1_TEXT.upcase)
- percent_2 = sprintf("%2d%",rate2*100.to_i)
- x_off = real_st_size(percent_2)
- draw_text(x+128-x_off,y+7.5*2-5*2+1,170,line_height,percent_2)
- draw_text(x,y+7.5*2-5*2+1,170,line_height,BAR2_TEXT.upcase)
- end
- #-------------------------------------------------------------------------
- # * Get String Width
- #-------------------------------------------------------------------------
- def real_st_size(st)
- size = 0
- for i in 0..(st.size-1)
- size += contents.text_size(st[i]).width
- end
- return size
- end
- end
- class Scene_ItemBase
- alias :dark_survival_hud_scene_itembase_useitem :use_item
- def use_item
- notes = item.note
- notes.split(/[\r\n]+/).each do |line|
- if line =~ REGEX_ADD_ENERGY_VAR
- $game_variables[BAR1_VAR] += $1.to_i
- end
- if line =~ REGEX_ADD_PERCENT_ENERGY_VAR
- value = ($1.to_f / 100)*$game_variables[BAR1_MAX_VAR]
- $game_variables[BAR1_VAR] += value
- end
- if line =~ REGEX_ADD_HYDRATION_VAR
- $game_variables[BAR2_VAR] += $1.to_i
- end
- if line =~ REGEX_ADD_PERCENT_HYDRA_VAR
- value = ($1.to_f / 100)*$game_variables[BAR2_MAX_VAR]
- $game_variables[BAR2_VAR] += value
- end
- end
- dark_survival_hud_scene_itembase_useitem
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment