bgillisp

Limited Steps Script v1.0

Aug 11th, 2014
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #bgillisp Limited Steps Module, version 1.0
  2. #This module allows you to set up a common event to occur after the
  3. #player has taken a certain number of steps.
  4.  
  5. #Usage:
  6. #You MUST start a new game to use this script, else it will crash the
  7. #first time you call the commands due to missing variables in $game_system
  8.  
  9. #To start the limited steps, call the command
  10. #$game_player.limited_steps_start(a, b, c) in a script call inside an event
  11.  
  12. #Example: The call $game_player.limited_steps_start(50, 1, false)
  13. #Will give the player 50 steps until common event 1 runs.
  14. #False tells it to not display the step count. Use true if you want the
  15. #window to show instead.
  16.  
  17. #To stop the limited steps, call the command
  18. #$game_player.limited_steps_end() in a script call inside an event
  19. #A use of this would be if the player could stop the event by say
  20. #pulling a switch
  21. #
  22. #Known Bugs
  23. #None at the moment.
  24.  
  25. #Known Restrictions
  26. #1: It is only possible to have one limited steps event active at a time
  27. # if you call $game_player.limited_steps_start while a limited_steps_start
  28. # is currently running, it will overwrite the first limited_steps_start
  29. # with the new one.
  30.  
  31. #Planned later features
  32. #1: Allow for an event to run concurrently after a step has been taken
  33. #2: ???
  34.  
  35.  
  36. #Editable Region: Change this to change the size of the window
  37. module BG_limitedsteps
  38. #Limited Steps Window X location. Edit this to change where the window starts
  39. Window_X = 0
  40.  
  41. #Limited Steps Window Y Location. Edit this to change where the window starts
  42. Window_Y = 0
  43.  
  44. #Limited Steps Window Height. A height of less than 64 usually results in
  45. #the text not being displayed, so it is recommended to go no lower than 64
  46. Window_Height = 64
  47.  
  48. #Limited Steps Window Width. Edit this to make the menu bigger or smaller.
  49. Window_Width = 200
  50. end
  51.  
  52. #Script starts below. Edit below here only if you know what you are doing.
  53.  
  54. class Game_System
  55.  
  56. #The four new variables the script needs to function.
  57. attr_accessor :limited_steps_on
  58. attr_accessor :steps_left
  59. attr_accessor :event_on_zero
  60. attr_accessor :display_steps_left
  61.  
  62. alias bg_gamesystem_limited_steps initialize
  63. def initialize
  64.  
  65. #Set the initial starting conditions
  66. @limited_steps_on = false
  67. steps_left = 0
  68. event_on_zero = 0
  69. display_steps_left = false
  70.  
  71. #Call the aliased method
  72. bg_gamesystem_limited_steps
  73. end
  74.  
  75. end
  76.  
  77. class Game_Temp
  78. #Variable to hold the window class to be displayed
  79. attr_accessor :display_move_steps_window
  80. end #End Game Temp
  81.  
  82. class Game_Player < Game_Character
  83.  
  84. alias bg_restrictedsteps_increase_steps increase_steps
  85. def increase_steps
  86. #Call aliased method.
  87. sendback = bg_restrictedsteps_increase_steps
  88.  
  89. #Process the limited step work here.
  90. if(sendback)
  91. if($game_system.limited_steps_on)
  92. $game_system.steps_left -= 1
  93.  
  94. #Update the window, if one is to be shown
  95. if($game_system.display_steps_left == true)
  96. $game_temp.display_move_steps_window.refresh()
  97. end
  98.  
  99. #Process event if no steps left. Event is set to <= 0 to allow for
  100. #fractional steps to have occured at some point.
  101. if($game_system.steps_left.to_i <= 0)
  102.  
  103.  
  104. #De-initialize everything
  105. $game_system.limited_steps_on = false
  106. $game_system.steps_left = 0
  107.  
  108. #Dipose of the window if one had been used
  109. if($game_system.display_steps_left == true)
  110. $game_temp.display_move_steps_window.dispose()
  111. end
  112.  
  113. $game_system.display_steps_left = false
  114.  
  115. #If passed a valid number for a common event, call that event
  116. if($game_system.event_on_zero.to_i >= 1)
  117. #Call the common event linked to the limited steps event.
  118. $game_temp.reserve_common_event($game_system.event_on_zero.to_i)
  119. end
  120.  
  121. end #End of if steps have ran out
  122.  
  123. end #End of processing if limited steps on
  124. end #End of processing sendback
  125. end #End of move_by_input
  126.  
  127. #New method: Restricted movement. Call this to turn on limited steps
  128. #To call this command, use $game_player.limited_steps_start(a, b, c)
  129. #a = number of steps before the common event runs
  130. #b = what event to call if steps run out. If a 0 or negative number
  131. #is passed, no event will be called when the steps run out.
  132. #c = whether or not to show the player the number of steps they have left
  133. def limited_steps_start(steps, event, display)
  134. $game_system.limited_steps_on = true
  135. $game_system.steps_left = steps
  136. $game_system.event_on_zero = event
  137. $game_system.display_steps_left = display
  138.  
  139. #Create a Window if display was asked for
  140. if(display == true)
  141. $game_temp.display_move_steps_window = Limited_Steps_Window.new()
  142. $game_temp.display_move_steps_window.show
  143. end
  144.  
  145. end #End of limited_steps_start
  146.  
  147. #New method: End limited steps. Call this to turn off limited steps
  148. #To call this command, use $game_player.limited_steps_end() in a script call.
  149. def limited_steps_end()
  150. $game_system.limited_steps_on = false
  151. $game_system.event_on_zero = 0
  152.  
  153. #Dispose of the window if one had been used.
  154. if($game_system.display_steps_left == true)
  155. $game_temp.display_move_steps_window.dispose()
  156. end
  157.  
  158. $game_system.display_steps_left = false
  159. end #End of limited steps end
  160.  
  161. end #End of Game_Player class edits
  162.  
  163. class Limited_Steps_Window < Window_Base
  164.  
  165. #Initialize the limited steps window
  166. def initialize()
  167. super(BG_limitedsteps::Window_X, BG_limitedsteps::Window_Y, BG_limitedsteps::Window_Width, BG_limitedsteps::Window_Height)
  168. open
  169. end
  170.  
  171. #Dispose of the window
  172. def dispose
  173. super()
  174. end
  175.  
  176. #Open the window
  177. def open
  178. refresh
  179. super
  180. end
  181.  
  182. #Return steps left
  183. def stepstogo
  184. $game_system.steps_left
  185. end
  186.  
  187. #Update the window with the number of steps left
  188. def refresh
  189. contents.clear
  190. string_to_show = "Steps Left: " + stepstogo.to_s
  191. draw_text(0, 0, BG_limitedsteps::Window_Width, 32, string_to_show)
  192. end
  193.  
  194. end #End of Limited_Steps_Window
  195.  
  196. #Edit to allow the window to be re-initialized upon loading a game.
  197. class Scene_Load < Scene_File
  198. alias bg_limitedsteps_on_load_success on_load_success
  199. def on_load_success
  200. #Call aliased method
  201. bg_limitedsteps_on_load_success
  202.  
  203. #If set to show the window, re-initilaize the window
  204. if($game_system.limited_steps_on == true)
  205. $game_temp.display_move_steps_window = Limited_Steps_Window.new()
  206. $game_temp.display_move_steps_window.show
  207. end #End if
  208. end
  209. end #End of Scene Load
RAW Paste Data