Multiple Timers 3.44 (Updated 03/16/11!)

Multiple Timers Version: 3.44
By: Glitchfinder


Introduction

Glitchfinder's Multiple Timers is a script intended for those who need to juggle several different timers at the same time, but want to avoid the hassle of scripting loops or adding new events to a map or battle. This script has been tested in both events and scripts, and will work in both RPG Maker XP and RPG Maker VX.

Features

  • Control, update, and check multiple timers dynamically!
  • Timers are independent of each other!
  • Individual timers may be updated independently!
  • Timers are automatically removed once completed and checked!
  • Timers can be displayed on screen!
  • Individual timers can be saved with the game!
  • Individual timers can be set to end battle when finished

Screenshots

Since the only visual elements of this script are identical to the default in-game timer, there is no point in showing any screenshots of it.

Script

  1. #≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  2. # ** Glitchfinder's Multiple Timers               [RPG Maker XP] [RPG Maker VX]
  3. #    Version 3.44
  4. #------------------------------------------------------------------------------
  5. #  This script helps scripters and eventers use multiple hidden in-game timers
  6. #  that can be called and modified at any time. Refer to "Game_Timer" for the
  7. #  instance of this class.
  8. #==============================================================================
  9. # * Version History
  10. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11. #   Version 1.00 ------------------------------------------------- (??????????)
  12. #     - Initial version
  13. #     - Author: Glitchfinder
  14. #   Version 2.00 ------------------------------------------------- (2008-06-11)
  15. #     - Script completely rewritten to work with multiple timers
  16. #     - Author: Glitchfinder
  17. #    Version 2.10 ------------------------------------------------ (2002-06-18)
  18. #      - Added the check_timing() method
  19. #      - Fixed bug with check() method
  20. #      - Author: Glitchfinder
  21. #     Version 2.11 ----------------------------------------------- (2007-06-19)
  22. #       - Reformatted and cleaned script
  23. #       - Author: Glitchfinder
  24. #    Version 2.21 ------------------------------------------------ (2007-06-22)
  25. #      - Added the extended_start() method
  26. #      - Author: Glitchfinder
  27. #    Version 2.31 ------------------------------------------------ (2007-07-20)
  28. #      - Added the update_single() method
  29. #      - Added the kill_timer() method
  30. #      - Added the adjust_time() method
  31. #      - Author: Glitchfinder
  32. #     Version 2.32 ----------------------------------------------- (2007-07-24)
  33. #       - Fixed bug with VX and the start() method
  34. #       - Fixed bug with VX and the extended_start() method
  35. #       - Author: Glitchfinder
  36. #   Version 3.32 ------------------------------------------------- (2009-06-28)
  37. #     - Script completely rewritten to increase efficiency
  38. #     - Modified most methods to include error-checking
  39. #     - Renamed the check() method to finished?()
  40. #     - Removed the modifications of Game_Temp
  41. #     - Added the script to the global variable $game_timer
  42. #     - Added new output to the check_timing() method
  43. #     - Modified the update() method of Scene_Battle
  44. #     - Added the ability for a timer to end battle
  45. #     - Added the end_battle() method
  46. #     - Added the end_battle?() method
  47. #     - Modified the update() method of Sprite_Timer
  48. #     - Added the ability to display a timer using Sprite_Timer
  49. #     - Modified the "Conditional Branch..." event command
  50. #     - Modified the "Control Variables..." event command
  51. #     - Modified the "Control Timer..." event command
  52. #     - Replaced the default timer with $game_timer
  53. #     - Added the display() method
  54. #     - Added the display?() method
  55. #     - Modified the write_save_data() method of Scene_Save
  56. #     - Modified the read_save_data() method of Scene_Load
  57. #     - Added the ability to save a timer when the game is saved
  58. #     - Added the save() method
  59. #     - Added the save?() method
  60. #     - Added the load_save() method
  61. #     - Author: Glitchfinder
  62. #     Version 3.33 ----------------------------------------------- (2009-06-28)
  63. #       - Script optimized further
  64. #       - Unnecessary lines removed
  65. #       - Code efficiency improved
  66. #       - Author: theory
  67. #     Version 3.34 ----------------------------------------------- (2009-06-29)
  68. #       - Script optimized
  69. #       - Unnecessary lines removed
  70. #       - Author: Glitchfinder
  71. #     Version 3.44 ----------------------------------------------- (2011-03-16)
  72. #       - Fixed Crash on F12
  73. #       - Converted $game_timer global into the Game_Timer module.
  74. #       - Author: Glitchfinder
  75. #==============================================================================
  76. # * Instructions
  77. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  78. #  Place this script above Main, and below the default scripts. (I realize this
  79. #  is obvious to most, but some people don't get it.)
  80. #
  81. #  To start a timer, use the following call:
  82. #    Game_Timer.start(seconds, key)
  83. #  Where seconds is the number of seconds you want the timer to run, and
  84. #  key is the name of that specific timer. You must use a seperate name for
  85. #  every timer, because when one finishes, only the first script checking for
  86. #  that name will return with the timer completed.
  87. #
  88. #  To check whether or not a timer has finished, use the following call:
  89. #    Game_Timer.finished?(key)
  90. #  Where timer_number is the number of the timer that you need to check. See
  91. #  the rules above regarding key.
  92. #
  93. #  To remove a timer, use the following call:
  94. #    Game_Timer.kill_timer(key)
  95. #  Where key is the timer that you wish to remove.
  96. #
  97. #  To adjuct the time remaining on a timer, use the following call:
  98. #    Game_Timer.adjust_time(setting, value, key)
  99. #  Where value is the number you want to adjust by, key is the timer you want
  100. #  to adjust, and setting in the operation you want to perform. (1 to add
  101. #  frames, 2 to subtract frames, 3 to multiply, 4 to divide, and 5 to perform a
  102. #  modulus operation)
  103. #
  104. #  To stop or start a timer, use the following call:
  105. #    Game_Timer.active(key, bool)
  106. #  Where key is the timer you want to start or stop, and bool is true if you
  107. #  want to start the timer, and false if you want to stop it.
  108. #
  109. #  To have a timer force battles to abort when they reach zero, use the
  110. #  following call:
  111. #    Game_Timer.end_battle(key, bool)
  112. #  Where key is the timer you want to modify, and bool is true if you want it
  113. #  to abort battles while it is 0, and false if you don't.
  114. #
  115. #  To set a timer to display, use the following call:
  116. #    Game_Timer.display(key, bool)
  117. #  Where key is the timer you want to display, and bool is either true or
  118. #  false, depending on the desired result.
  119. #
  120. #  To set a timer to be saved in the save file, use the following call:
  121. #    Game_Timer.save(key, bool)
  122. #  Where key is the timer you want to have saved, and bool is true if you want
  123. #  the timer to be saved, and false if you want it to disappear when the game
  124. #  is closed.
  125. #==============================================================================
  126. # * Method List
  127. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  128. #  initialize
  129. #    Sets up the script. Intended for internal use only.
  130. #
  131. #  update
  132. #    Updates all timers. Although intended for internal use, may be added to
  133. #    other scenes to force a timer update elsewhere.
  134. #
  135. #  update_single(key)
  136. #    Updates a single timer, specified by key.
  137. #
  138. #  start(seconds, key)
  139. #    Set up a timer, which will be accessed in the future by using key.
  140. #
  141. #  extended_start(hours, minutes, seconds, key)
  142. #    Set up and extended timer. Functions in the same way as start().
  143. #
  144. #  finished?(key)
  145. #    Returns true if the timer specified by key has reached 0, false otherwise.
  146. #    This method will delete the checked timer if it has reached 0.
  147. #
  148. #  check_timing(key)
  149. #    Debugging method. Returns a variety of messages based on the current state
  150. #    of the timer specified by key.
  151. #
  152. #  kill_timer(key)
  153. #    Erases the timer specified by key.
  154. #
  155. #  adjust_time(setting, value, key)
  156. #    Adjusts the remaining time in the timer specified by key. Setting
  157. #    specifies an operation. (1 => addition, 2 => subtraction,
  158. #    3 => multiplication, 4 = division, 5 = modulus
  159. #
  160. #  active(key, bool)
  161. #    Sets the timer specified by key to active or inactive, based on whether
  162. #    bool is true or false.
  163. #
  164. #  active?(key)
  165. #    Returns true if the timer specified by key is active, and false otherwise.
  166. #
  167. #  end_battle(key, bool)
  168. #    When bool is set to true, this method sets the timer specified by key to
  169. #    abort battles when it reaches 0. Otherwise, the timer will not abort
  170. #    battles when it reaches 0.
  171. #
  172. #  end_battle?
  173. #    Checks to see if a timer that aborts battle has reached 0. Intended for
  174. #    internal use.
  175. #
  176. #  display(key, bool)
  177. #    If bool is set to true, will display the timer specified by key.
  178. #    Otherwise, the timer is not displayed. Please note that only one timer will
  179. #    be displayed at any given time, no matter how many are set to display.
  180. #
  181. #  display?
  182. #    Checks to see if a timer is being displayed, and reuturns remaining time.
  183. #    This method is intended for internal use only.
  184. #
  185. #  save(key, bool)
  186. #    If bool is set to true, the timer specified by key will be saved along
  187. #    with the rest of the game. If bool is false, the timer will be deleted
  188. #    when the game closes, even if a save was made.
  189. #
  190. #  save?
  191. #    Returns an array of all timers set to be saved. This method is intended
  192. #    for internal use only.
  193. #
  194. #  load_save(timers)
  195. #    Loads all timers in the timers variable. This method is intended for
  196. #    internal use, but could be used to create new timers as well.
  197. #
  198. #  conditional_branch(parameters)
  199. #    Part of the interpreter's conditional branch processing. Intended for
  200. #    internal use only.
  201. #
  202. #  control_variables(parameters)
  203. #    Part of the interpreter's control variable processing. Intended for
  204. #    internal use only.
  205. #
  206. #  control_timer(parameters)
  207. #    The interpreter's control timer processing. Intended for internal use
  208. #    only, although it could be used to create an event timer through scripts.
  209. #==============================================================================
  210. # *Glitchfinder's Advice
  211. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  212. #  This script is meant for people with at least a basic level of scripting
  213. #  knowledge and ability. If you are unsure of your abilities, or don't know
  214. #  how to script, then it would be a good idea to avoid this script.
  215. #
  216. #  This script has been tested in both scripts and events, and will function in
  217. #  both cases.
  218. #
  219. #  This script will function in both RPG Maker XP and RPG Maker VX.
  220. #==============================================================================
  221. # * Contact
  222. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  223. #  Glitchfinder, the author of this script, may be contacted through his
  224. #  website, found at http://www.glitchkey.com
  225. #
  226. #  You may also find Glitchfinder at http://www.hbgames.org
  227. #==============================================================================
  228. # * Usage
  229. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  230. #  This script may be used with the following terms and conditions:
  231. #
  232. #    1. This script is free to use in any noncommercial project. If you wish to
  233. #       use this script in a commercial (paid) project, please contact
  234. #       Glitchfinder at his website.
  235. #    2. This script may only be hosted at the following domains:
  236. #         http://www.glitchkey.com
  237. #         http://www.hbgames.org
  238. #    3. If you wish to host this script elsewhere, please contact Glitchfinder
  239. #       or theory.
  240. #    4. If you wish to translate this script, please contact Glitchfinder or
  241. #       or theory. They will need the web address that you plan to host the
  242. #       script at, as well as the language this script is being translated to.
  243. #    5. This header must remain intact at all times.
  244. #    6. Glitchfinder and theory remain the sole owners of this code. They may
  245. #       modify or revoke this license at any time, for any reason.
  246. #    7. Any code derived from code within this script is owned by Glitchfinder
  247. #       and theory, and you must have their permission to publish, host, or
  248. #       distribute their code.
  249. #    8. This license applies to all code derived from the code within this
  250. #       script.
  251. #    9. If you use this script within your project, you must include visible
  252. #       credit to Glitchfinder and theory, within reason.
  253. #≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  254.  
  255.  
  256. #==============================================================================
  257. # ** Sprite_Timer
  258. #------------------------------------------------------------------------------
  259. #  This sprite is used to display the timer.It observes the $game_system
  260. #  class and automatically changes sprite conditions.
  261. #==============================================================================
  262.  
  263. class Sprite_Timer < Sprite
  264.   #--------------------------------------------------------------------------
  265.   # * Frame Update
  266.   #--------------------------------------------------------------------------
  267.   def update
  268.     super
  269.     # Hide timer sprite and return if there is no currently displayed timer
  270.     self.visible = Game_Timer.display? == false ? false : true
  271.     return if self.visible == false
  272.     # If timer needs to be redrawn
  273.     if Game_Timer.display? / Graphics.frame_rate != @total_sec
  274.       # Calculate total number of seconds and make a string
  275.       @total_sec = Game_Timer.display? / Graphics.frame_rate
  276.       text = sprintf("%02d:%02d", @total_sec / 60, @total_sec % 60)
  277.       # Clear window contents and draw timer
  278.       self.bitmap.clear
  279.       self.bitmap.draw_text(self.bitmap.rect, text, 1)
  280.     end
  281.   end
  282. end
  283.  
  284. #----------------------------------------------------------------------------
  285. # * Check for RGSS1
  286. #----------------------------------------------------------------------------
  287. if !(defined?(Graphics.brightness))
  288.  
  289. #==============================================================================
  290. # ** Scene_Save
  291. #------------------------------------------------------------------------------
  292. #  This class performs save screen processing.
  293. #==============================================================================
  294.  
  295. class Scene_Save < Scene_File
  296.   #--------------------------------------------------------------------------
  297.   # * Alias Methods
  298.   #--------------------------------------------------------------------------
  299.   # If the method has not been aliased
  300.   unless method_defined?(:multiple_timers_write_save_data)
  301.     # Alias the method
  302.     alias multiple_timers_write_save_data write_save_data
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * Write Save Data
  306.   #     file : write file object (opened)
  307.   #--------------------------------------------------------------------------
  308.   def write_save_data(file)
  309.     # Call original method
  310.     multiple_timers_write_save_data(file)
  311.     # Write save data
  312.     Marshal.dump(Game_Timer.save?, file)
  313.   end
  314. end
  315.  
  316. #==============================================================================
  317. # ** Scene_Load
  318. #------------------------------------------------------------------------------
  319. #  This class performs load screen processing.
  320. #==============================================================================
  321.  
  322. class Scene_Load < Scene_File
  323.   #--------------------------------------------------------------------------
  324.   # * Alias Methods
  325.   #--------------------------------------------------------------------------
  326.   # If the method has not been aliased
  327.   unless method_defined?(:multiple_timers_read_save_data)
  328.     # Alias the method
  329.     alias multiple_timers_read_save_data read_save_data
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Read Save Data
  333.   #     file : file object for reading (opened)
  334.   #--------------------------------------------------------------------------
  335.   def read_save_data(file)
  336.     # Call original method
  337.     multiple_timers_read_save_data(file)
  338.     # Load saved data
  339.     Game_Timer.load_save(Marshal.load(file)) unless file.eof?
  340.   end
  341. end
  342.  
  343. #==============================================================================
  344. # ** Interpreter
  345. #------------------------------------------------------------------------------
  346. #  This interpreter runs event commands. This class is used within the
  347. #  Game_System class and the Game_Event class.
  348. #==============================================================================
  349.  
  350. class Interpreter
  351.   #--------------------------------------------------------------------------
  352.   # * Alias Methods
  353.   #--------------------------------------------------------------------------
  354.   # If the method has not been aliased
  355.   unless method_defined?(:multiple_timers_command_111)
  356.     # Alias the method
  357.     alias multiple_timers_command_111 command_111
  358.   end
  359.   # If the method has not been aliased
  360.   unless method_defined?(:multiple_timers_command_122)
  361.     # Alias the method
  362.     alias multiple_timers_command_122 command_122
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Conditional Branch
  366.   #--------------------------------------------------------------------------
  367.   def command_111
  368.     # Initialize local variable: result
  369.     result = false
  370.     # If checking timer
  371.     if @parameters[0] == 3
  372.       # Call modified method
  373.       result = Game_Timer.conditional_branch(@parameters)
  374.       # Skip if branch is false
  375.       return command_skip if result == false
  376.     end
  377.     # Store determinant results in hash
  378.     @branch[@list[@index].indent] = result
  379.     # If determinant results are true
  380.     if @branch[@list[@index].indent] == true
  381.       # Delete branch data
  382.       @branch.delete(@list[@index].indent)
  383.       # Continue
  384.       return true
  385.     end
  386.     # Call aliased method
  387.     multiple_timers_command_111
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * Control Variables
  391.   #--------------------------------------------------------------------------
  392.   def command_122
  393.     # Initialize value
  394.     value = 0
  395.     # If @parameters[3] is set to other
  396.     if @parameters[3] == 7
  397.       # If @parameters[4] is set to timer
  398.       if @parameters[4] == 5  # timer
  399.         # Call modified method
  400.         Game_Timer.control_variables(@parameters)
  401.         # Continue
  402.         return true
  403.       end
  404.     end
  405.     # Call aliased method
  406.     multiple_timers_command_122
  407.   end
  408.   #--------------------------------------------------------------------------
  409.   # * Control Timer
  410.   #--------------------------------------------------------------------------
  411.   def command_124
  412.     # Call modified method
  413.     Game_Timer.control_timer(@parameters)
  414.     # Continue
  415.     return true
  416.   end
  417. end
  418.  
  419. #----------------------------------------------------------------------------
  420. # * End Check for RGSS1
  421. #----------------------------------------------------------------------------
  422. end
  423.  
  424. #----------------------------------------------------------------------------
  425. # * Check for RGSS2
  426. #----------------------------------------------------------------------------
  427. if (defined?(Graphics.brightness) == true)
  428.  
  429. #==============================================================================
  430. # ** Scene_File
  431. #------------------------------------------------------------------------------
  432. #  This class performs the save and load screen processing.
  433. #==============================================================================
  434.  
  435. class Scene_File < Scene_Base
  436.   #--------------------------------------------------------------------------
  437.   # * Alias Methods
  438.   #--------------------------------------------------------------------------
  439.   # If the initialize method has not been aliased
  440.   unless method_defined?(:multiple_timers_write_save_data)
  441.     # Alias the enemy selection method
  442.     alias multiple_timers_write_save_data write_save_data
  443.   end
  444.   # If the initialize method has not been aliased
  445.   unless method_defined?(:multiple_timers_read_save_data)
  446.     # Alias the enemy selection method
  447.     alias multiple_timers_read_save_data read_save_data
  448.   end
  449.   #--------------------------------------------------------------------------
  450.   # * Write Save Data
  451.   #     file : write file object (opened)
  452.   #--------------------------------------------------------------------------
  453.   def write_save_data(file)
  454.     # Call original method
  455.     multiple_timers_write_save_data(file)
  456.     # Write save data
  457.     Marshal.dump(Game_Timer.save?, file)
  458.   end
  459.   #--------------------------------------------------------------------------
  460.   # * Read Save Data
  461.   #     file : file object for reading (opened)
  462.   #--------------------------------------------------------------------------
  463.   def read_save_data(file)
  464.     # Call original method
  465.     multiple_timers_read_save_data(file)
  466.     # Load saved data
  467.     Game_Timer.load_save(Marshal.load(file)) unless file.eof?
  468.   end
  469. end
  470.  
  471. #==============================================================================
  472. # ** Game_Interpreter
  473. #------------------------------------------------------------------------------
  474. #  An interpreter for executing event commands. This class is used within the
  475. # Game_Map, Game_Troop, and Game_Event classes.
  476. #==============================================================================
  477.  
  478. class Game_Interpreter
  479.   #--------------------------------------------------------------------------
  480.   # * Alias Methods
  481.   #--------------------------------------------------------------------------
  482.   # If the initialize method has not been aliased
  483.   unless method_defined?(:multiple_timers_command_111)
  484.     # Alias the enemy selection method
  485.     alias multiple_timers_command_111 command_111
  486.   end
  487.   # If the initialize method has not been aliased
  488.   unless method_defined?(:multiple_timers_command_122)
  489.     # Alias the enemy selection method
  490.     alias multiple_timers_command_122 command_122
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # * Conditional Branch
  494.   #--------------------------------------------------------------------------
  495.   def command_111
  496.     # Initialize local variable: result
  497.     result = false
  498.     # If checking timer
  499.     if @params[0] == 3
  500.       # Call modified method
  501.       result = Game_Timer.conditional_branch(@params)
  502.       # Skip if branch is false
  503.       return command_skip if reult == false
  504.     end
  505.     # Store determinant results in hash
  506.     @branch[@indent] = result
  507.     # If determinant results are true
  508.     if @branch[@indent] == true
  509.       # Delete branch data
  510.       @branch.delete(@indent)
  511.       # Continue
  512.       return true
  513.     end
  514.     # Call aliased method
  515.     multiple_timers_command_111
  516.   end
  517.   #--------------------------------------------------------------------------
  518.   # * Control Variables
  519.   #--------------------------------------------------------------------------
  520.   def command_122
  521.     # Initialize value
  522.     value = 0
  523.     # If @params[3] is set to other
  524.     if @params[3] == 7
  525.       # If @params[4] is set to timer
  526.       if @params[4] == 5  # timer
  527.         # Call modified method
  528.         Game_Timer.control_variables(@params)
  529.         # Continue
  530.         return true
  531.       end
  532.     end
  533.     # Call aliased method
  534.     multiple_timers_command_122
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # * Control Timer
  538.   #--------------------------------------------------------------------------
  539.   def command_124
  540.     # Call modified method
  541.     Game_Timer.control_timer(@params)
  542.     # Continue
  543.     return true
  544.   end
  545. end
  546.  
  547. #----------------------------------------------------------------------------
  548. # * End Check for RGSS2
  549. #----------------------------------------------------------------------------
  550. end
  551.  
  552. #==============================================================================
  553. # ** Scene_Map
  554. #------------------------------------------------------------------------------
  555. #  This class performs map screen processing.
  556. #==============================================================================
  557.  
  558. class Scene_Map
  559.   #--------------------------------------------------------------------------
  560.   # * Alias Methods
  561.   #--------------------------------------------------------------------------
  562.   # If the initialize method has not been aliased
  563.   unless method_defined?(:multiple_timers_update)
  564.     # Alias the enemy selection method
  565.     alias multiple_timers_update update
  566.   end
  567.   #--------------------------------------------------------------------------
  568.   # * Frame Update
  569.   #--------------------------------------------------------------------------
  570.   def update
  571.     # Call original method
  572.     multiple_timers_update
  573.     # Update Game_Timer
  574.     Game_Timer.update
  575.   end
  576. end
  577.  
  578. #==============================================================================
  579. # ** Scene_Battle
  580. #------------------------------------------------------------------------------
  581. #  This class performs battle screen processing.
  582. #==============================================================================
  583.  
  584. class Scene_Battle
  585.   #--------------------------------------------------------------------------
  586.   # * Alias Methods
  587.   #--------------------------------------------------------------------------
  588.   # If the initialize method has not been aliased
  589.   unless method_defined?(:multiple_timers_update)
  590.     # Alias the enemy selection method
  591.     alias multiple_timers_update update
  592.   end
  593.   #--------------------------------------------------------------------------
  594.   # * Frame Update
  595.   #--------------------------------------------------------------------------
  596.   def update
  597.     # Update Game_Timer
  598.     Game_Timer.update
  599.     # Abort Battle if an appropriate timer has ended
  600.     $game_temp.battle_abort = true if Game_Timer.end_battle?
  601.     # Call original method
  602.     multiple_timers_update
  603.   end
  604. end
  605.  
  606. #==============================================================================
  607. # ** Game_Timer
  608. #------------------------------------------------------------------------------
  609. #  This class performs processing for in-script timers.
  610. # Refer to "$game_temp.game_timer" for the instance of this class.
  611. #==============================================================================
  612.  
  613. module Game_Timer
  614.   #--------------------------------------------------------------------------
  615.   # * Object Initialization
  616.   #--------------------------------------------------------------------------
  617.   begin
  618.     # Create timer hash
  619.     Timers = {}
  620.     # Set timer hash defaults
  621.     Timers.default = {
  622.       'time' => 0,
  623.       'active' => false,
  624.       'display' => false,
  625.       'endbattle' => false,
  626.       'finished' => false,
  627.       'save' => false
  628.     }
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # * Frame Update
  632.   #--------------------------------------------------------------------------
  633.   def self.update
  634.     # Iterate through all timers
  635.     Timers.keys.each { |key|
  636.     # Skip if the current timer is inactive, otherwise deduct timer
  637.     Timers[key]['active'] == false ? next : Timers[key]['time'] -= 1
  638.     # Set the timer to finished if the frame count is 0 or less
  639.     Timers[key]['active'] = false and
  640.     Timers[key]['finished'] = true if Timers[key]['time'] <= 0}
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   # * Frame Update (individual timer)
  644.   #     key : key for specific timer
  645.   #--------------------------------------------------------------------------
  646.   def self.update_single(key)
  647.     # Return if the current timer is inactive, otherwise deduct timer
  648.     Timers[key]['active'] == false ? return : Timers[key]['time'] -= 1
  649.     # Set the timer to finished if the frame count is 0 or less
  650.     Timers[key]['active'] = false and
  651.     Timers[key]['finished'] = true if Timers[key]['time'] <= 0
  652.   end
  653.   #--------------------------------------------------------------------------
  654.   # * Start Timer
  655.   #     seconds : time, in seconds
  656.   #     key     : key for specific timer
  657.   #--------------------------------------------------------------------------
  658.   def self.start(seconds, key)
  659.     # Check the validity of the second value
  660.     unless seconds.is_a?(Integer)
  661.       # Print an error and exit if the second value is invalid
  662.       p "You must set a timer's remaining time to a numeric value"
  663.       exit
  664.     end
  665.     # Setup new timer
  666.     Timers[key] = {
  667.       'time' => seconds * Graphics.frame_rate,
  668.       'active' => true,
  669.       'display' => false,
  670.       'endbattle' => false,
  671.       'finished' => false,
  672.       'save' => false
  673.     }
  674.   end
  675.   #--------------------------------------------------------------------------
  676.   # * Start Timer (extended)
  677.   #     hours   : added hours (not including minutes or seconds)
  678.   #     minutes : added minutes (not including hours or seconds)
  679.   #     seconds : added seconds (not including hours or minutes)
  680.   #     key     : key for specific timer
  681.   #--------------------------------------------------------------------------
  682.   def self.extended_start(hours, minutes, seconds, key)
  683.     # Check the validity of the time value
  684.     unless (hours.is_a?(Integer) == true && minutes.is_a?(Integer) == true &&
  685.            seconds.is_a?(Integer) == true)
  686.       # Print an error and exit if the time value is invalid
  687.       p "You must set a timer's remaining time to a numeric value"
  688.       exit
  689.     end
  690.     # Calculate time
  691.     time = ((hours * 3600 * Graphics.frame_rate) +
  692.            (minutes * 60 * Graphics.frame_rate) +
  693.            (seconds * Graphics.frame_rate))
  694.     # Setup new timer
  695.     Timers[key] = {
  696.       'time' => time,
  697.       'active' => true,
  698.       'display' => false,
  699.       'endbattle' => false,
  700.       'finished' => false,
  701.       'save' => false
  702.     }
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # * Check Timer
  706.   #     key : key for specific timer
  707.   #--------------------------------------------------------------------------
  708.   def self.finished?(key)
  709.     # Return false if the timer has not finished
  710.     return false if Timers[key]['finished'] == false
  711.     # Delete timer
  712.     Timers.delete(key)
  713.     return true
  714.   end
  715.   #--------------------------------------------------------------------------
  716.   # * Check Timer (Debugging)
  717.   #     key : key for specific timer
  718.   #--------------------------------------------------------------------------
  719.   def self.check_timing(key)
  720.     return unless ($DEBUG == true || $TEST == true)
  721.     # If the Timers hash includes the key
  722.     if Timers.include?(key)
  723.       # If the timer has time remaining
  724.       if Timers[key]['finished'] == false
  725.         # Set up message and print
  726.         s = 'The timer named ' + key.to_s + ' has ' + Timers[key]['time'].to_s
  727.         s += ' frames remaining.'
  728.         p s
  729.       else
  730.         # Print message
  731.         p 'The timer named ' + key.to_s + ' has reached zero.'
  732.       end
  733.       # Print message if timer is inactive
  734.       if Timers[key]['active'] == false
  735.         p 'The timer named ' + key.to_s + ' is currently inactive.'
  736.       end
  737.       # Print message if timer is set to end battle
  738.       if Timers[key]['endbattle'] == true
  739.         p 'The timer named ' + key.to_s + ' is currently set to end battle.'
  740.       end
  741.       # print message if timer is set to be saved in the file
  742.       if Timers[key]['save'] == true
  743.         p 'The timer named ' + key.to_s + ' is currently saved with the game.'
  744.       end
  745.     else
  746.       # Print message if the timer does not exist
  747.       p 'The timer named ' + key.to_s + ' does not exist.'
  748.     end
  749.   end
  750.   #--------------------------------------------------------------------------
  751.   # * Kill Timer
  752.   #     key : key for specific timer
  753.   #--------------------------------------------------------------------------
  754.   def self.kill_timer(key)
  755.     # Delete the timer if it exists
  756.     Timers.delete(key) if Timers.include?(key)
  757.   end
  758.   #--------------------------------------------------------------------------
  759.   # * Adjust Remaining Time
  760.   #     setting : type of operation
  761.   #     value   : value to use in the operation
  762.   #     key     : key for specific timer
  763.   #--------------------------------------------------------------------------
  764.   def self.adjust_time(setting, value, key)
  765.     # Print an error and exit if the value is invalid
  766.     unless value.is_a?(Integer)
  767.       p "You must modify a timer's remaining time with a numeric value"
  768.       exit
  769.     end
  770.     # Print an error and exit if the setting is invalid
  771.     unless (setting >= 1 && setting <= 5)
  772.       p "You have used an invalid setting when modifying the timer."
  773.       exit
  774.     end
  775.     # Perform the appropriate math function based on setting variable
  776.     case setting    
  777.     when 1 then Timers[key]['time'] += value
  778.     when 2 then Timers[key]['time'] -= value
  779.     when 3 then Timers[key]['time'] *= value
  780.     when 4 then Timers[key]['time'] /= value
  781.     when 5 then Timers[key]['time'] %= value
  782.     end
  783.   end
  784.   #--------------------------------------------------------------------------
  785.   # * Set Timer's Active Boolean
  786.   #     key  : key for specific timer
  787.   #     bool : true or false, where true ends battle when timer is at 0
  788.   #--------------------------------------------------------------------------
  789.   def self.active(key, bool)
  790.     # Check bool's validity
  791.     unless (bool == true || bool == false)
  792.       # Print an error and exit if bool is invalid
  793.       p "You must set a timer's active boolean to either true or false."
  794.       exit
  795.     end
  796.     # Set timer boolean if it exists
  797.     Timers[key]['active'] == bool if Timers.include?(key)
  798.   end
  799.   #--------------------------------------------------------------------------
  800.   # * Timer Active?
  801.   #     key : key for specific timer
  802.   #--------------------------------------------------------------------------
  803.   def self.active?(key)
  804.     # Return active value for specified timer
  805.     return Timers[key]['active']
  806.   end
  807.   #--------------------------------------------------------------------------
  808.   # * Set Timer's End Battle Boolean
  809.   #     key  : key for specific timer
  810.   #     bool : true or false, where true ends battle when timer is at 0
  811.   #--------------------------------------------------------------------------
  812.   def self.end_battle(key, bool)
  813.     # Check bool's validity
  814.     unless (bool == true || bool == false)
  815.       # Print an error and exit if bool is invalid
  816.       p "You must set a timer's end battle boolean to either true or false."
  817.       exit
  818.     end
  819.     # Set timer boolean if it exists
  820.     Timers[key]['endbattle'] == bool if Timers.include?(key)
  821.   end
  822.   #--------------------------------------------------------------------------
  823.   # * End Battle?
  824.   #--------------------------------------------------------------------------
  825.   def self.end_battle?
  826.     # Iterate through all timers
  827.     Timers.keys.each {|key| next if Timers[key]['active'] == false
  828.     # Return true if the timer is finished and is set to end battle
  829.     return true if Timers[key]['endbattle'] && Timers[key]['time'] <= 0}
  830.     return false
  831.   end
  832.   #--------------------------------------------------------------------------
  833.   # * Set Timer's Display Boolean
  834.   #     key  : key for specific timer
  835.   #     bool : true or false, where true means the timer is displayed
  836.   #--------------------------------------------------------------------------
  837.   def self.display(key, bool)
  838.     # Check bool's validity
  839.     unless (bool == true || bool == false)
  840.       # Print an error and exit if bool is invalid
  841.       p "You must set a timer's display boolean to either true or false."
  842.       exit
  843.     end
  844.     # Set timer boolean if it exists
  845.     Timers[key]['display'] = bool if Timers.include?(key)
  846.   end
  847.   #--------------------------------------------------------------------------
  848.   # * Display Timer?
  849.   #--------------------------------------------------------------------------
  850.   def self.display?
  851.     # Iterate through all timers
  852.     Timers.keys.each {|key| next if Timers[key]['active'] == false
  853.     # Return remaining time if the timer is set to display
  854.     return Timers[key]['time'] if Timers[key]['display'] == true}
  855.     return false
  856.   end
  857.   #--------------------------------------------------------------------------
  858.   # * Set Timer's Save Boolean
  859.   #     key  : key for specific timer
  860.   #     bool : true or false, where true means the timer is displayed
  861.   #--------------------------------------------------------------------------
  862.   def self.save(key, bool)
  863.     # Check bool's validity
  864.     unless (bool == true || bool == false)
  865.       # Print an error and exit if bool is invalid
  866.       p "You must set a timer's save boolean to either true or false."
  867.       exit
  868.     end
  869.     # Set timer boolean if it exists
  870.     Timers[key]['save'] = bool if Timers.include?(key)
  871.   end
  872.   #--------------------------------------------------------------------------
  873.   # * Save Timer?
  874.   #--------------------------------------------------------------------------
  875.   def self.save?
  876.     # Setup save hash
  877.     save = {}
  878.     # Iterate through timers and add the timer to the hash if it is set to save
  879.     Timers.keys.each{|x| save[x] = Timers[x] if Timers[x]['save'] == true}
  880.     return save
  881.   end
  882.   #--------------------------------------------------------------------------
  883.   # * Load Saved Timer
  884.   #--------------------------------------------------------------------------
  885.   def self.load_save(timers)
  886.     # Add timers to hash if any have been loaded
  887.     timers.keys.each {|key| Timers[key] = timers[key]} unless timers.empty?
  888.   end
  889.   #--------------------------------------------------------------------------
  890.   # * Conditional Branch
  891.   #--------------------------------------------------------------------------
  892.   def self.conditional_branch(parameters)
  893.     # If event timer is active
  894.     if active?('event')
  895.       # Set timer variable to currently displayed timer
  896.       timer = display?
  897.       # Skip command if no timer is currently displayed
  898.       return false if timer == false
  899.       # Calculate remaining timer
  900.       sec = timer / Graphics.frame_rate
  901.       # If checking for a value <= remaining time
  902.       if parameters[2] == 0
  903.         # set result to the truth value of remaining time >= checked time
  904.         result = (sec >= parameters[1])
  905.       else
  906.         # set result to the truth value of remaining time <= checked time
  907.         result = (sec <= parameters[1])
  908.       end
  909.     else
  910.       # Skip command if timer is not active
  911.       return false
  912.     end
  913.   end
  914.   #--------------------------------------------------------------------------
  915.   # * Control Variables
  916.   #--------------------------------------------------------------------------
  917.   def self.control_variables(parameters)
  918.     timer = display?
  919.     timer = 0 if timer == false
  920.     value = timer / Graphics.frame_rate
  921.     # Loop for group control
  922.     for i in parameters[0] .. parameters[1]
  923.       # Branch with control
  924.       case parameters[2]
  925.       when 0 then $game_variables[i] = value
  926.       when 1 then $game_variables[i] += value
  927.       when 2 then$game_variables[i] -= value
  928.       when 3 then $game_variables[i] *= value
  929.       when 4  # divide
  930.         if value != 0
  931.           $game_variables[i] /= value
  932.         end
  933.       when 5  # remainder
  934.         if value != 0
  935.           $game_variables[i] %= value
  936.         end
  937.       end
  938.       # Max / Min limit check
  939.       $game_variables[i] = 99999999 if $game_variables[i] > 99999999
  940.       $game_variables[i] = -99999999 if $game_variables[i] < -99999999
  941.     end
  942.     # Refresh map
  943.     $game_map.need_refresh = true
  944.   end
  945.   #--------------------------------------------------------------------------
  946.   # * Control Timer
  947.   #--------------------------------------------------------------------------
  948.   def self.control_timer(parameters)
  949.     # If started
  950.     if parameters[0] == 0
  951.       # Start timer
  952.       Game_Timer.start(parameters[1], 'event')
  953.       # Set timer to end battle
  954.       Game_Timer.end_battle('event', true)
  955.       # Display timer
  956.       Game_Timer.display('event', true)
  957.       # Set timer to save with game
  958.       Game_Timer.save('event', true)
  959.     # If stopped
  960.     else
  961.       # Hide timer
  962.       Game_Timer.active('event', false)
  963.     end
  964.   end
  965. end
