=begin
Script Name: Timer
Author: Tajiin
Release Date: 02/18/2014 | mm/dd/yyyy
Version: 3.0
Versions Date: 05/24/2015
Description:
With this script you can add timers that will count a specific time in
the background.
Script-Commands(Event > 3 > Script...):
$game_system.timer.set(i, t)
- Creates a timer
- i: is the index for the timer thatt'll be created
- t: is the index for the timer will count (in seconds)
$game_system.timer.check(i)
- tests if the timer is already done
- i: is the index for the timer that'll be tested
$game_system.timer.get(i, v)
- gives you the value from a timer. (in seconds)
- i: is the index for the timer with the value you'll get
$game_system.timer.stop(i)
- stops a timer
- i: is the index for the timer that will be stopped
$game_system.timer.start(i)
- starts a stopped timer
- i: is the index for the timer that will be restarted
$game_system.timer.stopped?(i)
- tests if a timer is stopped or not (True = stopped;
False = not stopped)
- i: is the index for the timer that'll be tested
Have Fun
SORRY FOR MY BAD ENGLISH SKILLS
=end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
# This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================
module DataManager
class << self
alias taj_datamanager_creategameobjects_ijabsdi96 create_game_objects
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
def create_game_objects
taj_datamanager_creategameobjects_ijabsdi96
$game_system.timer = Timer.new
end
end
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :timer
end
#==============================================================================
# ** Game_Timer
#------------------------------------------------------------------------------
# This class handles timers. Instances of this class are referenced by
# $game_timer.
#==============================================================================
class Game_Timer
alias taj_gametimer_update_dd128 update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
taj_gametimer_update_dd128
$game_system.timer.update
end
end
$imported = {} if $imported.nil?
$imported["Taj_Game_TimerCore"] = true
class Timer
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :timer
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@timer = Array.new()
end
#--------------------------------------------------------------------------
# * Set the timer
#--------------------------------------------------------------------------
def set(index, frames)
@timer[index] = Array.new
@timer[index][0] = frames*60
@timer[index][1] = false
end
#--------------------------------------------------------------------------
# * Set the timer
#--------------------------------------------------------------------------
def get(index, variable)
if !@timer[index].nil?
$game_variables[variable] = (@timer[index][0] / 60).round
else
msgbox_p("Error: TIMER DONT EXIST! #Index: " + index.to_s)
SceneManager.exit
end
end
#--------------------------------------------------------------------------
# * Stops a Timer
#--------------------------------------------------------------------------
def stop(index)
if !@timer[index].nil?
if !@timer[index][1]
@timer[index][1] = true
else
msgbox_p("Error: TIMER IS ALREADY STOPPED! #Index: " + index.to_s)
SceneManager.exit
end
else
msgbox_p("Error: TIMER DONT EXIST! #Index: " + index.to_s)
SceneManager.exit
end
end
#--------------------------------------------------------------------------
# * Stops a Timer
#--------------------------------------------------------------------------
def start(index)
if !@timer[index].nil?
if @timer[index][1]
@timer[index][1] = false
else
msgbox_p("Error: TIMER ISNT STOPPED! #Index: " + index.to_s)
SceneManager.exit
end
else
msgbox_p("Error: TIMER DONT EXIST! #Index: " + index.to_s)
SceneManager.exit
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @timer != Array.new
@timer.each_with_index do |t, i|
if !t.nil?
if !@timer[i][1]
@timer[i][0] -= 1 unless t[0] == 0
@timer[i][0] == nil if t[0] == 0
end
end
end
end
end
#--------------------------------------------------------------------------
# * Returns true if a Timer is Stopped
#--------------------------------------------------------------------------
def stopped?(index)
return @timer[index][1] if !@timer[index].nil?
msgbox_p("Error: TIMER DONT EXIST! #Index: " + index.to_s)
SceneManager.exit
end
#--------------------------------------------------------------------------
# * Check if Timer is ended
#--------------------------------------------------------------------------
def check(index)
if !@timer[index].nil?
return true if @timer[index][0] == 0
return false
else
msgbox_p("Error: TIMER DONT EXIST! #Index: " + index.to_s)
SceneManager.exit
end
end
end