RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Multi-timers - set and forget timers for game switches and event self switches

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 87
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


Code: [Select]
#==============================================================================
# ? 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.



« Last Edit: August 30, 2009, 01:37:39 AM by shaz »
Always remember you're unique.
Just like everybody else.

*
Rep:
Level 87
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.

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
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

*
Rep:
Level 87
lol - no - you're fast.  Lightning fast!

Thanks :)
Always remember you're unique.
Just like everybody else.

**
Rep: +0/-0Level 83
This is very useful. I've been looking for something like this for my game. Thanks!

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
This is a great script. Nice work, shaz!

*
Rep:
Level 87
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.