Expand to see the code.


Instructions

Place this script above Main, and below the default scripts. (I realize this is obvious to most, but some people don't get it.)

To start a timer, call Game_Timer.start(seconds, key) where seconds is the number of seconds you want the timer to run, and key is the name of that specific timer. You must use a separate name for every timer, because when one finishes, only the first script checking for that name will return with the timer completed.

To check whether or not a timer has finished, call Game_Timer.finished?(key) where timer_number is the number of the timer that you need to check. See the rules above regarding key.

To remove a timer, call Game_Timer.kill_timer(key) where key is the timer that you wish to remove.

To adjust the time remaining on a timer, call Game_Timer.adjust_time(setting, value, key) where value is the number you want to adjust by, key is the timer you want to adjust, and setting in the operation you want to perform. (1 to add frames, 2 to subtract frames, 3 to multiply, 4 to divide, and 5 to perform a modulus operation)

To stop or start a timer, call Game_Timer.active(key, bool) where key is the timer you want to start or stop, and bool is true if you want to start the timer, and false if you want to stop it.

To have a timer force battles to abort when they reach zero, call Game_Timer.end_battle(key, bool) where key is the timer you want to modify, and bool is true if you want it to abort battles while it is 0, and false if you don't.

To set a timer to display, call Game_Timer.display(key, bool) where key is the timer you want to display, and bool is either true or false, depending on the desired result.

To set a timer to be saved in the save file, call Game_Timer.save(key, bool) where key is the timer you want to have saved, and bool is true if you want the timer to be saved, and false if you want it to disappear when the game is closed.

Method List

set_power(power, duration)

Changes the intensity of the thunderstorm over the period specified by duration. (in frames) It is recommended that power be set to an integer from 0 to 9, where 0 is off and 9 is the most intense. Values below 0 function in the same way as 0, while values above 9 shorten the time between lightning strikes.

update

Updates all timers. Although intended for internal use, may be added to other scenes to force a timer update elsewhere.

update_single(key)

Updates a single timer, specified by key.

start(seconds, key)

Set up a timer, which will be accessed in the future by using key.

extended_start(hours, minutes, seconds, key)

Set up and extended timer. Functions in the same way as start().

finished?(key)

Returns true if the timer specified by key has reached 0, false otherwise. This method will delete the checked timer if it has reached 0.

check_timing(key)

Debugging method. Returns a variety of messages based on the current state of the timer specified by key.

kill_timer(key)

Erases the timer specified by key.

adjust_time(setting, value, key)

Adjusts the remaining time in the timer specified by key. Setting specifies an operation. (1 => addition, 2 => subtraction, 3 => multiplication, 4 = division, 5 = modulus)

active(key, bool)

Sets the timer specified by key to active or inactive, based on whether bool is true or false.

active?(key)

Returns true if the timer specified by key is active, and false otherwise.

end_battle(key, bool)

When bool is set to true, this method sets the timer specified by key to abort battles when it reaches 0. Otherwise, the timer will not abort battles when it reaches 0.

end_battle?

Checks to see if a timer that aborts battle has reached 0. Intended for internal use.

display(key, bool)

If bool is set to true, will display the timer specified by key. Otherwise, the timer is not displayed. Please note that only one timer will be displayed at any given time, no matter how many are set to display.

display?

Checks to see if a timer is being displayed, and reuturns remaining time. This method is intended for internal use only.

save(key, bool)

If bool is set to true, the timer specified by key will be saved along with the rest of the game. If bool is false, the timer will be deleted when the game closes, even if a save was made.

save?

Returns an array of all timers set to be saved. This method is intended for internal use only.

load_save(timers)

Loads all timers in the timers variable. This method is intended for internal use, but could be used to create new timers as well.

conditional_branch(parameters)

Part of the interpreter's conditional branch processing. Intended for internal use only.

control_variables(parameters)

Part of the interpreter's control variable processing. Intended for internal use only.

control_timer(parameters)

The interpreter's control timer processing. Intended for internal use only, although it could be used to create an event timer through scripts.

Terms and Conditions

  • This script is free to use in any noncommercial project. If you wish to use this script in a commercial (paid) project, please contact Glitchfinder at his website.
  • This script may only be hosted at the following domains:
    http://www.glitchkey.com
    http://www.hbgames.org
  • If you wish to host this script elsewhere, please contact Glitchfinder.
  • If you wish to translate this script, please contact Glitchfinder. He will need the web address that you plan to host the script at, as well as the language this script is being translated to.
  • The script header must remain intact at all times.
  • Glitchfinder remains the sole owner of this code. He may modify or revoke this license at any time, for any reason.
  • Any code derived from code within this script is owned by Glitchfinder, and you must have his permission to publish, host, or distribute his code.
  • This license applies to all code derived from the code within this script.
  • If you use this script within your project, you must include visible credit to Glitchfinder, within reason.
Just wondering because I am making a custom minigame for my game I'm currently making, does this actually show a timer somewhere on the screen or did I just mess up in the setup?
diablosbud wrote:
Just wondering because I am making a custom minigame for my game I'm currently making, does this actually show a timer somewhere on the screen or did I just mess up in the setup?


No, this script is meant only to provide background timers that the player is unaware of. (My current use is for a thunderstorm, among other things) Just try using the event timer's script, only slightly modified. (I'm not sure exactly where that is, its spread out all over the place)
Well actually can I have certain events happen with the default timer when it hits 0:00. If not i'll use this script for the background effects, and the actual timer to run as display, they work the same way other than effects 🙂.

