Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # * [ACE] Timer HUD EX
- #===============================================================================
- # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
- # * Version: 1.1
- # * Updated: 10/07/2015
- # * Requires: Sixth's Picture Number Drawing
- #-------------------------------------------------------------------------------
- # * < Change Log >
- #-------------------------------------------------------------------------------
- # * Version 1.0 (10/07/2015)
- # - Initial release.
- # * Version 1.1 (10/07/2015)
- # - Fixed the disposal of the timer pictures when changing scenes.
- # - The animated picture's refresh rate setting is now properly implemented.
- #-------------------------------------------------------------------------------
- # * < Description >
- #-------------------------------------------------------------------------------
- # * This script changes the default timer class heavily!
- # * New functions:
- # - Decreasing and increasing timer too!
- # - Pause/resume the timer anytime you want!
- # - Add/remove time from the counter anytime you want!
- # - Automatically call a common event when the timer is stopped/expired!
- # - Made the "Abort Battle" an optional thing only upon expire!
- # - Hide the timer anytime with a switch or with a simple button press!
- # * Visual updates:
- # - The numbers are displayed with pictures from now on!
- # (This is why this requires my Picture Number Drawing script.)
- # - Add a background for your timers!
- # - Add a gauge for your timers!
- # - Add an animated picture which follows the timer gauge automatically!
- # - Change any visuals whenever you want during the game too!
- #-------------------------------------------------------------------------------
- # * < Usage Information >
- #-------------------------------------------------------------------------------
- # * This script uses a custom made folder setup to get the location of the
- # pictures used. All images used must be in that folder!
- # You can set the folder location with the 'ImgFolder' setting!
- #-------------------------------------------------------------------------------
- # * < Script Calls >
- #-------------------------------------------------------------------------------
- # * To change any visual properties of the timer (such as change the images used,
- # their position, Z value or opacity), you can use the following script call:
- #
- # timer_pic(img_sym,prop,val)
- #
- # img_sym = The symbol of the image from the 'Pics' settings.
- # Can be: :fill, :spark, :back, :nums
- # Read more about what each of them does in the settings explanation!
- # prop = The property symbol from the image's settings.
- # You can use the same symbols used in the 'Pics' settings. These are
- # image specific symbols, so not every symbol used works for all of the
- # images (for example, the :nums "image" got no :img setting, so the
- # :img symbol can not be used on that image in the script call)!
- # val = The new value for the visual setting. This takes the same format as
- # the property symbol you entered uses in their settings below!
- #
- # Examples:
- #
- # timer_pic(:fill,:img,"timerfillv3b")
- # This would change the image used for the timer's gauge to the "timerfillv3b"
- # image found in the timer HUD folder.
- #
- # timer_pic(:spark,:frames,[0,1,2,3,2,1])
- # This would change the animation frames for the animated picture.
- #
- # timer_pic(:nums,:style,["timer_nums1",2])
- # This would change the number drawing style of the timer.
- #
- # NOTE:
- # Any changes made will only be visible after the next timer is started if
- # a timer is already running! The only exception is the number drawing style,
- # which can be changed anytime, and will be visible immediately!
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To change the stop/expire effects of the timer, you can use the following
- # script call:
- #
- # timer_eff(eff,prop,val)
- #
- # eff = The symbol of the effect to be changed.
- # Can be :stop or :expire. It should be obvious what this does.
- # prop = Just as for the visual settings, you can use any setting symbol here
- # from the 'TimerEffects' settings.
- # val = The new value for the setting. Takes the same format as the property
- # symbol you entered uses in the 'TimerEffects' settings!
- #
- # Examples:
- #
- # timer_eff(:stop,:event,24)
- # This would change the common event called when the timer is stopped.
- #
- # timer_eff(:expire,:abort_battle,true)
- # This would enable the "Abort_Battle" function, so whenever the timer expires,
- # and the party is in a battle, the battle will be aborted automatically.
- # I have set this to false by default in the settings below, since you can now
- # event whatever you want in your common events, which is way more flexible
- # than an auto-abort function. You can still enable it if you want thou.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To change the type of the timer, use the following script call:
- #
- # timer_type(type)
- #
- # type = The type of the timer. Can be :dec or :inc.
- # :dec is the default behaviour, so the timer will decrease due time,
- # while :inc will make the timer increase due time.
- # Note that you can change this even when a timer is already running!
- #
- # Examples: timer_type(:dec) *or* timer_type(:inc)
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To pause/resume the timer at any time, you can use the following
- # script calls:
- #
- # timer_pause *or* timer_resume
- #
- # Okay, this can't be more obvious, so I won't explain anything here. :P
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # * To increase or decrease the timer's counter manually, you can use the
- # following script call:
- #
- # timer_count(val)
- #
- # val = The value to be added for the counter.
- # You can use any integer numbers.
- # Use negative numbers to decrease the counter!
- #
- # NOTE:
- # Remember that the timer uses frames and NOT seconds, so if you add 120 to
- # the timer, you will add 120 frames to it, which is 2 seconds!
- # Keep this in mind when manipulating the timer!
- #
- # Examples: timer_count(400), timer_count(-360)
- #-------------------------------------------------------------------------------
- # * < Installation >
- #-------------------------------------------------------------------------------
- # * Place this script below Materials but above Main!
- #-------------------------------------------------------------------------------
- # * < Compatibility Info >
- #-------------------------------------------------------------------------------
- # * No known incompatibilities, but I suspect there can be some issues with
- # other scripts changing the timer's functions/visuals.
- # * I heavily changed the Game_Timer and Sprite_Timer classes.
- # * Also removed the default initialization of the timer sprite completely,
- # so from now on, the timer sprites are only initialized when they are really
- # needed, and they are disposed correctly when they are not needed anymore!
- # * Overwritten methods:
- # - In the Spriteset_Map/Spriteset_Battle classes:
- # ~ create_timer, ~ dispose_timer, ~ update_timer
- # - In the Game_Timer class:
- # ~ start, ~ update
- # - In the Sprite_Timer class:
- # ~ initialize, ~ redraw, ~ update
- # * Aliased methods:
- # - In the Game_Timer class:
- # ~ initialize, ~ stop, ~ on_expire
- #-------------------------------------------------------------------------------
- # * < Known Issues >
- #-------------------------------------------------------------------------------
- # * No known issues.
- #-------------------------------------------------------------------------------
- # * < Terms of Use >
- #-------------------------------------------------------------------------------
- # * Free to use for whatever purposes you want.
- # * Credit me (Sixth) in your game, pretty please! :P
- # * Posting modified versions of this script is allowed as long as you notice me
- # about it with a link to it!
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["SixthTimerHUD"] = true
- #===============================================================================
- # Settings:
- #===============================================================================
- module TimerHUD
- #-----------------------------------------------------------------------------
- # Image Folder Settings:
- #-----------------------------------------------------------------------------
- # Set up a custom folder where your timer HUD pictures will be read from.
- # All pictures used must be in this folder!
- #-----------------------------------------------------------------------------
- ImgFolder = "Graphics/TimerHUD/"
- #-----------------------------------------------------------------------------
- # Switch Settings:
- #-----------------------------------------------------------------------------
- # Set up a switch used to toggle the visibility of the timer HUD.
- # Enter the ID of the switch used for this here.
- # You can use this, in case you want to hide the HUD for a cut-scene, etc.
- #-----------------------------------------------------------------------------
- ToggleSw = 99
- #-----------------------------------------------------------------------------
- # Button Settings:
- #-----------------------------------------------------------------------------
- # Set up a button to be used for toggling the timer HUD anytime during the
- # game. Players can toggle the visibility with this button anytime they want,
- # except when an event is running, so they can't turn the HUD on if you
- # turned it off for a reason (like for a cut-scene).
- # Set it to nil if you want to disable this function!
- #-----------------------------------------------------------------------------
- ToggleButton = :L
- #-----------------------------------------------------------------------------
- # Visual Settings:
- #-----------------------------------------------------------------------------
- # Set up all of the visuals for the timer HUD here!
- #
- # Four images are used (well, one is not really a visible image):
- # :fill = This is the gauge which will be used for the timer.
- # :spark = This is the animated picture used which will follow the gauge
- # automatically. I named it this way, becaue I use this as an
- # animated spark for a burning rope, which is connected to a bomb.
- # Looks kinda cool! :D
- # :back = This is the background image used for the timer.
- # :nums = This is an invisible sprite for the numeric display of the timer.
- #
- # For all of these, some settings are the same, and these are:
- # :img = The image file name which will be used.
- # The :nums settings don't have this!
- # Setting this to nil will disable the image type!
- # :pos = The X and Y position of the image in an array.
- # Format: :pos => [x,y],
- # In the case of the :spark settings', depending on which gauge type
- # you have set for the :fill settings, either the X or the Y position
- # will not matter. If the gauge is horizontal, the X position will
- # be set automatically, if the gauge is vertical, the Y position will
- # be set automatically, so it will follow the gauge in both cases.
- # Also it is relative to the pictures' top left corner, except for
- # the :spark image! The :spark image's :pos settings are relative to
- # the image's center and NOT it's top left corner!
- # :opa = The opacity level of the image. Valid values: 0 - 255.
- # :z = The Z value of the image.
- #
- # The rest of the settings are image specific settings, so only one type got
- # them!
- #
- # Gauge specific settings (for the :fill settings):
- # :type = The type of the gauge.
- # Can be :horz (horizontal) or :vert (vertical).
- #
- # Animated picture specific settings (for the :spark settings):
- # :frames = The animation frame sequence used for the animation.
- # The picture used must be a vertical image sheet.
- # It can be any sized, and can contain as many aniimation frames
- # as you want!
- # The top frame's index is 0, the one below is 1, and so on.
- # Use these indexes to make your animation sequence.
- # You can re-use any frames as many times as you want!
- # Once the sequence is finished, the animation starts from the
- # beginning.
- # :rows = The number of frame pictures (rows) on your image sheet.
- # :rate = The refresh rate of the animation. The lower the number, the
- # quicker the animation frames will change, resulting in a smoother
- # animation! Use only positive integer numbers!
- #
- # Number display specific settings (for the :nums settings):
- # :pos2 = The X and Y position of the numbers drawn inside of the sprite.
- # Format is the same as for the regular :pos settings!
- # :size = The size of the invisible sprite where the numbers are drawn.
- # Format: :size => [width,height],
- # Depending on your number drawing style used, you might need to set
- # this to bigger or smaller values, so that your numbers would fit
- # inside the sprite where they are drawn.
- # :style = The drawing style used for the numbers.
- # Format: :style => ["img_name",row],
- # Read more about setting number drawing styles in my
- # Picture Number Drawing script!
- # :align = The alignment used for the number drawing.
- # 0 = left, 1 = middle, 2 = right.
- # Read more about setting number drawing alignment in my
- # Picture Number Drawing script!
- #-----------------------------------------------------------------------------
- Pics = { # <-- No touchy-touchy!
- :fill => {
- :img => "ropehorzv1a", :type => :horz, :pos => [321,16],
- :opa => 240, :z => 30,
- },
- :spark => {
- :img => "sparksv1a", :pos => [45,22], :opa => 240, :z => 50,
- :frames => [0,1,2,1], :rows => 3,
- },
- :back => {
- :img => "dinamite2va", :pos => [244,2], :opa => 240, :z => 10,
- },
- :nums => {
- :pos => [196,13], :pos2 => [110,0], :size => [120,40], :opa => 240,
- :z => 20, :style => ["hpnums1va",0], :align => 2,
- },
- } # <-- No touchy-touchy!
- #-----------------------------------------------------------------------------
- # Effect Settings:
- #-----------------------------------------------------------------------------
- # Set up the effects to be triggered when the timer is stopped or expired here.
- # These effects will be executed automatically every single time the timer
- # stops/expires!
- #
- # Two kind of effects can be set up:
- # :stop = Effects set here are executed when the timer is stopped.
- # :expire = Effects set here are executed when the timer is expired.
- #
- # For both types, you can set a common event to be run automatically.
- # The settings for these are:
- # :event = Enter the common event's ID here you want to be executed.
- # You can set this to nil if you don't want any auto-event to be
- # triggered.
- # :chance = You can randomize these auto-effects, so that they are not
- # executed every single time. Enter the percentage of the event
- # to be triggered here. 10 means 10%, 50 means 50%, and so on.
- #
- # The expire type got two additional settings:
- # :abort_battle = This is the default "Abourt Battle" function, which would
- # be run every single time the timer expires in the battle,
- # with no way to turn it off! Well, now you can turn it off
- # or turn it on whenever you want!
- # If this is turned ON, it will be executed, regardless of
- # the :chance settings used!
- # :inc_effect = You can choose to disable the expire effect completely when
- # the timer is set to the incrementing type. If this is set to
- # false, the timer can't "expire" at all, so the expire
- # effects can't be run either. If this is set to true, when the
- # timer reaches the max amount, the expire effects will be
- # triggered. If the timer is set to the incrementing type, the
- # max amount is the amount you have set in the "Control Timer"
- # event command, and the timer will always start on 0.
- #
- # NOTE:
- # Any of these settings can be changed with the provided script calls during
- # the game, even if the timer is running!
- # The automatic common event function should be a giant help in timer
- # related eventing! Yay! :D
- #-----------------------------------------------------------------------------
- TimerEffects = { # <-- No touchy-touchy!
- :stop => {:event => 9, :chance => 100},
- :expire => {
- :event => 10, :chance => 100, :abort_battle => false, :inc_effect => false
- },
- } # <-- No touchy-touchy!
- end # <-- No touchy-touchy!
- #===============================================================================
- # End of settings! O.o
- # Don't look below, someone may find out!
- #===============================================================================
- module Cache
- def self.timerhud(filename)
- load_bitmap(TimerHUD::ImgFolder, filename)
- end
- end
- class Game_Interpreter
- def timer_pic(sym,prop,val)
- $game_timer.data[sym][prop] = val
- end
- def timer_eff(eff,prop,val)
- $game_timer.effs[eff][prop] = val
- end
- def timer_pause
- $game_timer.pause = true
- end
- def timer_resume
- $game_timer.pause = false
- end
- def timer_type(type)
- $game_timer.type = type
- end
- def timer_count(val)
- $game_timer.count += val
- end
- end
- class Spriteset_Map
- def create_timer
- if $game_timer.working?
- $game_timer.init_pics
- end
- # Removed! Well, almost! :D
- end
- def dispose_timer
- if $game_timer.working?
- $game_timer.dispose_em_pics
- end
- # Removed! Well, almost! :D
- end
- def update_timer
- # Removed!
- end
- end
- class Spriteset_Battle
- def create_timer
- if $game_timer.working?
- $game_timer.init_pics
- end
- # Removed! Well, almost! :D
- end
- def dispose_timer
- if $game_timer.working?
- $game_timer.dispose_em_pics
- end
- # Removed! Well, almost! :D
- end
- def update_timer
- # Removed!
- end
- end
- class Game_Timer
- attr_accessor :data, :effs, :pause, :type, :count
- alias add_newhud6522 initialize
- def initialize
- @data = TimerHUD::Pics
- @effs = TimerHUD::TimerEffects
- @pics = {}
- @pause = false
- @type = :dec
- add_newhud6522
- end
- def init_pics
- @data.each do |sym,data|
- next if sym != :nums && data[:img].nil?
- case sym
- when :fill
- rate = @count.to_f/@max
- case data[:type]
- when :vert
- @pics[sym] = TimerBar1.new(data[:pos][0],data[:pos][1],Cache.timerhud(data[:img]),rate)
- when :horz
- @pics[sym] = TimerBar2.new(data[:pos][0],data[:pos][1],Cache.timerhud(data[:img]),rate)
- end
- when :nums
- @pics[sym] = Sprite_Timer.new
- @pics[sym].bitmap = Bitmap.new(data[:size][0],data[:size][1])
- @pics[sym].update
- else
- @pics[sym] = Sprite.new
- @pics[sym].bitmap = Cache.timerhud(data[:img])
- end
- if sym != :fill
- if sym == :spark
- @pics[sym].src_rect.height = @pics[sym].bitmap.height/data[:rows]
- @pics[sym].ox = @pics[sym].bitmap.width/2
- @pics[sym].oy = @pics[sym].src_rect.height/2
- @prate = 0; @picid = 0
- @pframes = @data[:spark][:frames]
- end
- @pics[sym].x = data[:pos][0]
- @pics[sym].y = data[:pos][1]
- end
- @pics[sym].z = data[:z]
- @pics[sym].opacity = data[:opa]
- @pics[sym].visible = $game_switches[TimerHUD::ToggleSw]
- end
- if @pics != {} && !@pics[:spark].nil? && !@pics[:fill].nil?
- case @data[:fill][:type]
- when :vert
- if @pics[:spark].y != @pics[:fill].y
- @pics[:spark].y = @pics[:fill].y
- end
- when :horz
- if @pics[:spark].x != @pics[:fill].x + @pics[:fill].src_rect.width
- @pics[:spark].x = @pics[:fill].x + @pics[:fill].src_rect.width
- end
- end
- end
- end
- def start(count)
- if @type == :dec
- @count = count
- elsif @type == :inc
- @count = 0
- end
- @max = count
- @working = true
- @prate = 0
- dispose_em_pics if @pics != {}
- init_pics
- end
- alias get_rid6533 stop
- def stop
- get_rid6533
- dispose_em_pics if @pics != {}
- do_stop_effects
- end
- def fill_rate
- return [@count.to_f/@max,1.0].min
- end
- def update_pic_anim
- if @prate % @data[:spark][:rate] == 0
- @picid += 1
- patt = @pframes[@picid % @pframes.size]
- @pics[:spark].src_rect.y = patt*@pics[:spark].src_rect.height
- end
- end
- def pics_anim_update
- if @working && ((@type == :dec && @count > 0) || @type == :inc)
- @count -= 1 if !@pause && @type == :dec
- @count += 1 if !@pause && @type == :inc
- @prate += 1
- @pics[:fill].update if @pics != {} && !@pics[:fill].nil?
- @pics[:nums].update if @pics != {} && !@pics[:nums].nil?
- if @pics != {} && !@pics[:spark].nil? && !@pics[:fill].nil?
- case @data[:fill][:type]
- when :vert
- if @pics[:spark].y != @pics[:fill].y
- @pics[:spark].y = @pics[:fill].y
- end
- when :horz
- if @pics[:spark].x != @pics[:fill].x + @pics[:fill].src_rect.width
- @pics[:spark].x = @pics[:fill].x + @pics[:fill].src_rect.width
- end
- end
- end
- update_pic_anim if @pics != {} && !@pics[:spark].nil?
- on_expire if @count == 0 && @type == :dec
- on_expire if @count == @max && @type == :inc && @effs[:expire][:inc_effect]
- end
- end
- def update_pic_visibility
- @pics.each do |sym,sprite|
- sprite.visible = $game_switches[TimerHUD::ToggleSw]
- end
- end
- def update
- if Input.trigger?(TimerHUD::ToggleButton) &&
- !$game_map.interpreter.running?
- $game_switches[TimerHUD::ToggleSw] = !$game_switches[TimerHUD::ToggleSw]
- end
- if @pics != {} && @pics[:fill].visible != $game_switches[TimerHUD::ToggleSw]
- update_pic_visibility
- end
- pics_anim_update
- end
- def dispose_em_pics
- @pics.each do |sym,sprite|
- sprite.bitmap.dispose
- sprite.dispose
- end
- @pics = {}
- end
- alias get_rid_o_pics8643 on_expire
- def on_expire
- get_rid_o_pics8643 if @effs[:expire][:battle_abort]
- dispose_em_pics if @pics != {}
- do_expire_effects
- end
- def do_expire_effects
- if !@effs[:expire].nil? && !@effs[:expire][:event].nil? && @effs[:expire][:chance] >= rand(100)
- $game_temp.reserve_common_event(@effs[:expire][:event])
- end
- end
- def do_stop_effects
- if !@effs[:stop].nil? && !@effs[:stop][:event].nil? && @effs[:stop][:chance] >= rand(100)
- $game_temp.reserve_common_event(@effs[:stop][:event])
- end
- end
- end
- class Sprite_Timer < Sprite
- def initialize(viewport=nil)
- @data = $game_timer.data[:nums]
- super(viewport)
- end
- def redraw
- self.bitmap.clear
- self.bitmap.draw_numbers(@data[:pos2][0],@data[:pos2][1],timer_text,255,@data[:align])
- end
- def update_num_data
- if @data != $game_timer.data[:nums]
- @data = $game_timer.data[:nums]
- if self.bitmap.num_style != @data[:style]
- self.bitmap.num_style = @data[:style]
- end
- end
- end
- def update
- super
- update_num_data
- update_bitmap
- end
- end
- class TimerBar1 < Sprite_Base
- def initialize(x,y,pic,rate)
- super(nil)
- self.x = x; self.y = y
- @ori_y = self.y
- @rate = rate
- self.bitmap = pic
- src_rect.height = self.bitmap.height * @rate
- src_rect.y = self.bitmap.height - src_rect.height
- self.y = @ori_y + src_rect.y
- end
- def update
- super
- update_rate
- end
- def update_rate
- if @rate != $game_timer.fill_rate
- @rate = $game_timer.fill_rate
- update_fill_rate
- end
- end
- def update_fill_rate
- src_rect.height = self.bitmap.height * @rate
- src_rect.y = self.bitmap.height - src_rect.height
- self.y = @ori_y + src_rect.y
- end
- end
- class TimerBar2 < Sprite_Base
- def initialize(x,y,pic,rate)
- super(nil)
- self.x = x; self.y = y
- @rate = rate; @pic = pic
- self.bitmap = pic
- update_fill_rate
- end
- def update
- super
- update_rate
- end
- def update_rate
- if @rate != $game_timer.fill_rate
- @rate = $game_timer.fill_rate
- update_fill_rate
- end
- end
- def update_fill_rate
- src_rect.width = self.bitmap.width * @rate
- end
- end
- #==============================================================================
- # !!END OF SCRIPT - OHH, NOES!!
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement