Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #bgillisp Limited Steps Module, version 1.0
- #This module allows you to set up a common event to occur after the
- #player has taken a certain number of steps.
- #Usage:
- #You MUST start a new game to use this script, else it will crash the
- #first time you call the commands due to missing variables in $game_system
- #To start the limited steps, call the command
- #$game_player.limited_steps_start(a, b, c) in a script call inside an event
- #Example: The call $game_player.limited_steps_start(50, 1, false)
- #Will give the player 50 steps until common event 1 runs.
- #False tells it to not display the step count. Use true if you want the
- #window to show instead.
- #To stop the limited steps, call the command
- #$game_player.limited_steps_end() in a script call inside an event
- #A use of this would be if the player could stop the event by say
- #pulling a switch
- #
- #Known Bugs
- #None at the moment.
- #Known Restrictions
- #1: It is only possible to have one limited steps event active at a time
- # if you call $game_player.limited_steps_start while a limited_steps_start
- # is currently running, it will overwrite the first limited_steps_start
- # with the new one.
- #Planned later features
- #1: Allow for an event to run concurrently after a step has been taken
- #2: ???
- #Editable Region: Change this to change the size of the window
- module BG_limitedsteps
- #Limited Steps Window X location. Edit this to change where the window starts
- Window_X = 0
- #Limited Steps Window Y Location. Edit this to change where the window starts
- Window_Y = 0
- #Limited Steps Window Height. A height of less than 64 usually results in
- #the text not being displayed, so it is recommended to go no lower than 64
- Window_Height = 64
- #Limited Steps Window Width. Edit this to make the menu bigger or smaller.
- Window_Width = 200
- end
- #Script starts below. Edit below here only if you know what you are doing.
- class Game_System
- #The four new variables the script needs to function.
- attr_accessor :limited_steps_on
- attr_accessor :steps_left
- attr_accessor :event_on_zero
- attr_accessor :display_steps_left
- alias bg_gamesystem_limited_steps initialize
- def initialize
- #Set the initial starting conditions
- @limited_steps_on = false
- steps_left = 0
- event_on_zero = 0
- display_steps_left = false
- #Call the aliased method
- bg_gamesystem_limited_steps
- end
- end
- class Game_Temp
- #Variable to hold the window class to be displayed
- attr_accessor :display_move_steps_window
- end #End Game Temp
- class Game_Player < Game_Character
- alias bg_restrictedsteps_increase_steps increase_steps
- def increase_steps
- #Call aliased method.
- sendback = bg_restrictedsteps_increase_steps
- #Process the limited step work here.
- if(sendback)
- if($game_system.limited_steps_on)
- $game_system.steps_left -= 1
- #Update the window, if one is to be shown
- if($game_system.display_steps_left == true)
- $game_temp.display_move_steps_window.refresh()
- end
- #Process event if no steps left. Event is set to <= 0 to allow for
- #fractional steps to have occured at some point.
- if($game_system.steps_left.to_i <= 0)
- #De-initialize everything
- $game_system.limited_steps_on = false
- $game_system.steps_left = 0
- #Dipose of the window if one had been used
- if($game_system.display_steps_left == true)
- $game_temp.display_move_steps_window.dispose()
- end
- $game_system.display_steps_left = false
- #If passed a valid number for a common event, call that event
- if($game_system.event_on_zero.to_i >= 1)
- #Call the common event linked to the limited steps event.
- $game_temp.reserve_common_event($game_system.event_on_zero.to_i)
- end
- end #End of if steps have ran out
- end #End of processing if limited steps on
- end #End of processing sendback
- end #End of move_by_input
- #New method: Restricted movement. Call this to turn on limited steps
- #To call this command, use $game_player.limited_steps_start(a, b, c)
- #a = number of steps before the common event runs
- #b = what event to call if steps run out. If a 0 or negative number
- #is passed, no event will be called when the steps run out.
- #c = whether or not to show the player the number of steps they have left
- def limited_steps_start(steps, event, display)
- $game_system.limited_steps_on = true
- $game_system.steps_left = steps
- $game_system.event_on_zero = event
- $game_system.display_steps_left = display
- #Create a Window if display was asked for
- if(display == true)
- $game_temp.display_move_steps_window = Limited_Steps_Window.new()
- $game_temp.display_move_steps_window.show
- end
- end #End of limited_steps_start
- #New method: End limited steps. Call this to turn off limited steps
- #To call this command, use $game_player.limited_steps_end() in a script call.
- def limited_steps_end()
- $game_system.limited_steps_on = false
- $game_system.event_on_zero = 0
- #Dispose of the window if one had been used.
- if($game_system.display_steps_left == true)
- $game_temp.display_move_steps_window.dispose()
- end
- $game_system.display_steps_left = false
- end #End of limited steps end
- end #End of Game_Player class edits
- class Limited_Steps_Window < Window_Base
- #Initialize the limited steps window
- def initialize()
- super(BG_limitedsteps::Window_X, BG_limitedsteps::Window_Y, BG_limitedsteps::Window_Width, BG_limitedsteps::Window_Height)
- open
- end
- #Dispose of the window
- def dispose
- super()
- end
- #Open the window
- def open
- refresh
- super
- end
- #Return steps left
- def stepstogo
- $game_system.steps_left
- end
- #Update the window with the number of steps left
- def refresh
- contents.clear
- string_to_show = "Steps Left: " + stepstogo.to_s
- draw_text(0, 0, BG_limitedsteps::Window_Width, 32, string_to_show)
- end
- end #End of Limited_Steps_Window
- #Edit to allow the window to be re-initialized upon loading a game.
- class Scene_Load < Scene_File
- alias bg_limitedsteps_on_load_success on_load_success
- def on_load_success
- #Call aliased method
- bg_limitedsteps_on_load_success
- #If set to show the window, re-initilaize the window
- if($game_system.limited_steps_on == true)
- $game_temp.display_move_steps_window = Limited_Steps_Window.new()
- $game_temp.display_move_steps_window.show
- end #End if
- end
- end #End of Scene Load
RAW Paste Data