vindaca510

Switch Timer System v1.0

Aug 4th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.16 KB | None | 0 0
  1.  
  2. ################################################################################
  3. #↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓#
  4. #↓                                                                            ↓#
  5. #↓                      Switch Timer System: Version 1.0                      ↓#
  6. #↓                                                                            ↓#
  7. #↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕#
  8. #↑                                                                            ↑#
  9. #↑                            Written By: Joe Pro                             ↑#
  10. #↑                        Last Edited:  July 31, 2014                         ↑#
  11. #↑                                                                            ↑#
  12. #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#
  13. ################################################################################
  14.  
  15. #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#
  16. #◙ ** Disclaimer                                                              ◙#
  17. #◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙#
  18. #◙                                                                            ◙#
  19. #◙ This script is not for commercial, if you wish to use this script in a     ◙#
  20. #◙ game please PM me. All credit is to be given to me as the author of this   ◙#
  21. #◙ script.                                                                    ◙#
  22. #◙                                                                            ◙#
  23. #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#
  24. #◙ ** How To Use                                                              ◙#
  25. #◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙#
  26. #◙                                                                            ◙#
  27. #◙ * Use the example below in an event script call to set up a new timer.     ◙#
  28. #◙                                                                            ◙#
  29. #◙    set_up_timer(goal_time, scene_type, $game_switch_id)                    ◙#
  30. #◙                                                                            ◙#
  31. #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#
  32. #◙ ** Updates / Version Notes                                                 ◙#
  33. #◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙#
  34. #◙                                                                            ◙#
  35. #◙   v0.1                                                                     ◙#
  36. #◙ ~◄◙◙◙◙►~                                                                   ◙#
  37. #◙ * This script allows you to set up a timer to be used through out the game.◙#
  38. #◙   Each timer can be assigned it's own switch. They can also be set up to   ◙#
  39. #◙   only update if a certian scene is running.                               ◙#
  40. #◙                                                                            ◙#
  41. #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#
  42.  
  43.  
  44.  
  45. ################################################################################
  46. #↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓#
  47. #↓                                                                            ↓#
  48. #↕                     Switch Timer System: Version 1.0                       ↕#
  49. #↑                                                                            ↑#
  50. #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑#
  51. ################################################################################
  52.  
  53.  
  54.  
  55. #==============================================================================
  56. # ** Game_System
  57. #------------------------------------------------------------------------------
  58. #  This class handles system data. It saves the disable state of saving and
  59. # menus. Instances of this class are referenced by $game_system.
  60. #==============================================================================
  61.  
  62. class Game_System
  63.  
  64.   #--------------------------------------------------------------------------
  65.   # * Public Instance Variables
  66.   #--------------------------------------------------------------------------
  67.   attr_accessor :timers            # timers
  68.  
  69.   #--------------------------------------------------------------------------
  70.   # * Aliasing Method: Object Initialization
  71.   #--------------------------------------------------------------------------
  72.   alias :gsi21321321 :initialize
  73.    
  74.   #--------------------------------------------------------------------------
  75.   # * Object Initialization
  76.   #--------------------------------------------------------------------------
  77.   def initialize
  78.     gsi21321321()
  79.     @timers = {}
  80.   end
  81.  
  82.   #--------------------------------------------------------------------------
  83.   # * Object Initialization
  84.   #--------------------------------------------------------------------------
  85.   def add_timer(goal_time, scene_type, switch)
  86.     @timers[(@timers.size + 1)] = {
  87.       :start => Graphics.frame_count,
  88.       :current => Graphics.frame_count,
  89.       :goal_time => goal_time,
  90.       :scene_type => scene_type,
  91.       :switch => switch,
  92.     }
  93.   end
  94.  
  95.   #--------------------------------------------------------------------------
  96.   # * Object Initialization
  97.   #--------------------------------------------------------------------------
  98.   def update_timer(id)
  99.     @timers[id][:current] += 1
  100.   end
  101.  
  102.   #--------------------------------------------------------------------------
  103.   # * Object Initialization
  104.   #--------------------------------------------------------------------------
  105.   def end_timer(id)
  106.     $game_switches[@timers[id][:switch]] = true if @timers[id][:switch]
  107.     @timers.delete(id)
  108.   end
  109.  
  110.   #--------------------------------------------------------------------------
  111.   # * Object Initialization
  112.   #--------------------------------------------------------------------------
  113.   def time_up?(id)
  114.     goal_time = @timers[id][:goal_time]
  115.     current = @timers[id][:current]
  116.     start = @timers[id][:start]
  117.     return ((current - start) / Graphics.frame_rate) >= goal_time
  118.   end
  119.  
  120.   #--------------------------------------------------------------------------
  121.   # * Object Initialization
  122.   #--------------------------------------------------------------------------
  123.   def update_all_timers
  124.     @timers.each_key { |id|
  125.       if @timers[id][:scene]
  126.         update_timer(id) if SceneManager.scene_is?(@timers[id][:scene])
  127.       else
  128.         update_timer(id)
  129.       end
  130.       end_timer(id) if time_up?(id)
  131.     }
  132.   end
  133.  
  134. end
  135.  
  136.  
  137. #==============================================================================
  138. # ** Game_Interpreter
  139. #------------------------------------------------------------------------------
  140. #  An interpreter for executing event commands. This class is used within the
  141. # Game_Map, Game_Troop, and Game_Event classes.
  142. #==============================================================================
  143.  
  144. class Game_Interpreter
  145.  
  146.   #--------------------------------------------------------------------------
  147.   # * Object Initialization
  148.   #--------------------------------------------------------------------------
  149.   def set_up_timer(goal_time, scene_type = nil, switch = nil)
  150.     $game_system.add_timer(goal_time, scene_type, switch)
  151.   end
  152.  
  153. end
  154.  
  155.  
  156. #==============================================================================
  157. # ** Scene_Base
  158. #------------------------------------------------------------------------------
  159. #  This is a super class of all scenes within the game.
  160. #==============================================================================
  161.  
  162. class Scene_Base
  163.  
  164.   #--------------------------------------------------------------------------
  165.   # * Aliasing Method: Frame Update
  166.   #--------------------------------------------------------------------------
  167.   alias :sbu325434 :update
  168.    
  169.   #--------------------------------------------------------------------------
  170.   # * Frame Update
  171.   #--------------------------------------------------------------------------
  172.   def update
  173.     sbu325434
  174.     $game_system.update_all_timers
  175.   end
  176.  
  177. end
Advertisement
Add Comment
Please, Sign In to add comment