Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. =begin
  2.  
  3.   Script Name:   Timer
  4.   Autor:         Tajiin
  5.   Datum:         18/02/2014 | tt/mm/jjjj
  6.  
  7.   Version: 3.0
  8.   Versions Datum: 24/05/2015
  9.  
  10.   Beschreibung:
  11.     Mit diesem Script kann man beliebig viele Timer erstellen.
  12.    
  13.   Script-Befehle(Event > 3 > Skript...):
  14.  
  15.     $game_system.timer.set(i, t)
  16.    
  17.       - Erstellt einen Timer.
  18.       - i: steht für den Index des Timers
  19.       - t: steht für die Zeit die der Timer herunterzählt. (in Sekunden)
  20.      
  21.      
  22.     $game_system.timer.check(i)
  23.    
  24.       - Testet ob der Timer bereits abgelaufen ist.
  25.       - i: steht für den Index des Timers der überprüft werden soll.
  26.      
  27.      
  28.     $game_system.timer.get(i, v)
  29.    
  30.       - Gibt euch den momentanen Wert eines Timers aus. (in Sekunden)
  31.       - i: steht für den Index des Timers dessen Wert ausgegeben werden soll.
  32.      
  33.      
  34.     $game_system.timer.stop(i)
  35.      
  36.       - Stoppt einen Timer
  37.       - i: steht für den Index des Timers der gestoppt werden soll.
  38.      
  39.      
  40.     $game_system.timer.start(i)
  41.    
  42.       - Startet einen gestoppten Timer
  43.       - i: steht für den Index des Timers der wieder gestartet werden soll.
  44.      
  45.      
  46.     $game_system.timer.stopped?(i)
  47.      
  48.       - Teste einen Timer ob er gestoppt ist oder nicht. (True = gestoppt;
  49.         False = nicht gestoppt)
  50.       - i: steht für den Index des Timers der getestet werden soll.
  51.    
  52.   Viel Spaß
  53.  
  54. =end
  55. #==============================================================================
  56. # ** DataManager
  57. #------------------------------------------------------------------------------
  58. #  This module manages the database and game objects. Almost all of the
  59. # global variables used by the game are initialized by this module.
  60. #==============================================================================
  61. module DataManager
  62.   class << self
  63.     alias taj_datamanager_creategameobjects_ijabsdi96     create_game_objects
  64.     #--------------------------------------------------------------------------
  65.     # * Create Game Objects
  66.     #--------------------------------------------------------------------------
  67.     def create_game_objects
  68.       taj_datamanager_creategameobjects_ijabsdi96
  69.       $game_system.timer     = Timer.new
  70.     end
  71.   end
  72. end
  73. #==============================================================================
  74. # ** Game_System
  75. #------------------------------------------------------------------------------
  76. #  This class handles system data. It saves the disable state of saving and
  77. # menus. Instances of this class are referenced by $game_system.
  78. #==============================================================================
  79.  
  80. class Game_System
  81.   #--------------------------------------------------------------------------
  82.   # * Public Instance Variables
  83.   #--------------------------------------------------------------------------
  84.   attr_accessor     :timer
  85. end
  86. #==============================================================================
  87. # ** Game_Timer
  88. #------------------------------------------------------------------------------
  89. #  This class handles timers. Instances of this class are referenced by
  90. # $game_timer.
  91. #==============================================================================
  92.  
  93. class Game_Timer
  94.   alias taj_gametimer_update_dd128      update
  95.   #--------------------------------------------------------------------------
  96.   # * Frame Update
  97.   #--------------------------------------------------------------------------
  98.   def update
  99.     taj_gametimer_update_dd128
  100.     $game_system.timer.update
  101.   end
  102. end
  103.  
  104. $imported = {} if $imported.nil?
  105. $imported["Taj_Game_TimerCore"] = true
  106.  
  107. class Timer
  108.   #--------------------------------------------------------------------------
  109.   # * Public Instance Variables
  110.   #--------------------------------------------------------------------------
  111.   attr_accessor   :timer
  112.   #--------------------------------------------------------------------------
  113.   # * Object Initialization
  114.   #--------------------------------------------------------------------------
  115.   def initialize
  116.     @timer = Array.new()
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Set the timer
  120.   #--------------------------------------------------------------------------
  121.   def set(index, frames)
  122.     @timer[index] = Array.new
  123.     @timer[index][0] = frames*60
  124.     @timer[index][1] = false
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * Set the timer
  128.   #--------------------------------------------------------------------------
  129.   def get(index, variable)
  130.     if !@timer[index].nil?
  131.       $game_variables[variable] = (@timer[index][0] / 60).round
  132.     else
  133.       msgbox_p("Error: TIMER EXITIERT NICHT! Index: "  + index.to_s)
  134.       SceneManager.exit
  135.     end
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Stops a Timer
  139.   #--------------------------------------------------------------------------
  140.   def stop(index)
  141.     if !@timer[index].nil?
  142.       if !@timer[index][1]
  143.         @timer[index][1] = true
  144.       else
  145.         msgbox_p("Error: TIMER WURDE BEREITS GESTOPPT! Index: "  + index.to_s)
  146.         SceneManager.exit
  147.       end
  148.     else
  149.       msgbox_p("Error: TIMER EXITIERT NICHT! Index: "  + index.to_s)
  150.       SceneManager.exit
  151.     end
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Stops a Timer
  155.   #--------------------------------------------------------------------------
  156.   def start(index)
  157.     if !@timer[index].nil?
  158.       if @timer[index][1]
  159.         @timer[index][1] = false
  160.       else
  161.         msgbox_p("Error: TIMER IST BEREITS GESTARTET! Index: "  + index.to_s)
  162.         SceneManager.exit
  163.       end
  164.     else
  165.       msgbox_p("Error: TIMER EXITIERT NICHT! Index: "  + index.to_s)
  166.       SceneManager.exit
  167.     end
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # * Frame Update
  171.   #--------------------------------------------------------------------------
  172.   def update
  173.     if @timer != Array.new
  174.       @timer.each_with_index do |t, i|
  175.         if !t.nil?
  176.           if !@timer[i][1]
  177.             @timer[i][0] -= 1 unless t[0] == 0
  178.             @timer[i][0] == nil if t[0] == 0
  179.           end
  180.         end
  181.       end
  182.     end
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Returns true if a Timer is Stopped
  186.   #--------------------------------------------------------------------------
  187.   def stopped?(index)
  188.     return @timer[index][1] if !@timer[index].nil?
  189.       msgbox_p("Error: TIMER EXITIERT NICHT! Index: "  + index.to_s)
  190.     SceneManager.exit
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # * Check if Timer is ended
  194.   #--------------------------------------------------------------------------
  195.   def check(index)
  196.     if !@timer[index].nil?
  197.       return true if @timer[index][0] == 0
  198.       return false
  199.     else
  200.       msgbox_p("Error: TIMER EXITIERT NICHT! Index: "  + index.to_s)
  201.       SceneManager.exit
  202.     end
  203.   end
  204. end