Galv’s Event Spawn Timer V.1.1

Demo – Version 1.1 >

#------------------------------------------------------------------------------#
#  Galv's Event Spawn Timer
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.1
#------------------------------------------------------------------------------#
#  2013-02-24 - Version 1.1 - added script call to purge specified timer
#                           - changed name to Event Spawn Timer
#  2013-02-23 - Version 1.0 - release
#-------------------------------------------------------------------------------
#  This script allows you to set respawn timers for events and have them auto-
#  matically change a switch or self switch when their timer expires.
#
#  As the timer checks are made during the event movements, obviously these
#  switches will not be changed until the player gets close enough. This was my
#  idea at keeping any lag or checking billions of things at once down. Use the
#  other script calls to force check if you require it to work differently.
#-------------------------------------------------------------------------------
 
#-------------------------------------------------------------------------------
#  SCRIPT CALL in EVENT script box
#-------------------------------------------------------------------------------
#  set_spawn(map_id,event_id,time)   # set which map, event and how many seconds
#                                    # before respawn. Setting map or event id
#                                    # to 0 will use current map and event the
#                                    # script call was done in.
#-------------------------------------------------------------------------------
#  EXAMPLES:
#  set_spawn(1,2,20)    # Event 2 on map 1 will respawn in 20 seconds from now
#  set_spawn(0,0,200)   # The event this call is in will respawn in 200 seconds
#-------------------------------------------------------------------------------
 
#-------------------------------------------------------------------------------
#  SCRIPT in a MOVE ROUTE script
#-------------------------------------------------------------------------------
#  do_respawn?(switch,status)   # This will check if the time is elapsed and
#                               # if so it will change a switch or self switch
#                               # to the status (true or false).
#-------------------------------------------------------------------------------
#  EXAMPLES:
#  do_respawn?("A",false)    # Turns self switch A OFF if time elapses
#  do_respawn?(1,true)       # Turns switch 1 ON if time elapses
#-------------------------------------------------------------------------------
 
#-------------------------------------------------------------------------------
#  SCRIPT CALLS in EVENT script box
#-------------------------------------------------------------------------------
#  purge_respawn_timers            # Remove all activated timers
#  purge_timer(map_id,event_id)    # Remove specified active timer from list
#
#  do_all_respawn(switch,status)   # Checks all events with respawn timers and
#                                  # changes all their switches to true or false
#
#  do_map_respawn(map_id,switch,status)  # Same as above but only for the map
#                                        # you designate with map_id
#
#  do_e_respawn(map_id,event_id,switch,status)  # Same as above but check a
#                                               # specific event on a map
#
#  # These calls can be made anywhere to check and affect those events.
#-------------------------------------------------------------------------------
 
#-------------------------------------------------------------------------------
#  SCRIPT for CONTROL VARIABLES
#-------------------------------------------------------------------------------
#  respawn_time(map_id,event_id)    # Get amount of time left until respawn for
#                                   # an event. Can use 0,0 to check the event
#                                   # and map the control variable is used on.
#-------------------------------------------------------------------------------
 
class Game_Event < Game_Character
  def do_respawn?(switch,status)
    return if !$game_system.spawn_timer[[@map_id,@id]]
    if $game_system.playtime >= $game_system.spawn_timer[[@map_id,@id]]
      if switch.is_a?(String)
        $game_self_switches[[@map_id, @id, switch]] = status
      elsif switch.is_a?(Numeric)
        $game_switches[switch] = status
      end
      $game_system.spawn_timer.delete([@map_id,@id])
    end
  end
end
 
class Game_System
  attr_accessor :spawn_timer
 
  alias galv_spawn_timer_game_system_initialize initialize
  def initialize
    @spawn_timer = {}
    galv_spawn_timer_game_system_initialize
  end
end
 
class Game_Interpreter
  def set_spawn(map_id,event_id,time)
    event_id = @event_id if event_id == 0
    map_id = $game_map.map_id if map_id == 0
    $game_system.spawn_timer[[map_id,event_id]] = $game_system.playtime + time
  end
 
  def do_all_respawn(switch,status)
    # set ALL stored respawn events to do this if timers are up
    $game_system.spawn_timer.each { |t|
      if $game_system.playtime >= t[1]
        if switch.is_a?(String)
          $game_self_switches[[t[0][0], t[0][1], switch]] = status
        elsif switch.is_a?(Numeric)
          $game_switches[switch] = status
        end
        $game_system.spawn_timer.delete(t[0])
      end
    }
  end
 
  def do_map_respawn(map_id,switch,status)
    # check all stored respawn events for a MAP to change if timers are up
    $game_system.spawn_timer.each { |t|
      next if t[0][0] != map_id
      if $game_system.playtime >= t[1]
        if switch.is_a?(String)
          $game_self_switches[[t[0][0], t[0][1], switch]] = status
        elsif switch.is_a?(Numeric)
          $game_switches[switch] = status
        end
        $game_system.spawn_timer.delete(t[0])
      end
    }
  end
 
  def do_e_respawn(map_id,event_id,switch,status)
    # check stored respawn event for a MAP to change if timer is up
    $game_system.spawn_timer.each { |t|
      next if t[0][0] != map_id
      next if t[0][1] != event_id
      if $game_system.playtime >= t[1]
        if switch.is_a?(String)
          $game_self_switches[[t[0][0], t[0][1], switch]] = status
        elsif switch.is_a?(Numeric)
          $game_switches[switch] = status
        end
        $game_system.spawn_timer.delete(t[0])
      end
    }
  end
 
  def respawn_time(map_id,event_id)
    # returns respawn time
    event_id = @event_id if event_id == 0
    map_id = $game_map.map_id if map_id == 0
    if $game_system.spawn_timer[[map_id,event_id]].nil?
      return 0
    else
      return $game_system.spawn_timer[[map_id,event_id]] - $game_system.playtime
    end
  end
 
  def purge_respawn_timers
    $game_system.spawn_timer = {}
  end
 
  def purge_timer(map_id,event_id)
    return if $game_system.spawn_timer[[map_id,event_id]].nil?
    $game_system.spawn_timer.delete([map_id,event_id])
  end
end

5 thoughts on “Galv’s Event Spawn Timer V.1.1

  1. Ruy says:

    Is this thread dead? last update 2013 (script)
    I have a question, considering the script:

    I have a setup dat involves farming, with 2 growth stages and then the main “full plant stage” but i can not get it to work properly. It goes to the 2nd stage like it should but then is stuck untill i (action button) the plant.

    Some one mentioned the second timer needed part, but i just seem to be lost on the subject. Can you help?

  2. bloodfayte says:

    Great script that helped me out a lot. Ty pal..

  3. logan says:

    my game gets a game interpreter crash every time i try to call this script? is this script no longer compatible?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s