Advertisement
dsiver144

Restricted Move Input

Sep 1st, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.19 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3.  Title: Restricted Move Input
  4.  Author: Tsukihime
  5.  Date: Aug 31, 2013
  6. --------------------------------------------------------------------------------
  7.  ** Change log
  8.  Aug 31, 2013
  9.    - Initial release
  10. --------------------------------------------------------------------------------  
  11.  ** Terms of Use
  12.  * Free to use in commercial/non-commercial projects
  13.  * No real support. The script is provided as-is
  14.  * Will do bug fixes, but no compatibility patches
  15.  * Features may be requested but no guarantees, especially if it is non-trivial
  16.  * Credits to Tsukihime in your project
  17.  * Preserve this header
  18. --------------------------------------------------------------------------------
  19.  ** Description
  20.  
  21.  This script allows you to enable or disable movement for specific
  22.  directions using script calls. When a direction is disabled, the player
  23.  is unable to move in that direction on the map using the direction input keys.
  24.  
  25. --------------------------------------------------------------------------------
  26.  ** Installation
  27.  
  28.  Place this script below Materials and above Main
  29.  
  30. --------------------------------------------------------------------------------
  31.  ** Usage
  32.  
  33.  The following script calls will enable or disable specific directions:
  34.  
  35.    disable_move_direction(dir_symbol)
  36.    enable_move_direction(dir_symbol)
  37.    
  38.  Where the `dir_symbol`is one of the following
  39.  
  40.    :UP
  41.    :LEFT
  42.    :RIGHT
  43.    :DOWN
  44.    
  45. --------------------------------------------------------------------------------
  46.  ** Example
  47.  
  48.  To prevent players from moving up or down, use the script calls
  49.  
  50.    disable_move_direction(:UP)
  51.    disable_move_direction(:DOWN)
  52.    
  53.  To enable them again, use the script calls
  54.  
  55.    enable_move_direction(:UP)
  56.    enable_move_direction(:DOWN)
  57.  
  58. #===============================================================================
  59. =end
  60. $imported = {} if $imported.nil?
  61. $imported["TH_RestrictedMoveInput"] = true
  62. #===============================================================================
  63. # ** Configuration
  64. #===============================================================================
  65. module TH
  66.   module Restricted_Move_Input
  67.    
  68.     Input_Map = {
  69.       :DOWN => 2,
  70.       :LEFT => 4,
  71.       :RIGHT => 6,
  72.       :UP => 8
  73.     }
  74.   end
  75. end
  76. #===============================================================================
  77. # ** Rest of Script
  78. #===============================================================================
  79. class Game_System
  80.  
  81.   def disabled_move_inputs
  82.     @move_input_disabled ||= {}
  83.   end
  84. end
  85.  
  86. class Game_Interpreter
  87.  
  88.   def disable_move_direction(dir_symbol)
  89.     dir = TH::Restricted_Move_Input::Input_Map[dir_symbol]
  90.     $game_system.disabled_move_inputs[dir] = true
  91.   end
  92.  
  93.   def enable_move_direction(dir_symbol)
  94.     dir = TH::Restricted_Move_Input::Input_Map[dir_symbol]
  95.     $game_system.disabled_move_inputs[dir] = false
  96.   end
  97. end
  98.  
  99. class Game_Player < Game_Character
  100.  
  101.   alias :th_linear_movement_move_by_input :move_by_input
  102.   def move_by_input
  103.     return if $game_system.disabled_move_inputs[Input.dir4]
  104.     th_linear_movement_move_by_input
  105.   end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement