SHARE
TWEET

[RMXP] Incremental Wait Timers 1.1

ForeverZer0 May 21st, 2011 295 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Incremental Wait Timers
  3. # Author: ForeverZer0
  4. # Date: 5.9.2011
  5. # Version: 1.1
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. # Explanation:
  9. #
  10. #  This is a little scripting tool I made to schedule events through scripting
  11. #  or script calls a little easier without the need create custom timers for
  12. #  everything. It will also eliminate the need to create a common event if you
  13. #  wanted to have a script call after a "Wait" command, but it would be cleared
  14. #  if the player walked off the current map when in a normal event.
  15. #
  16. # Instructions:
  17. #
  18. #   Either through a script or script call, use the following commands:
  19. #
  20. #     - $game_system.wait(FRAME_WAIT, 'STRING1', STRING2, etc, etc)
  21. #
  22. #     - $game_system.pause_timers(true/false)
  23. #
  24. #   The first command is the one to add timers. The first argument is the number
  25. #   of frames to wait before executing. The timers will run so long as the
  26. #   update method of $game_system is called, which by default is during
  27. #   Scene_Map and Scene_Battle. Any arguments after the first must being written
  28. #   as strings, that is with either single (' ') or double (" ") quotes around
  29. #   them. These strings will be passed to the Kernel.eval method when the timer
  30. #   reaches 0.
  31. #
  32. #   The second script call will pause the timers and keep them from updating.
  33. #   "true" will pause them, while "false" will unpause them.
  34. #
  35. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  36.  
  37. class Game_System
  38.  
  39.   attr_reader :wait_timer
  40.   attr_reader :paused
  41.  
  42.   alias zer0_wait_timers_init initialize
  43.   def initialize
  44.     zer0_wait_timers_init
  45.     # Initialize instance variables
  46.     @wait_timers, @timers_paused = [], false
  47.   end
  48.  
  49.   alias zer0_wait_timers_upd update
  50.   def update
  51.     if !@timers_paused && @wait_timers.size > 0
  52.       # Iterate throught timers and reduce wait time for each by 1
  53.       @wait_timers.each {|timer|
  54.         timer[0] -= 1
  55.         # Execute all script calls and remove timer when timer reaches 0
  56.         if timer[0] <= 0
  57.           (1...timer.size).each {|i| eval(timer[i]) }
  58.           @wait_timers -= [timer]
  59.         end
  60.       }
  61.     end
  62.     # Normal update method of Game_System
  63.     zer0_wait_timers_upd
  64.   end
  65.  
  66.   def clear_timers
  67.     # Clear timers by settiing array to an empty array
  68.     @wait_timers = []
  69.   end
  70.  
  71.   def pause_timers(bool = true)
  72.     # Set bool value for "pause"
  73.     @timers_paused = bool
  74.   end
  75.  
  76.   def wait(*args)
  77.     # Add supplied array of arguments to the timer queue
  78.     @wait_timers.push(args)
  79.   end
  80. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top