EDIT: Also could you make a script line for conditional branches for me to have it check the timer has ended (I know that part exists, and you posted the line already, but what about with), and if it is ended have an event run. This will help because in my game that has an ABS I plan to send waves of enemies charging at the player, and he must fend them off until the timer ends. Please will you help me with this immportant part?
I'm not sure, but you might be able to use an old event self switch modifier script that someone posted a while back to pull that off. Essentially, you could have the timer run out of time, and then call the self switch code to shange the specific event's self switches, thus "activating" another page on the event. Also, I just tested this script in RMVX, and found that it works in that as well. Yayz! Must update title!
heh, Thanks. This will be very useful. I really do think the built in timer in xp quite useless for hidden commands seeing as it displays the time. And the VX compatibility, well, thats just a major bonus. Perfect for time related quests. Again, Thank you.
Yea, I may be able to use a switch, but I still need a way to trigger that switch. I'll try searching for that script you mentioned, and later today I'll post with my findings. Thanks for the suggestion :thumb:.

EDIT: I tried searching that exact text "Self Switch Modifier", and didn't find anything other than this topic, and some sort of ABS. I tried searching Self Switch but there are way to many topics, could you please make a piece of code for a conditional branch that if a certain timer is up it activates?
diablosbud wrote:
Yea, I may be able to use a switch, but I still need a way to trigger that switch. I'll try searching for that script you mentioned, and later today I'll post with my findings. Thanks for the suggestion :thumb:.

EDIT: I tried searching that exact text "Self Switch Modifier", and didn't find anything other than this topic, and some sort of ABS. I tried searching Self Switch but there are way to many topics, could you please make a piece of code for a conditional branch that if a certain timer is up it activates?


I just dug thru an old external hard drive for an old project of mine, and found the script. Here:

Content Hidden Show
#==============================================================================
# ** Control Self Switches
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#
#      To set a self switch:
#        sg_selfswitch(EVENT,'LETTER',OFF)
#
#
#      For example:
#        sg_selfswitch(44,'A')
#          That would turn self switch A in event #44 on.
#
#        sg_selfswitch(37,'B',1)
#          That would turn off self switch B in event #37.
#
#
#      To check self switches, use this:
#        sg_selfcheck(44,'A')
#          That would be "true" if the switch is on. Mainly for conditional branches.
#
#==============================================================================
begin
  SDK.log('Control Self Switches', 'sandgolem', 1, '22.07.06')
  rescue
end

def sg_selfswitch(ev, a, v = 0)
  key = [$game_map.map_id, ev, a]
  $game_self_switches[key] = (v == 0)
  $game_map.need_refresh = true
end
 
def sg_selfcheck(ev, a)
  key = [$game_map.map_id, ev, a]
  return $game_self_switches[key]
