Main Menu

Multi-timers - set and forget timers for game switches and event self switches

Started by shaz, August 30, 2009, 12:36:47 AM

0 Members and 1 Guest are viewing this topic.

shaz

Multi-timers
Version: 1.0
Author: Shaz
Date: August 30, 2009

Version History




  • 1.0  08.30.2009 Original

Planned Future Versions


  • Allow timer to be turned on OR off

Description



This script allows you to set timers to turn on an unlimited number of switches or event self switches after a set delay.  

Features


  • No need to use variables and conditions required by the Control Timer event command
  • Set the timer and forget it - the script takes care of checking when the timer is up, and updates the switches and self switches for you
  • Unlimited number of switches and self switches, each with their own delay
  • Can have multiple timers running at once without affecting each other

Instructions

Copy the entire script below into a new slot above Main and below all other scripts.

Create a Script event command, and place the call to $game_system.set_timer inside with the appropriate arguments.

To set a timer for switch 15 to be turned on in 30 minutes, use $game_system.set_timer(30, 15)
Have an event or common event that's conditioned to run when switch 15 is on.
Make sure you turn the switch off again if you only want it to run once.

To set a timer for self switch A on map 8, event 32 to be turned on in 45 seconds (3/4 or 0.75 of a minute), use $game_system.set_timer(0.75, [8, 32, 'A'])
You can also use $game_map.map_id and @event_id if you're referring to the current event on the current map: $game_system.set_timer(0.75, [$game_map.map_id, @event_id, 'A'])

Script




#==============================================================================
# ? Multi_Timer
#------------------------------------------------------------------------------
#   This script allows you to set up multiple timers in your game, to
#   turn on game switches or event self switches after a set delay.
#
#   To set a timer to turn a switch on, call
#     $game_system.set_timer(minutes, switch)
#
#   To set a timer to turn a self switch on, call
#     $game_system.set_timer(minutes, [mapid, eventid, selfswitch])
#
#   This switch or self switch will be turned on when the time elapses.
#   The trigger is then removed from the list of timers.
#   Self switches can be set & turned on even if you're not on that map.
#
#   Note - for fractions of minutes, pass in 0.5 rather than .5
#==============================================================================

class Game_System
 #--------------------------------------------------------------------------
 # ? Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :event_timer              # Switch/SelfSwitch timer
 
 #--------------------------------------------------------------------------
 # * Alias Listings
 #--------------------------------------------------------------------------
 alias_method :shaz_game_system_init, :initialize
 alias_method :shaz_game_system_update, :update
 
 #--------------------------------------------------------------------------
 # ? Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   shaz_game_system_init
   @event_timer = {}
 end

 #--------------------------------------------------------------------------
 # ? Update
 #--------------------------------------------------------------------------
 def update
   shaz_game_system_update
   check_event_timers
 end
 
 #--------------------------------------------------------------------------
 # ? Set an event timer to trigger a switch or a self switch
 #--------------------------------------------------------------------------    
 def set_timer(minutes, key)
   # If you're introducing this into a game where players will have saved files,
   # uncomment the following line to avoid nil object errors
   # @event_timer = {} if @event_timer == nil
   
   # this is the frame_count at which the event should trigger,
   # based on the current frame rate
   @event_timer[key] = Graphics.frame_count + (minutes * 60 * Graphics.frame_rate)
 end
 
 #--------------------------------------------------------------------------
 # ? Check event timers
 #--------------------------------------------------------------------------    
 def check_event_timers
   @event_timer.each do |key, value|
     if value <= Graphics.frame_count
       if key.is_a?(Array)
         $game_self_switches[key] = true
         $game_map.events[key[1]].refresh if key[0] == $game_map.map_id
       else
         $game_switches[key] = true
         $game_map.refresh
       end
       @event_timer.delete(key)
     end
   end
 end
end  


Credit




  • Shaz

Thanks


  • lambchop, for whose game (Aveyond: The Lost Orb) the script was made

Support



Post questions in this thread or send me a PM

Known Compatibility Issues

This should not have any compatibility issues with any other systems, unless one of them defines @event_timer, set_timer or check_event_timers for $game_system.

Demo



Demo attached.
The male NPC and the event in the top left corner combine to show an example of setting switches using the timer (NPC sets switch, corner event is conditioned by switch).
The flowers along the back provide examples of setting event self-switches using the timer.



Always remember you're unique.
Just like everybody else.

shaz

Ugh!  I can't believe I posted this in VX scripts! 

Can a mod please move it to XP for me?  Sorry...
Always remember you're unique.
Just like everybody else.

Grafikal

This is an XP script, not VX. Careful where ya post. I moved it for ya.

edit:: lol, i moved it before you posted that comment ~ im just slow on the upkeep here typing these things :P

shaz

Always remember you're unique.
Just like everybody else.

turdalmighty

This is very useful. I've been looking for something like this for my game. Thanks!

modern algebra


shaz

not nearly as fancy as yours, but even little scripts can be handy ;)

I'm going to update it over the weekend to allow a timer to turn a switch ON or OFF.
Always remember you're unique.
Just like everybody else.