Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # ** Cooldowns
- # Author: Eshra
- # Release Date: 6 Nov. 2012
- # Compatibility: RPG Maker VX Ace
- # Dependencies: (~^_^)~Hotkeys v0.1
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- # About:
- #
- # This script is an add-on for the hotkeys script I wrote. It allows items
- # and skills to be tagged with cooldowns to prevent them from being used
- # again immediately.
- #
- #------------------------------------------------------------------------------
- # * How to Use
- #------------------------------------------------------------------------------
- #
- # These notetags are supported:
- #
- # <cooldown VALUE>
- # gives an item or skill a cooldown period in frames
- #
- # <global cooldown VALUE>
- # gives an item a global cooldown, given in frames. (no skills or items can be
- # used while the global cooldown is active)
- #
- # <duration VALUE>
- # Can be used to specify how long a skill/item will be active (for scripted
- # skills/items only currently).
- #
- # - Replace VALUE in the above notetags with an integer -
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Original Release Date: 6 Nov. 2012
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Update Log
- # 6 Nov. 2012 - Decided to release without fixing the f12 problem.
- #
- # 23 Aug. 2012 - Finished first working version
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Author Notes:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # I still have not fixed the problem when using f12 to reset the game. I have
- # no idea how f12 actually works, it looks like it just calls SceneManager.run
- # but somehow all of the graphics are cleaned up.
- # Once I understand what f12 is doing I will fix this issue.
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Terms of Use
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Free to use as you please. Please respect the header though so the dates can
- # be preserved.
- #------------------------------------------------------------------------------
- ($imported||={})["(~^_^)~Cooldowns"] = 0.1
- module COOLDOWNS
- module USE_FAILED
- SOUND = 3 # Default Buzzer
- end
- module REGEXP
- TAG = /<(?:!|)cooldown\s*(\d+)>/i
- GLOBAL = /<(?:!|)global cooldown\s*(\d+)>/i
- end
- end
- module DURATION
- module REGEXP
- TAG = /<(?:!|)duration\s*(\d+)>/i
- end
- module NAME
- TAG = /<(?:!|)ts-name = (\w+)(?:\s|)\[T(\d+)\]>/i
- end
- end
- #==============================================================================
- # ** DataManager
- #==============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # alias method: load_database
- #--------------------------------------------------------------------------
- class <<self; alias load_dtbase_mp_cd_ntags load_database; end
- def self.load_database
- load_dtbase_mp_cd_ntags
- load_map_cd_notetags
- end
- #--------------------------------------------------------------------------
- # new method: load_notetags_abe
- #--------------------------------------------------------------------------
- def self.load_map_cd_notetags
- groups = [$data_armors, $data_weapons, $data_items, $data_skills]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_sc_map_cd_notetags
- end
- end
- end
- end # DataManager
- #==============================================================================
- # ** RPG::UsableItem
- #==============================================================================
- class RPG::UsableItem < RPG::BaseItem
- attr_accessor :cooldown_timer
- attr_accessor :base_cooldown
- attr_accessor :duration_timer
- attr_accessor :base_duration
- attr_accessor :global_cooldown
- def load_sc_map_cd_notetags
- @cooldown_timer = 0
- @base_cooldown = 0
- @duration_timer = 0
- @base_duration = 0
- @global_cooldown = 0
- self.note.split(/[\r\n]+/).each { |line|
- next unless line != nil
- case line
- when COOLDOWNS::REGEXP::TAG
- @base_cooldown = $1.to_i
- when DURATION::REGEXP::TAG
- @base_duration = $1.to_i
- when COOLDOWNS::REGEXP::GLOBAL
- @global_cooldown = $1.to_i
- #print "loaded global cool = #{@global_cooldown}\n"
- end # End - case line
- } # End - self.note.split
- end # End - load_sc_map_cd_notetagss
- end # End - RPG::UsableItem
- #==============================================================================
- # ** RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- attr_accessor :name
- end
- #==============================================================================
- # ** RPG::EquipItem
- #==============================================================================
- class RPG::EquipItem < RPG::BaseItem
- attr_accessor :cooldown_timer
- attr_accessor :base_cooldown
- attr_accessor :duration_timer
- attr_accessor :base_duration
- attr_accessor :global_cooldown
- def load_sc_map_cd_notetags
- @cooldown_timer = 0
- @base_cooldown = 0
- @duration_timer = 0
- @base_duration = 0
- @global_cooldown = 0
- self.note.split(/[\r\n]+/).each { |line|
- next unless line != nil
- case line
- when COOLDOWNS::REGEXP::TAG
- @base_cooldown = $1.to_i
- when DURATION::REGEXP::TAG
- @base_duration = $1.to_i
- when COOLDOWNS::REGEXP::GLOBAL
- @global_cooldown = $1.to_i
- end # End - case line
- } # End - self.note.split
- end # End - load_sc_map_cd_notetagss
- end # End - RPG::EquipItem
- #==============================================================================
- # ** Game_Map
- #==============================================================================
- class Game_Map
- attr_accessor :cooldown_queue # Items on cd are placed here
- attr_accessor :duration_queue # Items that last over time are place here
- attr_accessor :global_cooldown
- attr_accessor :global_cooldown_base
- #
- # ** Alias method initialize
- #
- alias gme_map_cool_down_ch_initialize initialize
- def initialize
- gme_map_cool_down_ch_initialize
- @cooldown_queue = []
- @duration_queue = []
- @global_cooldown = 0
- @global_cooldown_base = 0
- end # End - initialize
- #
- # ** Alias method update
- #
- alias gme_map_cool_down_ch_update_9817 update
- def update(*arg)
- gme_map_cool_down_ch_update_9817(*arg)
- @global_cooldown -= 1 if @global_cooldown > 0
- #print "global_cooldown remaining: #{global_cooldown}\n"
- #print "cooldown_queue = #{@cooldown_queue.inspect}\n"
- @cooldown_queue.each{ |item|
- item.cooldown_timer-=1
- #print "cooldown left on #{item}: #{item.cooldown_timer}\n"
- if(item.cooldown_timer <= 0)
- @cooldown_queue.delete(item)
- end
- } # End - @cooldown_queue.each
- @duration_queue.each{ |item|
- item.duration_timer-=1
- #print "duration left on #{item}: #{item.duration_timer}\n"
- if(item.duration_timer <= 0)
- @duration_queue.delete(item)
- end
- } # End - @duration_queue.each
- end # End - update
- # Store all the cooldown data for the item.
- def init_cooldown_timers(item)
- item.cooldown_timer = item.base_cooldown
- item.duration_timer = item.base_duration
- #print "init cooldown_timer, item gcd = #{item.global_cooldown}\n"
- if @global_cooldown < item.global_cooldown
- @global_cooldown = item.global_cooldown
- @global_cooldown_base = item.global_cooldown
- end
- @cooldown_queue.push(item) unless @cooldown_queue.include?(item)
- @duration_queue.push(item) unless @duration_queue.include?(item)
- end
- def game_timer_skills
- @@game_timer_skills
- end
- # Check if there is a global cooldown
- def all_cd?
- #print "on gcd = ", @global_cooldown > 0, "\n"
- return @global_cooldown > 0
- end
- def gcd_val(mod = 0)
- @global_cooldown + mod
- end
- def gcd_base(mod = 0)
- @global_cooldown_base + mod
- end
- end # End - Scene_Map
- #==============================================================================
- # ** Aliased use_item methods in various classes: **
- #==============================================================================
- class Scene_ItemBase < Scene_MenuBase
- alias item_usable_check_for_cd_4289_use_item use_item
- def use_item
- if item.cooldown_timer > 0 || $game_map.all_cd?
- Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- return
- end
- #print "on global cooldown? #{$game_map.all_cd?}\n"
- item_usable_check_for_cd_4289_use_item
- $game_map.init_cooldown_timers(item)
- end # End - use_item
- end # End - Scene_ItemBase
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- alias item_usable_check_for_cd_4285_use_item use_item
- def use_item(item)
- #print "cooldown_timer: #{item.cooldown_timer}"
- if item.cooldown_timer > 0 || $game_map.all_cd?
- Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
- return
- end
- item_usable_check_for_cd_4285_use_item(item)
- $game_map.init_cooldown_timers(item)
- end # End - use_item
- end # End - Game_Battler
- # End of File
Advertisement
Add Comment
Please, Sign In to add comment