end
Expand to see the code.


Also, I believe it requires the SDK, although you might be able to delete that line altogether.
NearSerendy wrote:
heh, Thanks. This will be very useful. I really do think the built in timer in xp quite useless for hidden commands seeing as it displays the time. And the VX compatibility, well, thats just a major bonus. Perfect for time related quests. Again, Thank you.


Thanks! I really just built this because some of my scripts (mostly weather based ones) required timers. I liked my original timer, but I realized that it would be simpler if I could compress it into one script. As you said, the VX compatability is an added bonus. I just didn't use any edited methods (mostly by accident), and it works just fine.

Oops! I'm just used to forums that automerge posts, I guess. (pojo being one). I wish I could delete this post, but it appears I can't. o.0
Well, I don't understand how that script did anything, I still need to modify the script to work so it activates a switch when the timer finishes. That way I can activate an event in the script, this script I believe only lets you activate from the map, tried in the script. I need a script line for a conditional branch, please help me do this.
diablosbud wrote:
Well, I don't understand how that script did anything, I still need to modify the script to work so it activates a switch when the timer finishes. That way I can activate an event in the script, this script I believe only lets you activate from the map, tried in the script. I need a script line for a conditional branch, please help me do this.
If a timer has already been activated, just add the following to the conditional branch script line:

