I'm thinking of using Ct_Bolt's timer script for my game.
This honestly seems like a great script because it allows you to have multiple timers go off at once, or at least that what it seems to me. This would be very useful for my game.
However I can't seem to find any command that detects if a timer has reached 0.
For example, with rpg makers default timer, you can have it so once it reaches 0 it activates some event. It's pretty neat.
But in Ct's script I can't seem to find that feature?
Like if timer number 2 reaches 0 it activates an event, meanwhile timer number 3 is still counting down.
If that's not a feature available in this script, does anyone know of another script I can use?
Thank you.
#==============================================================================
# Title: CT_Timers (v3.0)
# Author: CT_Bolt
# Date: September 19, 2013
# Version History:
# v1.00 (02-28-2013)
# -- First release
# v1.02 (03-01-2013)
# -- Bug Fix & More Comments
# v2.0 (03-01-2013)
# -- Major Update
# -- Changed from a Timer Add-on to it's own timer
# v2.1 (03-03-2013)
# -- Added Features
# -- Optional prefix & suffix can now be added
# -- Multiple buttons can now be assigned for pressing
# v2.2 (03-03-2013)
# -- Added more features
# -- Add or remove time from a currently running CT_Timer
# -- Pause & resume a currently running CT_Timer
# v2.21 (03-08-2013)
# -- Bugfix - Save/Load wasn't working
# v2.5 (07-21-2013)
# -- Added features
# -- Audio was added
# -- Ability to fade in
# v2.6 (08-16-2013)
# -- Added features
# -- Optional Turn a switch on when the timer starts
# & turn off the switch when the timer stops
# v2.6.2 (09-04-2013)
# -- Bug Fixes
# -- Slightly cleaner code
# -- Made the demo into a mini-game to help nyxzryu
# v3.0 (09-19-2013)
# -- Major Update
# -- Basically re-wrote everything
# -- Added many new features
# -- Unlimited CT_Timers
# -- Much more customizable
#------------------------------------------------------------------------------
# Description:
# A whole new set of timers. Can have multiple timers active at once.
# Custom properties (font color, font size, x, y, z, etc.)
# Let's you press multiple buttons while a ct_timer is active.
# Counts the button presses & stores them in a variable.
# Allows a switch to be used to determine if the ct_timer will be visible.
# Add\Remove time from a currently running CT_Timer with a simple script call.
# Pause\Resume a currently running CT_Timer with a simple script call.
#------------------------------------------------------------------------------
# Compatibility:
# This should be compatible with all scripts as long as they
# don't overwrite any methods used in this script.
#
# Alias Methods:
# module DataManager
# create_game_objects
# make_save_contents
# extract_save_contents(contents)
#
# module BattleManager
# battle_start
# battle_end(result)
#
# class Spriteset_Map
# initialize
# dispose
# update
#
# class Spriteset_Battle
# initialize
# dispose
# update
#
# class Scene_Map < Scene_Base
# start
# update
#
# class Scene_Battle < Scene_Base
# start
# update
# update_basic
#
# New Classes:
# CT_ScheduledTask
# CT_Font
# CT_Imageset
# CT_Textset
# CT_Audio
# CT_Properties
# CT_Game_Timer
# CT_Sprite_Timer < Sprite
#------------------------------------------------------------------------------
# Usage:
# In a script call use the following method to start/stop a ct_timer:
# ct_timer(mins, [secs], [CT_Timer_ID], [start], [CT_audio])
#
# Examples:
# ct_timer(1, 30) # Starts a timer at 1 min 30 seconds
# ct_timer(0, 80) # Starts a timer at 1 min 20 seconds
# ct_timer(2) # Starts a timer at 2 mins
# ct_timer(0, 0, 2, false) # Stops the timer of $ct_game_timer[2]
#
# In a script call you can also use the following:
# Examples:
# $ct_game_timer[0].add_time (1, 20) # Add 1 minute & 20 seconds to timer id 0
# $ct_game_timer[1].lose_time(0, 15) # Subtract 15 seconds to timer id 1
# $ct_game_timer[0].pause # Pause countdown on timer id 0
# $ct_game_timer[2].resume # Resume countdown on timer id 2
#
# Configure module CT_Timer to the way you would like it.
# Configure $ct_game_timer in the DataManager Module to the way you like it.
#------------------------------------------------------------------------------
# Installation:
# To install the script, open the script editor and paste this script on
# a new section (insert) below the Materials & above Main Process.
#==============================================================================
#==============================================================================
# ** Module CT_Timer
#------------------------------------------------------------------------------
#==============================================================================
module CT_Timer
DEFAULT_WIDTH = 90
DEFAULT_HEIGHT = 38
DEFAULT_X = Graphics.width - DEFAULT_WIDTH
DEFAULT_Y = 83
end
#==============================================================================
# ** Module DataManager
#------------------------------------------------------------------------------
#==============================================================================
module DataManager
class << self
alias_method🙂my_create_game_objects, :create_game_objects)
alias_method🙂my_make_save_contents, :make_save_contents)
alias_method🙂my_extract_save_contents, :extract_save_contents)
end
def self.create_game_objects
my_create_game_objects
#~ x, y,
#~ schedule,
#~ imageset,
#~ textset
#~ auto_stop,
#~ z,
#~ accept_input_switch_id,
#~ hide_timer_switch_id,
#~ stay_in_battle_switch_id,
#~ pause_in_battle_switch_id,
#~ wait_for_timer_switch_id,
#~ button_press,
#~ button_count_var_id,
#~ auto_unaccept_input,
#~ width,
#~ height
$ct_game_timer = [#0
CT_Game_Timer.new, # A timer with minimal settings
#1
CT_Game_Timer.new( # A timer with lots of settings
# X
CT_Properties.new(CT_Timer:😀EFAULT_X,
# Y
CT_Timer:😀EFAULT_Y - CT_Timer:😀EFAULT_HEIGHT,
# Schedule
[CT_ScheduledTask.new("expire", nil, "common event", 2),
CT_ScheduledTask.new("start", "on", "switch", 121),
CT_ScheduledTask.new("start", "on", "switch", 123),
CT_ScheduledTask.new("start", "on", "switch", 124),
],
# Background Image(s)
[CT_Imageset.new("Timer BG2", 255),
CT_Imageset.new("Timer BG", 180)
],
# Text Settings
CT_Textset.new(CT_Font.new([000,000,000],
[255,255,255],
48, true),
"~", "~"),
nil, # Auto-Stop (deault is true)
nil, # Z (deault is 200)
123, # accept input switch id
nil, # hide timer switch id
121, # stay in battle if timer expires switch id
nil, # pause the timer while in battle switch id
124, # wait for the timer while in battle switch id
[:Z, :Y], # Buttons that can be pressed
1, # Variable ID for the total button count
nil, # auto-unaccept input (default is true)
nil, # width (default is CT_Timer:😀EFAULT_WIDTH)
nil, # height (default is CT_Timer:😀EFAULT_HEIGHT)
)
),
#2
CT_Game_Timer.new(
CT_Properties.new(CT_Timer:😀EFAULT_X, 20,
[CT_ScheduledTask.new("count down", "00:05", "common event", 7),
CT_ScheduledTask.new("at time", "00:45", "common event", 8),
CT_ScheduledTask.new("time range", "00:11...00:00", "common event", 3),
CT_ScheduledTask.new("start", "on", "switch", 291),
CT_ScheduledTask.new("start", "on", "switch", 131),
CT_ScheduledTask.new("expire", "off", "switch", 291)
],
nil,
CT_Textset.new(CT_Font.new([255,000,000],
[000,000,000],
48, true),
" ", " "), nil, nil,
nil, nil, 131
)
),
# 3
CT_Game_Timer.new(
CT_Properties.new(0, 83,
[CT_ScheduledTask.new("at time", "00:10", "common event", 21),
CT_ScheduledTask.new("at time", "00:20", "common event", 21),
CT_ScheduledTask.new("at time", "00:30", "common event", 21),
CT_ScheduledTask.new("at time", "00:40", "common event", 21),
CT_ScheduledTask.new("at time", "00:50", "common event", 21),
CT_ScheduledTask.new("at time", "01:00", "common event", 21),
CT_ScheduledTask.new("at time", "01:10", "common event", 21),
CT_ScheduledTask.new("at time", "01:20", "common event", 21),
CT_ScheduledTask.new("expire", "off", "common event", 20 )
]
)
),
#4
CT_Game_Timer.new(
CT_Properties.new(CT_Timer:😀EFAULT_X, 83,
[CT_ScheduledTask.new("expire", "off", "common event", 6 )
]
)
)
]
end
def self.make_save_contents
contents = my_make_save_contents
contents[:ct_timer] = $ct_game_timer
contents
end
def self.extract_save_contents(contents)
my_extract_save_contents(contents)
$ct_game_timer = contents[:ct_timer]
end
end
#==============================================================================
# ** CT_Schedule
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_ScheduledTask
attr_accessor :mode
attr_accessor :min
attr_accessor :sec
attr_accessor :type
attr_accessor :id
attr_accessor :start_min
attr_accessor :end_min
attr_accessor :start_sec
attr_accessor :end_sec
attr_accessor :switch_mode
def initialize(mode = "at time", param = "0:5", type = "common event", id = 1)
@min = 0
@sec = 0
@start_min = 0
@start_sec = 0
@end_min = 0
@end_sec = 0
@mode = mode.downcase
@type = type.downcase
@id = id
@switch_mode = true
if param
if param.class.to_s.downcase == "string"
if @mode == "time range" && param[0,param.index("...")]
param1 = param[0,param.index("...")]
param2 = param[param.index("...")+3,param.length]
if param1.index(":")
@start_min = param1[0,param1.index(":")].to_i
@start_sec = param1[param1.index(":")+1,param1.length].to_i
else
@start_min = param1.to_i
end
if param2.index(":")
@end_min = param2[0,param2.index(":")].to_i
@end_sec = param2[param2.index(":")+1,param2.length].to_i
else
@end_min = param2.to_i
end
else
if @mode == "at time" || @mode == "count down"
if param.index(":")
@min = param[0,param.index(":")].to_i
@sec = param[param.index(":")+1,param.length].to_i
else
@min = param1.to_i
end
end
end
end
if @type == "switch"
if param
if param.class.to_s.downcase == "string"
if param=="on"
param=true
else
param=false
end
end
end
@switch_mode = param
end
end
end
end
#==============================================================================
# ** CT_Font
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Font
attr_accessor :color
attr_accessor 😮utline_color
attr_accessor :size
attr_accessor :bold
attr_accessor :italic
attr_accessor 😮utline
attr_accessor :shadow
attr_accessor :name
def initialize(color = [255, 255, 255], outline_color = [0, 0, 0],
size = 26, bold = false, italic = false,
outline = false, shadow = false,
name = ["VL Gothic"]
)
color = [75,33,15] unless color
outline_color = [000,000,000] unless outline_color
size = 26 unless size
bold = false unless bold
italic = false unless italic
outline = false unless outline
shadow = false unless shadow
name = ["VL Gothic"] unless name
@color = color
@outline_color = outline_color
@size = size
@bold = bold
@italic = italic
@outline = outline
@Shadow = shadow
@Name = name
end
end
#==============================================================================
# ** CT_Imageset
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Imageset
attr_accessor :filename
attr_accessor 😮pacity
def initialize(filename, opacity = 255)
opacity = 255 unless opacity
@filename = filename
@opacity = opacity
end
end
#==============================================================================
# ** CT_Textset
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Textset
attr_accessor :font
attr_accessor 😛refix
attr_accessor :suffix
attr_accessor :alignment
attr_accessor :visible
def initialize(font = CT_Font.new, prefix = "", suffix = "",
alignment = 0, visible = true)
font = CT_font.new unless font
prefix = "" unless prefix
suffix = "" unless suffix
alignment = 0 unless alignment
visible = true unless visible
@font = font
@prefix = prefix
@suffix = suffix
@alignment = alignment
@visible = visible
end
end
#==============================================================================
# ** CT_Audio
#------------------------------------------------------------------------------
# This class handles timers. Instances of this class are referenced by
# $ct_game_timer.
#==============================================================================
class CT_Audio
attr_accessor :filename
attr_accessor :from_start
attr_accessor :fadein_step
attr_accessor :fadein_increase
attr_accessor :start_volume
attr_accessor :volume
attr_accessor :end_volume
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(filename = "Field1", start_volume = 100, end_volume = nil, fadein_increase = 5, fadein_step = 20, from_start = false)
if !filename.downcase.include?("/")
filename = "Audio/BGM/" + filename
end
@filename = filename
@from_start = from_start
@fadein_step = fadein_step
@fadein_increase = fadein_increase
@start_volume = start_volume
@Volume = @start_volume
if end_volume
@end_volume = end_volume
else
@end_volume = @start_volume
end
end
end
#==============================================================================
# ** CT_Properties
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Properties
attr_accessor :textset
attr_accessor :schedule
attr_accessor :x
attr_accessor :y
attr_accessor :z
attr_accessor :width
attr_accessor :height
attr_accessor :accept_input_switch_id
attr_accessor :hide_timer_switch_id
attr_accessor :stay_in_battle_switch_id # Switch used to keep the player in battle
# after the timer expires
attr_accessor 😛ause_in_battle_switch_id # Switch used to determine if the timer will
# update in battle
attr_accessor :wait_for_timer_switch_id # Set true to "pause the battle" while the timer counts down
attr_accessor :button_press # Button symbols for what button will be used
# Default valid button symbols:
# 😀OWN = Down Arrow Key
# :LEFT = Left Arrow Key
# :RIGHT = Right Arrow Key
# :UP = Up Arrow Key
# :A = Shift Key
# :B = X or Esc Key
# :C = Z or Enter or Space Key
# :X = A Key
# :Y = S Key
# :Z = D Key
# :L = Q Key
# :R = W Key
# :SHIFT = Shift Key
# :CTRL = CTRL Key
# :ALT = ALT Key
# :F5 = F5 Key
# :F6 = F6 Key
# :F7 = F7 Key
# :F8 = F8 Key
# :F9 = F9 Key
# Note if you don't want to use that at all
# set it to nil (button_press = nil)
attr_accessor :button_count_var_id # Variable ID used to keep count of how many
# times the button was pressed
attr_accessor :auto_unaccept_input # Set true to turn the accept_input_switch_id
# switch off when the timer expires
attr_accessor :auto_stop # Set true to turn the accept_input_switch_id
# switch off when the timer expires
attr_accessor :imageset
def initialize(x = CT_Timer:😀EFAULT_X, y = CT_Timer:😀EFAULT_Y, schedule = nil,
imageset = nil,
textset = CT_Textset.new, auto_stop = true, z = 200,
accept_input_switch_id = nil,
hide_timer_switch_id = nil,
stay_in_battle_switch_id = nil,
pause_in_battle_switch_id = nil,
wait_for_timer_switch_id = nil,
button_press = nil, #[:Z, :Y],
button_count_var_id = nil,
auto_unaccept_input = true,
width = CT_Timer:😀EFAULT_WIDTH,
height = CT_Timer:😀EFAULT_HEIGHT
)
x = CT_Timer:😀EFAULT_X unless x
@x = x
y = CT_Timer:😀EFAULT_Y unless y
@y = y
width = CT_Timer:😀EFAULT_WIDTH unless width
@width = width
height = CT_Timer:😀EFAULT_HEIGHT unless height
@height = height
@schedule = schedule
@imageset = imageset
textset = CT_Textset.new unless textset
@textset = textset
auto_stop = true unless auto_stop
@auto_stop = auto_stop
z = 200 unless z
@z = z
@accept_input_switch_id = accept_input_switch_id
@hide_timer_switch_id = hide_timer_switch_id
@stay_in_battle_switch_id = stay_in_battle_switch_id
@pause_in_battle_switch_id = pause_in_battle_switch_id
@wait_for_timer_switch_id = wait_for_timer_switch_id
@button_press = button_press
@button_count_var_id = button_count_var_id
auto_unaccept_input = true unless auto_unaccept_input
@auto_unaccept_input = auto_unaccept_input
end
end
#==============================================================================
# ** CT_Game_Timer
#------------------------------------------------------------------------------
# This class handles timers. Instances of this class are referenced by
# $ct_game_timer.
#==============================================================================
class CT_Game_Timer
attr_accessor :ct_properties
attr_accessor :ct_audio
attr_accessor 😛aused
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(ct_properties = CT_Properties.new)
@count = 0
@fade_in_count = 20
@ct_audio = nil
@working = false
@paused = false
@ct_properties = ct_properties
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if !@paused
if @ct_properties.accept_input_switch_id
if $game_switches[@ct_properties.accept_input_switch_id]
if @working && @count > 0
if @ct_properties.button_press
@ct_properties.button_press.each do |bp|
if Input.trigger?(bp)
if @ct_properties.button_count_var_id
$game_variables[@ct_properties.button_count_var_id]=
$game_variables[@ct_properties.button_count_var_id]+1
end
end
end
end
end
end
end
if @working && @count > 0
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "at time"
v = (i.min * 60) + (i.sec+1)
if @count == v * Graphics.frame_rate && i.type == "common event"
$game_temp.reserve_common_event(i.id)
end
end
end
end
if @ct_audio
if @ct_audio.volume < @ct_audio.end_volume
@fade_in_count += 1
if @fade_in_count >= @ct_audio.fadein_step
@fade_in_count = 0
@ct_audio.volume += @ct_audio.fadein_increase unless @ct_audio.volume >= @ct_audio.end_volume
Audio.bgm_play(@ct_audio.filename, @ct_audio.volume)
end
end
end
@count -= 1
on_expire if @count <= 0
end
end
end
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
def start(count)
@count = count
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "count down"
i.mode = "at time"
i.sec = (@count / Graphics.frame_rate) - ((i.min * 60) + i.sec)
i.min = 0
end
end
end
@working = true
@active = true
@paused = false
if @ct_properties.button_count_var_id
$game_variables[@ct_properties.button_count_var_id]=0
end
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "start"
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
elsif i.type == "switch"
$game_switches[i.id] = i.switch_mode
end
end
end
end
if @ct_audio
if @ct_audio.from_start
Audio.bgm_stop
end
if @ct_audio.volume < @ct_audio.end_volume
@fade_in_count += 1
if @fade_in_count >= @ct_audio.fadein_step
@fade_in_count = 0
@ct_audio.volume += @ct_audio.fadein_increase unless @ct_audio.volume >= @ct_audio.end_volume
Audio.bgm_play(@ct_audio.filename, @ct_audio.volume)
end
end
end
end
#--------------------------------------------------------------------------
# * Stop
#--------------------------------------------------------------------------
def stop
if @ct_properties.accept_input_switch_id
$game_switches[@ct_properties.accept_input_switch_id] = false
end
@working = false
end
#--------------------------------------------------------------------------
# * Determine if Working
#--------------------------------------------------------------------------
def working?
@working
end
def active?
@active
end
#--------------------------------------------------------------------------
# * Get Seconds
#--------------------------------------------------------------------------
def sec
@count / Graphics.frame_rate
end
#--------------------------------------------------------------------------
# * Processing When Timer Reaches 0
#--------------------------------------------------------------------------
def on_expire
if @ct_properties.accept_input_switch_id
if $game_switches[@ct_properties.accept_input_switch_id]
puts "Total of buttons presses was " + $game_variables[@ct_properties.button_count_var_id].to_s + " times.\n"
end
end
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "expire"
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
elsif i.type == "switch"
$game_switches[i.id] = i.switch_mode
end
end
end
end
if @ct_properties.auto_unaccept_input
if @ct_properties.accept_input_switch_id
$game_switches[@ct_properties.accept_input_switch_id] = false
end
end
if @ct_properties.auto_stop
stop
end
@active = false
if @ct_properties.stay_in_battle_switch_id
BattleManager.abort unless $game_switches[@ct_properties.stay_in_battle_switch_id]
else
BattleManager.abort
end
end
#--------------------------------------------------------------------------
# * Add more time
#--------------------------------------------------------------------------
def add_time(min = 0, sec = 0)
count = (min * 60) + sec
@count += count * Graphics.frame_rate
end
#--------------------------------------------------------------------------
# * Subtract more time
#--------------------------------------------------------------------------
def lose_time(min = 0, sec = 0)
count = (min * 60) + sec
@count = [@count - (count * Graphics.frame_rate), 1].max
end
#--------------------------------------------------------------------------
# * Pause
#--------------------------------------------------------------------------
def pause
@paused = true
end
#--------------------------------------------------------------------------
# * Resume
#--------------------------------------------------------------------------
def resume
@paused = false
end
#--------------------------------------------------------------------------
# * Pause
#--------------------------------------------------------------------------
def paused?
@paused
end
end
#==============================================================================
# ** CT_Sprite_Timer
#------------------------------------------------------------------------------
# This sprite is for ct_timer displays.
# It monitors $ct_game_timer and automatically changes sprite states.
#==============================================================================
class CT_Sprite_Timer < Sprite
attr_accessor :ct_game_timer
attr_accessor :bg
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(viewport, ct_game_timer = $ct_game_timer)
super(viewport)
@ct_game_timer = ct_game_timer
@Index = 0
if @ct_game_timer.ct_properties.imageset
@bg = []
@ct_game_timer.ct_properties.imageset.each do |i|
@bg[@index] = Cache.load_bitmap("Graphics/Pictures/", i.filename, 0)
@Index = @Index + 1
end
end
create_bitmap
create_font
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# * Create Bitmap
#--------------------------------------------------------------------------
def create_bitmap
self.bitmap = Bitmap.new(@ct_game_timer.ct_properties.width,
@ct_game_timer.ct_properties.height)
end
#--------------------------------------------------------------------------
# * Create Font
#--------------------------------------------------------------------------
def create_font
self.bitmap.font.name = @ct_game_timer.ct_properties.textset.font.name
self.bitmap.font.outline = @ct_game_timer.ct_properties.textset.font.outline
self.bitmap.font.shadow = @ct_game_timer.ct_properties.textset.font.shadow
self.bitmap.font.bold = @ct_game_timer.ct_properties.textset.font.bold
self.bitmap.font.italic = @ct_game_timer.ct_properties.textset.font.italic
self.bitmap.font.size = @ct_game_timer.ct_properties.textset.font.size
self.bitmap.font.color.set(@ct_game_timer.ct_properties.textset.font.color[0],
@ct_game_timer.ct_properties.textset.font.color[1],
@ct_game_timer.ct_properties.textset.font.color[2])
self.bitmap.font.out_color.set(@ct_game_timer.ct_properties.textset.font.outline_color[0],
@ct_game_timer.ct_properties.textset.font.outline_color[1],
@ct_game_timer.ct_properties.textset.font.outline_color[2])
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @ct_game_timer.ct_properties.hide_timer_switch_id
if not $game_switches[@ct_game_timer.ct_properties.hide_timer_switch_id]
super
update_bitmap
update_position
update_visibility
else
self.visible = false
end
else
super
update_bitmap
update_position
update_visibility
end
end
#--------------------------------------------------------------------------
# * Update Transfer Origin Bitmap
#--------------------------------------------------------------------------
def update_bitmap
if @ct_game_timer.sec != @total_sec
@total_sec = @ct_game_timer.sec
if @ct_game_timer.ct_properties.schedule
@ct_game_timer.ct_properties.schedule.each do |i|
if i.mode == "time range"
v1 = (i.start_min * 60) + (i.start_sec + 1)
v2 = (i.end_min * 60) + (i.end_sec + 1)
if @ct_game_timer.sec <= (v1) && @ct_game_timer.sec >= (v2)
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
end
end
end
end
end
redraw
end
end
#--------------------------------------------------------------------------
# * Redraw
#--------------------------------------------------------------------------
def redraw
self.bitmap.clear
@Index = 0
if @bg
@bg.each do |i|
self.bitmap.stretch_blt(self.bitmap.rect, i, i.rect, @ct_game_timer.ct_properties.imageset[@index].opacity)
@Index = @Index + 1
end
end
self.bitmap.draw_text(self.bitmap.rect, timer_text, 1)
end
#--------------------------------------------------------------------------
# * Create Text
#--------------------------------------------------------------------------
def timer_text
sprintf(@ct_game_timer.ct_properties.textset.prefix +
"%02d:%02d" + @ct_game_timer.ct_properties.textset.suffix,
@total_sec / 60, @total_sec % 60)
end
#--------------------------------------------------------------------------
# * Update Position
#--------------------------------------------------------------------------
def update_position
self.x = @ct_game_timer.ct_properties.x
self.y = @ct_game_timer.ct_properties.y
self.z = @ct_game_timer.ct_properties.z
end
#--------------------------------------------------------------------------
# * Update Visibility
#--------------------------------------------------------------------------
def update_visibility
self.visible = @ct_game_timer.working?
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================
class Spriteset_Map
attr_accessor :ct_timer_sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :my_init :initialize
def initialize()
create_ct_timers()
my_init
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
alias :my_dispose :dispose
def dispose
my_dispose
dispose_ct_timers
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
update_ct_timers
end
#--------------------------------------------------------------------------
# * Create CT_Timer Sprites
#--------------------------------------------------------------------------
def create_ct_timers(ct_game_timer = $ct_game_timer)
@ct_timer_sprite = []
@Index = 0
ct_game_timer.each do |i|
@ct_timer_sprite[@index] = CT_Sprite_Timer.new(@viewport2, i)
@Index = @Index + 1
end
end
#--------------------------------------------------------------------------
# * Free CT_Timer Sprite
#--------------------------------------------------------------------------
def dispose_ct_timers
@ct_timer_sprite.each do |i|
i.dispose
end
end
#--------------------------------------------------------------------------
# * Update CT_Timer Sprite
#--------------------------------------------------------------------------
def update_ct_timers
@ct_timer_sprite.each do |i|
i.update
end
end
end
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================
class Spriteset_Battle
attr_accessor :ct_timer_sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :my_init :initialize
def initialize()
create_ct_timers()
my_init
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
alias :my_dispose :dispose
def dispose
my_dispose
dispose_ct_timers
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
update_ct_timers
end
#--------------------------------------------------------------------------
# * Create CT_Timer Sprites
#--------------------------------------------------------------------------
def create_ct_timers(ct_game_timer = $ct_game_timer)
@ct_timer_sprite = []
@Index = 0
ct_game_timer.each do |i|
@ct_timer_sprite[@index] = CT_Sprite_Timer.new(@viewport2, i)
@Index = @Index + 1
end
end
#--------------------------------------------------------------------------
# * Free CT_Timer Sprite
#--------------------------------------------------------------------------
def dispose_ct_timers
@ct_timer_sprite.each do |i|
i.dispose
end
end
#--------------------------------------------------------------------------
# * Update CT_Timer Sprite
#--------------------------------------------------------------------------
def update_ct_timers
@ct_timer_sprite.each do |i|
i.update
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
attr_accessor :ct_timer
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
alias :my_start :start
def start
my_start
@ct_timer = $ct_game_timer
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
@ct_timer.each do |i|
i.update
end
update_scene if scene_change_ok?
end
end
#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#
#==============================================================================
module BattleManager
class << self
alias_method🙂my_battle_start, :battle_start)
alias_method🙂my_battle_end, :battle_end)
end
def self.battle_start
$ct_game_timer.each do |i|
if i.ct_properties.pause_in_battle_switch_id
if $game_switches[i.ct_properties.pause_in_battle_switch_id]
i.paused = true
end
end
end
my_battle_start
end
def self.battle_end(result)
$ct_game_timer.each do |i|
if i.ct_properties.pause_in_battle_switch_id
if $game_switches[i.ct_properties.pause_in_battle_switch_id]
i.paused = false
end
end
end
my_battle_end(result)
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle < Scene_Base
attr_accessor :ct_timer
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
alias :my_start :start
def start
my_start
@ct_timer = $ct_game_timer
@old_continue = true
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
@paused_timer = false
@accept_input = false
@wait_for_timer = false
@continue = true
@ct_timer.each do |i|
if i.active?
if i.ct_properties.pause_in_battle_switch_id
@paused_timer = i.paused
end
if i.ct_properties.accept_input_switch_id
@accept_input = $game_switches[i.ct_properties.accept_input_switch_id]
end
if i.ct_properties.wait_for_timer_switch_id
@wait_for_timer = $game_switches[i.ct_properties.wait_for_timer_switch_id]
end
end
end
if @wait_for_timer && !@paused_timer
super
@continue = false
else
if @old_continue != @continue
turn_end
end
my_update
end
@old_continue = @continue
end
#--------------------------------------------------------------------------
# * Update Frame (Basic)
#--------------------------------------------------------------------------
alias :my_update_basic :update_basic
def update_basic
my_update_basic
@ct_timer.each do |i|
i.update
end
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * ct_timer
# Use this to set up a ct_timer
#--------------------------------------------------------------------------
def ct_timer(mins = 0, secs = 0, ct_game_timer = $ct_game_timer[0], start = true, ct_audio = nil)
mins = 0 unless mins
secs = 0 unless secs
if ct_game_timer
if ct_game_timer.class.to_s.downcase == "fixnum"
ct_game_timer = $ct_game_timer[ct_game_timer]
end
end
ct_game_timer = $ct_game_timer[0] unless ct_game_timer
start = false unless start
if start # Start
v = (mins * 60) + secs
ct_game_timer.ct_audio = ct_audio
ct_game_timer.start(v * Graphics.frame_rate)
else # Stop
ct_game_timer.stop
end
end
end
# Title: CT_Timers (v3.0)
# Author: CT_Bolt
# Date: September 19, 2013
# Version History:
# v1.00 (02-28-2013)
# -- First release
# v1.02 (03-01-2013)
# -- Bug Fix & More Comments
# v2.0 (03-01-2013)
# -- Major Update
# -- Changed from a Timer Add-on to it's own timer
# v2.1 (03-03-2013)
# -- Added Features
# -- Optional prefix & suffix can now be added
# -- Multiple buttons can now be assigned for pressing
# v2.2 (03-03-2013)
# -- Added more features
# -- Add or remove time from a currently running CT_Timer
# -- Pause & resume a currently running CT_Timer
# v2.21 (03-08-2013)
# -- Bugfix - Save/Load wasn't working
# v2.5 (07-21-2013)
# -- Added features
# -- Audio was added
# -- Ability to fade in
# v2.6 (08-16-2013)
# -- Added features
# -- Optional Turn a switch on when the timer starts
# & turn off the switch when the timer stops
# v2.6.2 (09-04-2013)
# -- Bug Fixes
# -- Slightly cleaner code
# -- Made the demo into a mini-game to help nyxzryu
# v3.0 (09-19-2013)
# -- Major Update
# -- Basically re-wrote everything
# -- Added many new features
# -- Unlimited CT_Timers
# -- Much more customizable
#------------------------------------------------------------------------------
# Description:
# A whole new set of timers. Can have multiple timers active at once.
# Custom properties (font color, font size, x, y, z, etc.)
# Let's you press multiple buttons while a ct_timer is active.
# Counts the button presses & stores them in a variable.
# Allows a switch to be used to determine if the ct_timer will be visible.
# Add\Remove time from a currently running CT_Timer with a simple script call.
# Pause\Resume a currently running CT_Timer with a simple script call.
#------------------------------------------------------------------------------
# Compatibility:
# This should be compatible with all scripts as long as they
# don't overwrite any methods used in this script.
#
# Alias Methods:
# module DataManager
# create_game_objects
# make_save_contents
# extract_save_contents(contents)
#
# module BattleManager
# battle_start
# battle_end(result)
#
# class Spriteset_Map
# initialize
# dispose
# update
#
# class Spriteset_Battle
# initialize
# dispose
# update
#
# class Scene_Map < Scene_Base
# start
# update
#
# class Scene_Battle < Scene_Base
# start
# update
# update_basic
#
# New Classes:
# CT_ScheduledTask
# CT_Font
# CT_Imageset
# CT_Textset
# CT_Audio
# CT_Properties
# CT_Game_Timer
# CT_Sprite_Timer < Sprite
#------------------------------------------------------------------------------
# Usage:
# In a script call use the following method to start/stop a ct_timer:
# ct_timer(mins, [secs], [CT_Timer_ID], [start], [CT_audio])
#
# Examples:
# ct_timer(1, 30) # Starts a timer at 1 min 30 seconds
# ct_timer(0, 80) # Starts a timer at 1 min 20 seconds
# ct_timer(2) # Starts a timer at 2 mins
# ct_timer(0, 0, 2, false) # Stops the timer of $ct_game_timer[2]
#
# In a script call you can also use the following:
# Examples:
# $ct_game_timer[0].add_time (1, 20) # Add 1 minute & 20 seconds to timer id 0
# $ct_game_timer[1].lose_time(0, 15) # Subtract 15 seconds to timer id 1
# $ct_game_timer[0].pause # Pause countdown on timer id 0
# $ct_game_timer[2].resume # Resume countdown on timer id 2
#
# Configure module CT_Timer to the way you would like it.
# Configure $ct_game_timer in the DataManager Module to the way you like it.
#------------------------------------------------------------------------------
# Installation:
# To install the script, open the script editor and paste this script on
# a new section (insert) below the Materials & above Main Process.
#==============================================================================
#==============================================================================
# ** Module CT_Timer
#------------------------------------------------------------------------------
#==============================================================================
module CT_Timer
DEFAULT_WIDTH = 90
DEFAULT_HEIGHT = 38
DEFAULT_X = Graphics.width - DEFAULT_WIDTH
DEFAULT_Y = 83
end
#==============================================================================
# ** Module DataManager
#------------------------------------------------------------------------------
#==============================================================================
module DataManager
class << self
alias_method🙂my_create_game_objects, :create_game_objects)
alias_method🙂my_make_save_contents, :make_save_contents)
alias_method🙂my_extract_save_contents, :extract_save_contents)
end
def self.create_game_objects
my_create_game_objects
#~ x, y,
#~ schedule,
#~ imageset,
#~ textset
#~ auto_stop,
#~ z,
#~ accept_input_switch_id,
#~ hide_timer_switch_id,
#~ stay_in_battle_switch_id,
#~ pause_in_battle_switch_id,
#~ wait_for_timer_switch_id,
#~ button_press,
#~ button_count_var_id,
#~ auto_unaccept_input,
#~ width,
#~ height
$ct_game_timer = [#0
CT_Game_Timer.new, # A timer with minimal settings
#1
CT_Game_Timer.new( # A timer with lots of settings
# X
CT_Properties.new(CT_Timer:😀EFAULT_X,
# Y
CT_Timer:😀EFAULT_Y - CT_Timer:😀EFAULT_HEIGHT,
# Schedule
[CT_ScheduledTask.new("expire", nil, "common event", 2),
CT_ScheduledTask.new("start", "on", "switch", 121),
CT_ScheduledTask.new("start", "on", "switch", 123),
CT_ScheduledTask.new("start", "on", "switch", 124),
],
# Background Image(s)
[CT_Imageset.new("Timer BG2", 255),
CT_Imageset.new("Timer BG", 180)
],
# Text Settings
CT_Textset.new(CT_Font.new([000,000,000],
[255,255,255],
48, true),
"~", "~"),
nil, # Auto-Stop (deault is true)
nil, # Z (deault is 200)
123, # accept input switch id
nil, # hide timer switch id
121, # stay in battle if timer expires switch id
nil, # pause the timer while in battle switch id
124, # wait for the timer while in battle switch id
[:Z, :Y], # Buttons that can be pressed
1, # Variable ID for the total button count
nil, # auto-unaccept input (default is true)
nil, # width (default is CT_Timer:😀EFAULT_WIDTH)
nil, # height (default is CT_Timer:😀EFAULT_HEIGHT)
)
),
#2
CT_Game_Timer.new(
CT_Properties.new(CT_Timer:😀EFAULT_X, 20,
[CT_ScheduledTask.new("count down", "00:05", "common event", 7),
CT_ScheduledTask.new("at time", "00:45", "common event", 8),
CT_ScheduledTask.new("time range", "00:11...00:00", "common event", 3),
CT_ScheduledTask.new("start", "on", "switch", 291),
CT_ScheduledTask.new("start", "on", "switch", 131),
CT_ScheduledTask.new("expire", "off", "switch", 291)
],
nil,
CT_Textset.new(CT_Font.new([255,000,000],
[000,000,000],
48, true),
" ", " "), nil, nil,
nil, nil, 131
)
),
# 3
CT_Game_Timer.new(
CT_Properties.new(0, 83,
[CT_ScheduledTask.new("at time", "00:10", "common event", 21),
CT_ScheduledTask.new("at time", "00:20", "common event", 21),
CT_ScheduledTask.new("at time", "00:30", "common event", 21),
CT_ScheduledTask.new("at time", "00:40", "common event", 21),
CT_ScheduledTask.new("at time", "00:50", "common event", 21),
CT_ScheduledTask.new("at time", "01:00", "common event", 21),
CT_ScheduledTask.new("at time", "01:10", "common event", 21),
CT_ScheduledTask.new("at time", "01:20", "common event", 21),
CT_ScheduledTask.new("expire", "off", "common event", 20 )
]
)
),
#4
CT_Game_Timer.new(
CT_Properties.new(CT_Timer:😀EFAULT_X, 83,
[CT_ScheduledTask.new("expire", "off", "common event", 6 )
]
)
)
]
end
def self.make_save_contents
contents = my_make_save_contents
contents[:ct_timer] = $ct_game_timer
contents
end
def self.extract_save_contents(contents)
my_extract_save_contents(contents)
$ct_game_timer = contents[:ct_timer]
end
end
#==============================================================================
# ** CT_Schedule
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_ScheduledTask
attr_accessor :mode
attr_accessor :min
attr_accessor :sec
attr_accessor :type
attr_accessor :id
attr_accessor :start_min
attr_accessor :end_min
attr_accessor :start_sec
attr_accessor :end_sec
attr_accessor :switch_mode
def initialize(mode = "at time", param = "0:5", type = "common event", id = 1)
@min = 0
@sec = 0
@start_min = 0
@start_sec = 0
@end_min = 0
@end_sec = 0
@mode = mode.downcase
@type = type.downcase
@id = id
@switch_mode = true
if param
if param.class.to_s.downcase == "string"
if @mode == "time range" && param[0,param.index("...")]
param1 = param[0,param.index("...")]
param2 = param[param.index("...")+3,param.length]
if param1.index(":")
@start_min = param1[0,param1.index(":")].to_i
@start_sec = param1[param1.index(":")+1,param1.length].to_i
else
@start_min = param1.to_i
end
if param2.index(":")
@end_min = param2[0,param2.index(":")].to_i
@end_sec = param2[param2.index(":")+1,param2.length].to_i
else
@end_min = param2.to_i
end
else
if @mode == "at time" || @mode == "count down"
if param.index(":")
@min = param[0,param.index(":")].to_i
@sec = param[param.index(":")+1,param.length].to_i
else
@min = param1.to_i
end
end
end
end
if @type == "switch"
if param
if param.class.to_s.downcase == "string"
if param=="on"
param=true
else
param=false
end
end
end
@switch_mode = param
end
end
end
end
#==============================================================================
# ** CT_Font
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Font
attr_accessor :color
attr_accessor 😮utline_color
attr_accessor :size
attr_accessor :bold
attr_accessor :italic
attr_accessor 😮utline
attr_accessor :shadow
attr_accessor :name
def initialize(color = [255, 255, 255], outline_color = [0, 0, 0],
size = 26, bold = false, italic = false,
outline = false, shadow = false,
name = ["VL Gothic"]
)
color = [75,33,15] unless color
outline_color = [000,000,000] unless outline_color
size = 26 unless size
bold = false unless bold
italic = false unless italic
outline = false unless outline
shadow = false unless shadow
name = ["VL Gothic"] unless name
@color = color
@outline_color = outline_color
@size = size
@bold = bold
@italic = italic
@outline = outline
@Shadow = shadow
@Name = name
end
end
#==============================================================================
# ** CT_Imageset
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Imageset
attr_accessor :filename
attr_accessor 😮pacity
def initialize(filename, opacity = 255)
opacity = 255 unless opacity
@filename = filename
@opacity = opacity
end
end
#==============================================================================
# ** CT_Textset
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Textset
attr_accessor :font
attr_accessor 😛refix
attr_accessor :suffix
attr_accessor :alignment
attr_accessor :visible
def initialize(font = CT_Font.new, prefix = "", suffix = "",
alignment = 0, visible = true)
font = CT_font.new unless font
prefix = "" unless prefix
suffix = "" unless suffix
alignment = 0 unless alignment
visible = true unless visible
@font = font
@prefix = prefix
@suffix = suffix
@alignment = alignment
@visible = visible
end
end
#==============================================================================
# ** CT_Audio
#------------------------------------------------------------------------------
# This class handles timers. Instances of this class are referenced by
# $ct_game_timer.
#==============================================================================
class CT_Audio
attr_accessor :filename
attr_accessor :from_start
attr_accessor :fadein_step
attr_accessor :fadein_increase
attr_accessor :start_volume
attr_accessor :volume
attr_accessor :end_volume
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(filename = "Field1", start_volume = 100, end_volume = nil, fadein_increase = 5, fadein_step = 20, from_start = false)
if !filename.downcase.include?("/")
filename = "Audio/BGM/" + filename
end
@filename = filename
@from_start = from_start
@fadein_step = fadein_step
@fadein_increase = fadein_increase
@start_volume = start_volume
@Volume = @start_volume
if end_volume
@end_volume = end_volume
else
@end_volume = @start_volume
end
end
end
#==============================================================================
# ** CT_Properties
#------------------------------------------------------------------------------
#
#==============================================================================
class CT_Properties
attr_accessor :textset
attr_accessor :schedule
attr_accessor :x
attr_accessor :y
attr_accessor :z
attr_accessor :width
attr_accessor :height
attr_accessor :accept_input_switch_id
attr_accessor :hide_timer_switch_id
attr_accessor :stay_in_battle_switch_id # Switch used to keep the player in battle
# after the timer expires
attr_accessor 😛ause_in_battle_switch_id # Switch used to determine if the timer will
# update in battle
attr_accessor :wait_for_timer_switch_id # Set true to "pause the battle" while the timer counts down
attr_accessor :button_press # Button symbols for what button will be used
# Default valid button symbols:
# 😀OWN = Down Arrow Key
# :LEFT = Left Arrow Key
# :RIGHT = Right Arrow Key
# :UP = Up Arrow Key
# :A = Shift Key
# :B = X or Esc Key
# :C = Z or Enter or Space Key
# :X = A Key
# :Y = S Key
# :Z = D Key
# :L = Q Key
# :R = W Key
# :SHIFT = Shift Key
# :CTRL = CTRL Key
# :ALT = ALT Key
# :F5 = F5 Key
# :F6 = F6 Key
# :F7 = F7 Key
# :F8 = F8 Key
# :F9 = F9 Key
# Note if you don't want to use that at all
# set it to nil (button_press = nil)
attr_accessor :button_count_var_id # Variable ID used to keep count of how many
# times the button was pressed
attr_accessor :auto_unaccept_input # Set true to turn the accept_input_switch_id
# switch off when the timer expires
attr_accessor :auto_stop # Set true to turn the accept_input_switch_id
# switch off when the timer expires
attr_accessor :imageset
def initialize(x = CT_Timer:😀EFAULT_X, y = CT_Timer:😀EFAULT_Y, schedule = nil,
imageset = nil,
textset = CT_Textset.new, auto_stop = true, z = 200,
accept_input_switch_id = nil,
hide_timer_switch_id = nil,
stay_in_battle_switch_id = nil,
pause_in_battle_switch_id = nil,
wait_for_timer_switch_id = nil,
button_press = nil, #[:Z, :Y],
button_count_var_id = nil,
auto_unaccept_input = true,
width = CT_Timer:😀EFAULT_WIDTH,
height = CT_Timer:😀EFAULT_HEIGHT
)
x = CT_Timer:😀EFAULT_X unless x
@x = x
y = CT_Timer:😀EFAULT_Y unless y
@y = y
width = CT_Timer:😀EFAULT_WIDTH unless width
@width = width
height = CT_Timer:😀EFAULT_HEIGHT unless height
@height = height
@schedule = schedule
@imageset = imageset
textset = CT_Textset.new unless textset
@textset = textset
auto_stop = true unless auto_stop
@auto_stop = auto_stop
z = 200 unless z
@z = z
@accept_input_switch_id = accept_input_switch_id
@hide_timer_switch_id = hide_timer_switch_id
@stay_in_battle_switch_id = stay_in_battle_switch_id
@pause_in_battle_switch_id = pause_in_battle_switch_id
@wait_for_timer_switch_id = wait_for_timer_switch_id
@button_press = button_press
@button_count_var_id = button_count_var_id
auto_unaccept_input = true unless auto_unaccept_input
@auto_unaccept_input = auto_unaccept_input
end
end
#==============================================================================
# ** CT_Game_Timer
#------------------------------------------------------------------------------
# This class handles timers. Instances of this class are referenced by
# $ct_game_timer.
#==============================================================================
class CT_Game_Timer
attr_accessor :ct_properties
attr_accessor :ct_audio
attr_accessor 😛aused
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(ct_properties = CT_Properties.new)
@count = 0
@fade_in_count = 20
@ct_audio = nil
@working = false
@paused = false
@ct_properties = ct_properties
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if !@paused
if @ct_properties.accept_input_switch_id
if $game_switches[@ct_properties.accept_input_switch_id]
if @working && @count > 0
if @ct_properties.button_press
@ct_properties.button_press.each do |bp|
if Input.trigger?(bp)
if @ct_properties.button_count_var_id
$game_variables[@ct_properties.button_count_var_id]=
$game_variables[@ct_properties.button_count_var_id]+1
end
end
end
end
end
end
end
if @working && @count > 0
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "at time"
v = (i.min * 60) + (i.sec+1)
if @count == v * Graphics.frame_rate && i.type == "common event"
$game_temp.reserve_common_event(i.id)
end
end
end
end
if @ct_audio
if @ct_audio.volume < @ct_audio.end_volume
@fade_in_count += 1
if @fade_in_count >= @ct_audio.fadein_step
@fade_in_count = 0
@ct_audio.volume += @ct_audio.fadein_increase unless @ct_audio.volume >= @ct_audio.end_volume
Audio.bgm_play(@ct_audio.filename, @ct_audio.volume)
end
end
end
@count -= 1
on_expire if @count <= 0
end
end
end
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
def start(count)
@count = count
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "count down"
i.mode = "at time"
i.sec = (@count / Graphics.frame_rate) - ((i.min * 60) + i.sec)
i.min = 0
end
end
end
@working = true
@active = true
@paused = false
if @ct_properties.button_count_var_id
$game_variables[@ct_properties.button_count_var_id]=0
end
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "start"
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
elsif i.type == "switch"
$game_switches[i.id] = i.switch_mode
end
end
end
end
if @ct_audio
if @ct_audio.from_start
Audio.bgm_stop
end
if @ct_audio.volume < @ct_audio.end_volume
@fade_in_count += 1
if @fade_in_count >= @ct_audio.fadein_step
@fade_in_count = 0
@ct_audio.volume += @ct_audio.fadein_increase unless @ct_audio.volume >= @ct_audio.end_volume
Audio.bgm_play(@ct_audio.filename, @ct_audio.volume)
end
end
end
end
#--------------------------------------------------------------------------
# * Stop
#--------------------------------------------------------------------------
def stop
if @ct_properties.accept_input_switch_id
$game_switches[@ct_properties.accept_input_switch_id] = false
end
@working = false
end
#--------------------------------------------------------------------------
# * Determine if Working
#--------------------------------------------------------------------------
def working?
@working
end
def active?
@active
end
#--------------------------------------------------------------------------
# * Get Seconds
#--------------------------------------------------------------------------
def sec
@count / Graphics.frame_rate
end
#--------------------------------------------------------------------------
# * Processing When Timer Reaches 0
#--------------------------------------------------------------------------
def on_expire
if @ct_properties.accept_input_switch_id
if $game_switches[@ct_properties.accept_input_switch_id]
puts "Total of buttons presses was " + $game_variables[@ct_properties.button_count_var_id].to_s + " times.\n"
end
end
if @ct_properties.schedule
@ct_properties.schedule.each do |i|
if i.mode == "expire"
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
elsif i.type == "switch"
$game_switches[i.id] = i.switch_mode
end
end
end
end
if @ct_properties.auto_unaccept_input
if @ct_properties.accept_input_switch_id
$game_switches[@ct_properties.accept_input_switch_id] = false
end
end
if @ct_properties.auto_stop
stop
end
@active = false
if @ct_properties.stay_in_battle_switch_id
BattleManager.abort unless $game_switches[@ct_properties.stay_in_battle_switch_id]
else
BattleManager.abort
end
end
#--------------------------------------------------------------------------
# * Add more time
#--------------------------------------------------------------------------
def add_time(min = 0, sec = 0)
count = (min * 60) + sec
@count += count * Graphics.frame_rate
end
#--------------------------------------------------------------------------
# * Subtract more time
#--------------------------------------------------------------------------
def lose_time(min = 0, sec = 0)
count = (min * 60) + sec
@count = [@count - (count * Graphics.frame_rate), 1].max
end
#--------------------------------------------------------------------------
# * Pause
#--------------------------------------------------------------------------
def pause
@paused = true
end
#--------------------------------------------------------------------------
# * Resume
#--------------------------------------------------------------------------
def resume
@paused = false
end
#--------------------------------------------------------------------------
# * Pause
#--------------------------------------------------------------------------
def paused?
@paused
end
end
#==============================================================================
# ** CT_Sprite_Timer
#------------------------------------------------------------------------------
# This sprite is for ct_timer displays.
# It monitors $ct_game_timer and automatically changes sprite states.
#==============================================================================
class CT_Sprite_Timer < Sprite
attr_accessor :ct_game_timer
attr_accessor :bg
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(viewport, ct_game_timer = $ct_game_timer)
super(viewport)
@ct_game_timer = ct_game_timer
@Index = 0
if @ct_game_timer.ct_properties.imageset
@bg = []
@ct_game_timer.ct_properties.imageset.each do |i|
@bg[@index] = Cache.load_bitmap("Graphics/Pictures/", i.filename, 0)
@Index = @Index + 1
end
end
create_bitmap
create_font
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# * Create Bitmap
#--------------------------------------------------------------------------
def create_bitmap
self.bitmap = Bitmap.new(@ct_game_timer.ct_properties.width,
@ct_game_timer.ct_properties.height)
end
#--------------------------------------------------------------------------
# * Create Font
#--------------------------------------------------------------------------
def create_font
self.bitmap.font.name = @ct_game_timer.ct_properties.textset.font.name
self.bitmap.font.outline = @ct_game_timer.ct_properties.textset.font.outline
self.bitmap.font.shadow = @ct_game_timer.ct_properties.textset.font.shadow
self.bitmap.font.bold = @ct_game_timer.ct_properties.textset.font.bold
self.bitmap.font.italic = @ct_game_timer.ct_properties.textset.font.italic
self.bitmap.font.size = @ct_game_timer.ct_properties.textset.font.size
self.bitmap.font.color.set(@ct_game_timer.ct_properties.textset.font.color[0],
@ct_game_timer.ct_properties.textset.font.color[1],
@ct_game_timer.ct_properties.textset.font.color[2])
self.bitmap.font.out_color.set(@ct_game_timer.ct_properties.textset.font.outline_color[0],
@ct_game_timer.ct_properties.textset.font.outline_color[1],
@ct_game_timer.ct_properties.textset.font.outline_color[2])
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @ct_game_timer.ct_properties.hide_timer_switch_id
if not $game_switches[@ct_game_timer.ct_properties.hide_timer_switch_id]
super
update_bitmap
update_position
update_visibility
else
self.visible = false
end
else
super
update_bitmap
update_position
update_visibility
end
end
#--------------------------------------------------------------------------
# * Update Transfer Origin Bitmap
#--------------------------------------------------------------------------
def update_bitmap
if @ct_game_timer.sec != @total_sec
@total_sec = @ct_game_timer.sec
if @ct_game_timer.ct_properties.schedule
@ct_game_timer.ct_properties.schedule.each do |i|
if i.mode == "time range"
v1 = (i.start_min * 60) + (i.start_sec + 1)
v2 = (i.end_min * 60) + (i.end_sec + 1)
if @ct_game_timer.sec <= (v1) && @ct_game_timer.sec >= (v2)
if i.type == "common event"
$game_temp.reserve_common_event(i.id)
end
end
end
end
end
redraw
end
end
#--------------------------------------------------------------------------
# * Redraw
#--------------------------------------------------------------------------
def redraw
self.bitmap.clear
@Index = 0
if @bg
@bg.each do |i|
self.bitmap.stretch_blt(self.bitmap.rect, i, i.rect, @ct_game_timer.ct_properties.imageset[@index].opacity)
@Index = @Index + 1
end
end
self.bitmap.draw_text(self.bitmap.rect, timer_text, 1)
end
#--------------------------------------------------------------------------
# * Create Text
#--------------------------------------------------------------------------
def timer_text
sprintf(@ct_game_timer.ct_properties.textset.prefix +
"%02d:%02d" + @ct_game_timer.ct_properties.textset.suffix,
@total_sec / 60, @total_sec % 60)
end
#--------------------------------------------------------------------------
# * Update Position
#--------------------------------------------------------------------------
def update_position
self.x = @ct_game_timer.ct_properties.x
self.y = @ct_game_timer.ct_properties.y
self.z = @ct_game_timer.ct_properties.z
end
#--------------------------------------------------------------------------
# * Update Visibility
#--------------------------------------------------------------------------
def update_visibility
self.visible = @ct_game_timer.working?
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================
class Spriteset_Map
attr_accessor :ct_timer_sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :my_init :initialize
def initialize()
create_ct_timers()
my_init
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
alias :my_dispose :dispose
def dispose
my_dispose
dispose_ct_timers
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
update_ct_timers
end
#--------------------------------------------------------------------------
# * Create CT_Timer Sprites
#--------------------------------------------------------------------------
def create_ct_timers(ct_game_timer = $ct_game_timer)
@ct_timer_sprite = []
@Index = 0
ct_game_timer.each do |i|
@ct_timer_sprite[@index] = CT_Sprite_Timer.new(@viewport2, i)
@Index = @Index + 1
end
end
#--------------------------------------------------------------------------
# * Free CT_Timer Sprite
#--------------------------------------------------------------------------
def dispose_ct_timers
@ct_timer_sprite.each do |i|
i.dispose
end
end
#--------------------------------------------------------------------------
# * Update CT_Timer Sprite
#--------------------------------------------------------------------------
def update_ct_timers
@ct_timer_sprite.each do |i|
i.update
end
end
end
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================
class Spriteset_Battle
attr_accessor :ct_timer_sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :my_init :initialize
def initialize()
create_ct_timers()
my_init
update
end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
alias :my_dispose :dispose
def dispose
my_dispose
dispose_ct_timers
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
update_ct_timers
end
#--------------------------------------------------------------------------
# * Create CT_Timer Sprites
#--------------------------------------------------------------------------
def create_ct_timers(ct_game_timer = $ct_game_timer)
@ct_timer_sprite = []
@Index = 0
ct_game_timer.each do |i|
@ct_timer_sprite[@index] = CT_Sprite_Timer.new(@viewport2, i)
@Index = @Index + 1
end
end
#--------------------------------------------------------------------------
# * Free CT_Timer Sprite
#--------------------------------------------------------------------------
def dispose_ct_timers
@ct_timer_sprite.each do |i|
i.dispose
end
end
#--------------------------------------------------------------------------
# * Update CT_Timer Sprite
#--------------------------------------------------------------------------
def update_ct_timers
@ct_timer_sprite.each do |i|
i.update
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
attr_accessor :ct_timer
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
alias :my_start :start
def start
my_start
@ct_timer = $ct_game_timer
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
my_update
@ct_timer.each do |i|
i.update
end
update_scene if scene_change_ok?
end
end
#==============================================================================
# ** BattleManager
#------------------------------------------------------------------------------
#
#==============================================================================
module BattleManager
class << self
alias_method🙂my_battle_start, :battle_start)
alias_method🙂my_battle_end, :battle_end)
end
def self.battle_start
$ct_game_timer.each do |i|
if i.ct_properties.pause_in_battle_switch_id
if $game_switches[i.ct_properties.pause_in_battle_switch_id]
i.paused = true
end
end
end
my_battle_start
end
def self.battle_end(result)
$ct_game_timer.each do |i|
if i.ct_properties.pause_in_battle_switch_id
if $game_switches[i.ct_properties.pause_in_battle_switch_id]
i.paused = false
end
end
end
my_battle_end(result)
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle < Scene_Base
attr_accessor :ct_timer
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
alias :my_start :start
def start
my_start
@ct_timer = $ct_game_timer
@old_continue = true
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :my_update :update
def update
@paused_timer = false
@accept_input = false
@wait_for_timer = false
@continue = true
@ct_timer.each do |i|
if i.active?
if i.ct_properties.pause_in_battle_switch_id
@paused_timer = i.paused
end
if i.ct_properties.accept_input_switch_id
@accept_input = $game_switches[i.ct_properties.accept_input_switch_id]
end
if i.ct_properties.wait_for_timer_switch_id
@wait_for_timer = $game_switches[i.ct_properties.wait_for_timer_switch_id]
end
end
end
if @wait_for_timer && !@paused_timer
super
@continue = false
else
if @old_continue != @continue
turn_end
end
my_update
end
@old_continue = @continue
end
#--------------------------------------------------------------------------
# * Update Frame (Basic)
#--------------------------------------------------------------------------
alias :my_update_basic :update_basic
def update_basic
my_update_basic
@ct_timer.each do |i|
i.update
end
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * ct_timer
# Use this to set up a ct_timer
#--------------------------------------------------------------------------
def ct_timer(mins = 0, secs = 0, ct_game_timer = $ct_game_timer[0], start = true, ct_audio = nil)
mins = 0 unless mins
secs = 0 unless secs
if ct_game_timer
if ct_game_timer.class.to_s.downcase == "fixnum"
ct_game_timer = $ct_game_timer[ct_game_timer]
end
end
ct_game_timer = $ct_game_timer[0] unless ct_game_timer
start = false unless start
if start # Start
v = (mins * 60) + secs
ct_game_timer.ct_audio = ct_audio
ct_game_timer.start(v * Graphics.frame_rate)
else # Stop
ct_game_timer.stop
end
end
end
This honestly seems like a great script because it allows you to have multiple timers go off at once, or at least that what it seems to me. This would be very useful for my game.
However I can't seem to find any command that detects if a timer has reached 0.
For example, with rpg makers default timer, you can have it so once it reaches 0 it activates some event. It's pretty neat.
But in Ct's script I can't seem to find that feature?
Like if timer number 2 reaches 0 it activates an event, meanwhile timer number 3 is still counting down.
If that's not a feature available in this script, does anyone know of another script I can use?
Thank you.