Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. =begin
  2.  
  3.   Script Name:    Timer
  4.   Author:         Tajiin
  5.   Release Date:   02/18/2014 | mm/dd/yyyy
  6.  
  7.   Version: 3.0
  8.   Versions Date: 05/24/2015
  9.  
  10.   Description:
  11.     With this script you can add timers that will count a specific time in
  12.     the background.
  13.    
  14.   Script-Commands(Event > 3 > Script...):
  15.  
  16.     $game_system.timer.set(i, t)
  17.    
  18.       - Creates a timer
  19.       - i: is the index for the timer thatt'll be created
  20.       - t: is the index for the timer will count (in seconds)
  21.      
  22.      
  23.     $game_system.timer.check(i)
  24.    
  25.       - tests if the timer is already done
  26.       - i: is the index for the timer that'll be tested
  27.      
  28.      
  29.     $game_system.timer.get(i, v)
  30.    
  31.       - gives you the value from a timer. (in seconds)
  32.       - i: is the index for the timer with the value you'll get
  33.      
  34.      
  35.     $game_system.timer.stop(i)
  36.      
  37.       - stops a timer
  38.       - i: is the index for the timer that will be stopped
  39.      
  40.      
  41.     $game_system.timer.start(i)
  42.    
  43.       - starts a stopped timer
  44.       - i: is the index for the timer that will be restarted
  45.      
  46.      
  47.     $game_system.timer.stopped?(i)
  48.      
  49.       - tests if a timer is stopped or not (True = stopped;
  50.         False = not stopped)
  51.       - i: is the index for the timer that'll be tested
  52.    
  53.   Have Fun
  54.  
  55.   SORRY FOR MY BAD ENGLISH SKILLS
  56.  
  57. =end
  58. #==============================================================================
  59. # ** DataManager
  60. #------------------------------------------------------------------------------
  61. #  This module manages the database and game objects. Almost all of the
  62. # global variables used by the game are initialized by this module.
  63. #==============================================================================
  64. module DataManager
  65.   class << self
  66.     alias taj_datamanager_creategameobjects_ijabsdi96     create_game_objects
  67.     #--------------------------------------------------------------------------
  68.     # * Create Game Objects
  69.     #--------------------------------------------------------------------------
  70.     def create_game_objects
  71.       taj_datamanager_creategameobjects_ijabsdi96
  72.       $game_system.timer     = Timer.new
  73.     end
  74.   end
  75. end
  76. #==============================================================================
  77. # ** Game_System
  78. #------------------------------------------------------------------------------
  79. #  This class handles system data. It saves the disable state of saving and
  80. # menus. Instances of this class are referenced by $game_system.
  81. #==============================================================================
  82.  
  83. class Game_System
  84.   #--------------------------------------------------------------------------
  85.   # * Public Instance Variables
  86.   #--------------------------------------------------------------------------
  87.   attr_accessor     :timer
  88. end
  89. #==============================================================================
  90. # ** Game_Timer
  91. #------------------------------------------------------------------------------
  92. #  This class handles timers. Instances of this class are referenced by
  93. # $game_timer.
  94. #==============================================================================
  95.  
  96. class Game_Timer
  97.   alias taj_gametimer_update_dd128      update
  98.   #--------------------------------------------------------------------------
  99.   # * Frame Update
  100.   #--------------------------------------------------------------------------
  101.   def update
  102.     taj_gametimer_update_dd128
  103.     $game_system.timer.update
  104.   end
  105. end
  106.  
  107. $imported = {} if $imported.nil?
  108. $imported["Taj_Game_TimerCore"] = true
  109.  
  110. class Timer
  111.   #--------------------------------------------------------------------------
  112.   # * Public Instance Variables
  113.   #--------------------------------------------------------------------------
  114.   attr_accessor   :timer
  115.   #--------------------------------------------------------------------------
  116.   # * Object Initialization
  117.   #--------------------------------------------------------------------------
  118.   def initialize
  119.     @timer = Array.new()
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # * Set the timer
  123.   #--------------------------------------------------------------------------
  124.   def set(index, frames)
  125.     @timer[index] = Array.new
  126.     @timer[index][0] = frames*60
  127.     @timer[index][1] = false
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # * Set the timer
  131.   #--------------------------------------------------------------------------
  132.   def get(index, variable)
  133.     if !@timer[index].nil?
  134.       $game_variables[variable] = (@timer[index][0] / 60).round
  135.     else
  136.       msgbox_p("Error: TIMER DONT EXIST! #Index: "  + index.to_s)
  137.       SceneManager.exit
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Stops a Timer
  142.   #--------------------------------------------------------------------------
  143.   def stop(index)
  144.     if !@timer[index].nil?
  145.       if !@timer[index][1]
  146.         @timer[index][1] = true
  147.       else
  148.         msgbox_p("Error: TIMER IS ALREADY STOPPED! #Index: "  + index.to_s)
  149.         SceneManager.exit
  150.       end
  151.     else
  152.       msgbox_p("Error: TIMER DONT EXIST! #Index: "  + index.to_s)
  153.       SceneManager.exit
  154.     end
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # * Stops a Timer
  158.   #--------------------------------------------------------------------------
  159.   def start(index)
  160.     if !@timer[index].nil?
  161.       if @timer[index][1]
  162.         @timer[index][1] = false
  163.       else
  164.         msgbox_p("Error: TIMER ISNT STOPPED! #Index: "  + index.to_s)
  165.         SceneManager.exit
  166.       end
  167.     else
  168.       msgbox_p("Error: TIMER DONT EXIST! #Index: "  + index.to_s)
  169.       SceneManager.exit
  170.     end
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # * Frame Update
  174.   #--------------------------------------------------------------------------
  175.   def update
  176.     if @timer != Array.new
  177.       @timer.each_with_index do |t, i|
  178.         if !t.nil?
  179.           if !@timer[i][1]
  180.             @timer[i][0] -= 1 unless t[0] == 0
  181.             @timer[i][0] == nil if t[0] == 0
  182.           end
  183.         end
  184.       end
  185.     end
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # * Returns true if a Timer is Stopped
  189.   #--------------------------------------------------------------------------
  190.   def stopped?(index)
  191.     return @timer[index][1] if !@timer[index].nil?
  192.     msgbox_p("Error: TIMER DONT EXIST! #Index: "  + index.to_s)
  193.     SceneManager.exit
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Check if Timer is ended
  197.   #--------------------------------------------------------------------------
  198.   def check(index)
  199.     if !@timer[index].nil?
  200.       return true if @timer[index][0] == 0
  201.       return false
  202.     else
  203.       msgbox_p("Error: TIMER DONT EXIST! #Index: "  + index.to_s)
  204.       SceneManager.exit
  205.     end
  206.   end
  207. end