$game_temp.game_timer.check(timer_number)

If it is true, the conditional branch will activate, otherwise, it will either do nothing or use its else condition.

Also, try copying the script I have up right now, because if you copied before I made my first update to that post, the script will not return as true, no matter what you do.
I'm using XP, and I updated my script from the one in the first post again today, I got the event to run (I messed up with the auto-run), but it always makes it false. Could you please help me fix this bug?
diablosbud wrote:
I'm using XP, and I updated my script from the one in the first post again today, I got the event to run (I messed up with the auto-run), but it always makes it false. Could you please help me fix this bug?


Have you set the timer to update?
Yes I made sure I made it update in Scene_Map, I am not sure if it is placed right though. Here is the place I placed it:
        # Update map, interpreter, and player order
        # (this update order is important for when conditions are fulfilled
        # to run any event, and the player isn't provided the opportunity to
        # move in an instant)
        $game_map.update
        $game_system.map_interpreter.update
        $game_player.update
        $game_temp.game_timer.update
Expand to see the code.


Could you please tell me if I placed the map update for the timer right? It is line 57.
I cant figger this out cold you make a demo for me.
diablosbud wrote:
Yes I made sure I made it update in Scene_Map, I am not sure if it is placed right though. Here is the place I placed it:
      # Update map, interpreter, and player order
      # (this update order is important for when conditions are fulfilled
      # to run any event, and the player isn't provided the opportunity to
      # move in an instant)
      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update
      $game_temp.game_timer.update
Expand to see the code.


Could you please tell me if I placed the map update for the timer right? It is line 57.


Here is my entire update method. (minus a few things for other custom scripts that don't need to be revealed yet)

Content Hidden Show
  def update
    # Loop
    loop do
      # Update map, interpreter, and player order
      # (this update order is important for when conditions are fulfilled
      # to run any event, and the player isn't provided the opportunity to
      # move in an instant)
      $game_map.update
      $game_system.map_interpreter.update
      $game_player.update
      # Update system (timer), screen
      $game_system.update
      $game_screen.update
      # Abort loop if player isn't place moving
      unless $game_temp.player_transferring
        break
      end
      # Run place move
      transfer_player
      # Abort loop if transition processing
      if $game_temp.transition_processing
        break
      end
    end
    # Update sprite set
    @spriteset.update
    # Update message window
    @message_window.update
    # If game over
    if $game_temp.gameover
      # Switch to game over screen
      $scene = Scene_Gameover.new
      return
    end
    # If returning to title screen
    if $game_temp.to_title
      # Change to title screen
      $scene = Scene_Title.new
      return
    end
    # If transition processing
    if $game_temp.transition_processing
      # Clear transition processing flag
      $game_temp.transition_processing = false
      # Execute transition
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    # If showing message window
    if $game_temp.message_window_showing
      return
    end
    # If encounter list isn't empty, and encounter count is 0
    if $game_player.encounter_count == 0 and $game_map.encounter_list != []
      # If event is running or encounter is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.encounter_disabled
        # Confirm troop
        n = rand($game_map.encounter_list.size)
        troop_id = $game_map.encounter_list[n]
        # If troop is valid
        if $data_troops[troop_id] != nil
          # Set battle calling flag
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = troop_id
          $game_temp.battle_can_escape = true
          $game_temp.battle_can_lose = false
          $game_temp.battle_proc = nil
        end
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # If event is running, or menu is not forbidden
      unless $game_system.map_interpreter.running? or
             $game_system.menu_disabled
        # Set menu calling flag or beep flag
        $game_temp.menu_calling = true
        $game_temp.menu_beep = true
      end
    end
    # If debug mode is ON and F9 key was pressed
    if $DEBUG and Input.press?(Input::F9)
      # Set debug calling flag
      $game_temp.debug_calling = true
    end
    # If player is not moving
    unless $game_player.moving?
      # Run calling of each screen
      if $game_temp.battle_calling
        call_battle
      elsif $game_temp.shop_calling
        call_shop
      elsif $game_temp.name_calling
        call_name
      elsif $game_temp.menu_calling
        call_menu
      elsif $game_temp.save_calling
        call_save
      elsif $game_temp.debug_calling
        call_debug
      end
    end
    $game_temp.game_timer.update
  end
Expand to see the code.


robot79796 wrote:
I cant figger this out cold you make a demo for me.


Would you be able to say what the problem is? Is it giving you an error message, or not doing anything, or ending too quickly? (or something else altogether?)
I have it updated the same place you do, exactly the same place, but it still doesn't work. I believe that it is the script snippet you posted to try to make the conditional branches, because it isn't anything from the scripting required. I have that script at the bottem the Game_Timer. Also the timer number for both is the same at 1 so it should be working, I can't see anything else wrong other than the conditional branch script.

Do I need to change anything in the Game_Timer script to make it work?
diablosbud wrote:
I have it updated the same place you do, exactly the same place, but it still doesn't work. I believe that it is the script snippet you posted to try to make the conditional branches, because it isn't anything from the scripting required. I have that script at the bottem the Game_Timer. Also the timer number for both is the same at 1 so it should be working, I can't see anything else wrong other than the conditional branch script.

Do I need to change anything in the Game_Timer script to make it work?


Ok, I'm giving you something to add to the script to check if it is actually timing. Just add it at the bottom.

  def check2(timer_number)
    if Timers::Timers[timer_number] == nil
      print "time is up"
    else
      time = Timers::Timers[timer_number].to_s
      print time
    end
  end
Expand to see the code.


You can call it with $game_temp.game_timer.check2(timer_number) where timer_number is the number of the timer you are using. It will either print the current time left (in frames), or it will print "time is up" if the timer is done. I would call this with an event on the map, and check it every few seconds to see if the timer is going down at all.

Now, If you're wondering why I'm posting this, it was in the beta version of my script. I used it to check whether the problem with my timer was with the update method, or some other problem. More often than not, it was updating improperly.
I tried adding that script snippet at the bottem of the Game_Timer even after all of the ends, and used a call script instead of a script conditional branch entering "$game_temp.game_timer.check2(1)", but it doesn't work, and instead when I try to check the time with that call script I get an error saying "Script 'Game_Timer' line 89: NameError occurred. uninitialized constant Timers". If it isn't much trouble as said before, could you please make a demo for this?
diablosbud wrote:
I tried adding that script snippet at the bottem of the Game_Timer even after all of the ends, and used a call script instead of a script conditional branch entering "$game_temp.game_timer.check2(1)", but it doesn't work, and instead when I try to check the time with that call script I get an error saying "Script 'Game_Timer' line 89: NameError occurred. uninitialized constant Timers". If it isn't much trouble as said before, could you please make a demo for this?


Here's a link to the demo, complete with a working event reference for both checks.

http://www.megaupload.com/?d=QD086DV2

Sorry about uploading to megaupload, its just what I use most often.
Alright, I'm sorry about this but I'm still having a few issues, with the events. I have two events on this map having anything to do with this timer script (other events are enemies for my ABS system). Here are screenshots of their event pages, sorry they are a bit blurred, sorry for that, but still readable:

http://img297.imageshack.us/img297/1503/timereventautorunzw6.th.png[/img] http://img46.imageshack.us/img46/2508/timereventactionbuttonna4.th.png[/img]

Could you please help me just finish up making my timer events, this way I'm done, and now how for the rest of the uses I need for it?
diablosbud wrote:
Alright, I'm sorry about this but I'm still having a few issues, with the events. I have two events on this map having anything to do with this timer script (other events are enemies for my ABS system). Here are screenshots of their event pages, sorry they are a bit blurred, sorry for that, but still readable:

http://img297.imageshack.us/img297/1503/timereventautorunzw6.th.png[/img] http://img46.imageshack.us/img46/2508/timereventactionbuttonna4.th.png[/img]

Could you please help me just finish up making my timer events, this way I'm done, and now how for the rest of the uses I need for it?


I assume that you have the update methods somewhere else? Because with the events I see, you don't update the timer, you just check it. I'm not at home right now, but I could test those events when I get home later. If you want to run it through the events only, just add "$game_temp.game_timer.update" to the parallel process event, if you don't want to run it from the scripts. (Also, I'm planning an update for the timer script within the next few days that enables you to update timers independently of one another, if you want to do that. The only reason I'm doing this is because in one of my tests, I realized that ocassionally you want multiple factors to affect a timer, and if you've already set it, you might be out of luck in changing the remaining time/speed. I am also planning to add a "kill_timer" command to stop a timer in the middle of processing, as well as an "adjust_time" method, to change the remaining time. (it will essentially allow you to either add to, subtract from, multiply, or divide the remaining time, depending on the first number you input)

Also, you seem to have the start method confused. The time is in seconds only. To get the same time as your control timer, you multiply the number of minutes by 60. So, you would actually have the method as $game_temp.game_timer.start(170, 1).

EDIT: I just tried your first event in the demo I posted, and it worked just fine. I'm not sure what you're doing wrong, unless it is simply not updating...
U can do a demo???
There already is a demo look 3 posts above yours.

EDIT: Yeah, I didn't update in the events I thought the update method in Scene_Map took full care of that, so I'll try that right now. Also cool ideas for the kill_timer, and adjust_timer those would make neat additions.
ok ty
diablosbud wrote:
There already is a demo look 3 posts above yours.

EDIT: Yeah, I didn't update in the events I thought the update method in Scene_Map took full care of that, so I'll try that right now. Also cool ideas for the kill_timer, and adjust_timer those would make neat additions.


Technically, it should work from scene_map. Try using those events in the demo I posted. I tried them, and they worked just fine.
Could you make it so the timers freeze when in menu

NVM they do
Well, I finished my second event using a switch I turned on when it checked on the parallel process event then making a conditional branch in the action button event for that switch being on. Thanks for your help, now I know what I have to do for when I am making this into a mission timer for my game 🙂.
Sorry for almost necroposting. (one or two more days, and it would have been) Anyway, I just updated the script to include all of those commands that I had mentioned before, as well as full instructions and a version history in the header. Yes, I realize that some of those updates were not posted here. Anyway, I hope everyone enjoys it!
This is an excellent Script. It can be used to manage tons of effects that require a duration. Love it.

As to the earlier posts about trying to implement it in an event, it's pretty easy. Just make a Conditional Branch, go over to tab 4, radio button "Script", and enter "$game_temp.game_timer.check(timer_number)" in the field, where timer_number is the number assigned to that clock (which you set earlier with either of the timer functions Glitch provides). It'll register as true when the Counter is 0 and activate whatever other stuff you put in the Event. Just be sure to make the event in question Parallel.

I've only been messing around with Ruby and RMXP for about a week, and the code is pretty self explanatory to me. I wouldn't consider it something only for advanced codemonkeys; even a dumby like me can use it and it works great.

I'm using it right now to control the duration on Torches (a usable item) when inside a dark area (specifically with Blizzard's DDNS, where I modified the dark interiors to be so dark as to be mostly all black without torches or some other lightsource, like a light spell or whatever).

With this Script, I'll be able to implement a Food/Hunger Script, possibly a Need Rest Script, Stealth duration, duration on Map-use Skills and Spells, all kinds of neat stuff.

Thanks a bunch!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=49209