Archeia

Yanfly Engine Ace - Move Restrict Region v1.03

Mar 30th, 2014
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Move Restrict Region v1.03
  4. # -- Last Updated: 2012.01.03
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-MoveRestrictRegion"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.23.08 - Added Feature: <all restrict: x>
  17. # 2012.01.03 - Added Feature: <all restrict: x>
  18. # 2011.12.26 - Bug Fixed: Player Restricted Regions.
  19. # 2011.12.15 - Started Script and Finished.
  20. #
  21. #==============================================================================
  22. # ▼ Introduction
  23. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. # Not everybody wants NPC's to travel all over the place. With this script, you
  25. # can set NPC's to be unable to move pass tiles marked by a specified Region.
  26. # Simply draw out the area you want to enclose NPC's in on and they'll be
  27. # unable to move past it unless they have Through on. Likewise, there are
  28. # regions that you can prevent the player from moving onto, too!
  29. #
  30. #==============================================================================
  31. # ▼ Instructions
  32. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. # To install this script, open up your script editor and copy/paste this script
  34. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  35. #
  36. # -----------------------------------------------------------------------------
  37. # Map Notetags - These notetags go in the map notebox in a map's properties.
  38. # -----------------------------------------------------------------------------
  39. # <all restrict: x>
  40. # <all restrict: x, x>
  41. # Players and NPC's on the map will be unable to move past region x even if
  42. # they have the "through" flag set. The only thing that can go past is if the
  43. # player is using the debug through flag. Draw out the area you want to close
  44. # the player and NPC's in with the regions and both will be unable to move onto
  45. # any of those tiles marked by region x. If you want to have more regions
  46. # restrict NPC's, insert multiples of this tag.
  47. #
  48. # <npc restrict: x>
  49. # <npc restrict: x, x>
  50. # NPC's on that map will be unable to move past regions x unless they have a
  51. # "Through" flag on. Draw out the area you want to close NPC's in with the
  52. # regions and the NPC's will be unable to move onto any of those tiles marked
  53. # by region x. If you want to have more regions restrict NPC's, insert
  54. # multiples of this tag.
  55. #
  56. # <player restrict: x>
  57. # <player restrict: x, x>
  58. # Players will not be able to move on tiles marked by region x unless the
  59. # player has a "Through" flag on. Draw out the area you want to close the
  60. # player in with the regions and the player will be unable to move past any of
  61. # those tiles marked by region x. If you want to have more regions restrict the
  62. # player, insert multiples of this tag.
  63. #
  64. #==============================================================================
  65. # ▼ Compatibility
  66. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  67. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  68. # it will run with RPG Maker VX without adjusting.
  69. #
  70. #==============================================================================
  71.  
  72. module YEA
  73.   module MOVE_RESTRICT
  74.    
  75.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  76.     # - Default Completely Restricted Regions -
  77.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  78.     # If you want there to always be a region ID that will forbid both the
  79.     # player and NPC's from passing through, insert that region ID into the
  80.     # array below. This effect will completely block out both players and NPC's
  81.     # even if they have the "through" flag. However, it does not block the
  82.     # debug_through flag for players.
  83.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  84.     DEFAULT_ALL = [61]
  85.    
  86.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  87.     # - Default Player Restricted Regions -
  88.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  89.     # If you want there to always be a region ID that will forbid the player
  90.     # from passing through, insert that region ID into the array below.
  91.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  92.     DEFAULT_PLAYER = [62]
  93.    
  94.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  95.     # - Default NPC Restricted Regions -
  96.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  97.     # If you want there to always be a region ID that will forbid NPC's from
  98.     # passing through, insert that region ID into the array below.
  99.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  100.     DEFAULT_NPC = [63]
  101.    
  102.   end # MOVE_RESTRICT
  103. end # YEA
  104.  
  105. #==============================================================================
  106. # ▼ Editting anything past this point may potentially result in causing
  107. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  108. # halitosis so edit at your own risk.
  109. #==============================================================================
  110.  
  111. module YEA
  112.   module REGEXP
  113.   module MAP
  114.    
  115.     ALL_RESTRICT =
  116.       /<(?:ALL_RESTRICT|all restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  117.     NPC_RESTRICT =
  118.       /<(?:NPC_RESTRICT|npc restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  119.     PLAYER_RESTRICT =
  120.       /<(?:PLAYER_RESTRICT|player restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  121.    
  122.   end # MAP
  123.   end # REGEXP
  124. end # YEA
  125.  
  126. #==============================================================================
  127. # ■ RPG::Map
  128. #==============================================================================
  129.  
  130. class RPG::Map
  131.  
  132.   #--------------------------------------------------------------------------
  133.   # public instance variables
  134.   #--------------------------------------------------------------------------
  135.   attr_accessor :all_restrict_regions
  136.   attr_accessor :npc_restrict_regions
  137.   attr_accessor :player_restrict_regions
  138.  
  139.   #--------------------------------------------------------------------------
  140.   # common cache: load_notetags_mrr
  141.   #--------------------------------------------------------------------------
  142.   def load_notetags_mrr
  143.     @all_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_ALL.clone
  144.     @npc_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_NPC.clone
  145.     @player_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_PLAYER.clone
  146.     #---
  147.     self.note.split(/[\r\n]+/).each { |line|
  148.       case line
  149.       #---
  150.       when YEA::REGEXP::MAP::ALL_RESTRICT
  151.         $1.scan(/\d+/).each { |num|
  152.         @all_restrict_regions.push(num.to_i) if num.to_i > 0 }
  153.       when YEA::REGEXP::MAP::NPC_RESTRICT
  154.         $1.scan(/\d+/).each { |num|
  155.         @npc_restrict_regions.push(num.to_i) if num.to_i > 0 }
  156.       when YEA::REGEXP::MAP::PLAYER_RESTRICT
  157.         $1.scan(/\d+/).each { |num|
  158.         @player_restrict_regions.push(num.to_i) if num.to_i > 0 }
  159.       #---
  160.       end
  161.     } # self.note.split
  162.     #---
  163.   end
  164.  
  165. end # RPG::Map
  166.  
  167. #==============================================================================
  168. # ■ Game_Map
  169. #==============================================================================
  170.  
  171. class Game_Map
  172.  
  173.   #--------------------------------------------------------------------------
  174.   # alias method: setup
  175.   #--------------------------------------------------------------------------
  176.   alias game_map_setup_mrr setup
  177.   def setup(map_id)
  178.     game_map_setup_mrr(map_id)
  179.     @map.load_notetags_mrr
  180.   end
  181.  
  182.   #--------------------------------------------------------------------------
  183.   # new method: all_restrict_regions
  184.   #--------------------------------------------------------------------------
  185.   def all_restrict_regions
  186.     return @map.all_restrict_regions
  187.   end
  188.  
  189.   #--------------------------------------------------------------------------
  190.   # new method: npc_restrict_regions
  191.   #--------------------------------------------------------------------------
  192.   def npc_restrict_regions
  193.     return @map.npc_restrict_regions
  194.   end
  195.  
  196.   #--------------------------------------------------------------------------
  197.   # new method: player_restrict_regions
  198.   #--------------------------------------------------------------------------
  199.   def player_restrict_regions
  200.     return @map.player_restrict_regions
  201.   end
  202.  
  203. end # Game_Map
  204.  
  205. #==============================================================================
  206. # ■ Game_CharacterBase
  207. #==============================================================================
  208.  
  209. class Game_CharacterBase
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # alias method: passable?
  213.   #--------------------------------------------------------------------------
  214.   alias game_characterbase_passable_mrr passable?
  215.   def passable?(x, y, d)
  216.     return false if npc_region_forbid?(x, y, d)
  217.     return false if player_region_forbid?(x, y, d)
  218.     return game_characterbase_passable_mrr(x, y, d)
  219.   end
  220.  
  221.   #--------------------------------------------------------------------------
  222.   # new method: npc_forbid?
  223.   #--------------------------------------------------------------------------
  224.   def npc_region_forbid?(x, y, d)
  225.     return false unless self.is_a?(Game_Event)
  226.     region = 0
  227.     case d
  228.     when 1; region = $game_map.region_id(x-1, y+1)
  229.     when 2; region = $game_map.region_id(x+0, y+1)
  230.     when 3; region = $game_map.region_id(x+1, y+1)
  231.     when 4; region = $game_map.region_id(x-1, y+0)
  232.     when 5; region = $game_map.region_id(x+0, y+0)
  233.     when 6; region = $game_map.region_id(x+1, y+0)
  234.     when 7; region = $game_map.region_id(x-1, y-1)
  235.     when 8; region = $game_map.region_id(x+0, y-1)
  236.     when 9; region = $game_map.region_id(x+1, y-1)
  237.     end
  238.     return true if $game_map.all_restrict_regions.include?(region)
  239.     return false if @through
  240.     return $game_map.npc_restrict_regions.include?(region)
  241.   end
  242.  
  243.   #--------------------------------------------------------------------------
  244.   # new method: player_region_forbid?
  245.   #--------------------------------------------------------------------------
  246.   def player_region_forbid?(x, y, d)
  247.     return false unless self.is_a?(Game_Player)
  248.     return false if debug_through?
  249.     region = 0
  250.     case d
  251.     when 1; region = $game_map.region_id(x-1, y+1)
  252.     when 2; region = $game_map.region_id(x+0, y+1)
  253.     when 3; region = $game_map.region_id(x+1, y+1)
  254.     when 4; region = $game_map.region_id(x-1, y+0)
  255.     when 5; region = $game_map.region_id(x+0, y+0)
  256.     when 6; region = $game_map.region_id(x+1, y+0)
  257.     when 7; region = $game_map.region_id(x-1, y-1)
  258.     when 8; region = $game_map.region_id(x+0, y-1)
  259.     when 9; region = $game_map.region_id(x+1, y-1)
  260.     end
  261.     return true if $game_map.all_restrict_regions.include?(region)
  262.     return false if @through
  263.     return $game_map.player_restrict_regions.include?(region)
  264.   end
  265.  
  266. end # Game_CharacterBase
  267.  
  268. #==============================================================================
  269. #
  270. # ▼ End of File
  271. #
  272. #==============================================================================
RAW Paste Data