Advertisement
roninator2

Yanfly Move Restrict Regions - Vehicle addon

Dec 8th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.26 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Move Restrict Region v1.03 - Addon
  4. # -- Last Updated: 2012.01.03
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. # -- Addon Mod: Roninator2
  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. # Must be below Yanfly Engine Ace - Move Restrict Region v1.03
  37. #
  38. # -----------------------------------------------------------------------------
  39. # Map Notetags - These notetags go in the map notebox in a map's properties.
  40. # -----------------------------------------------------------------------------
  41. #
  42. # <vehicle restrict: x>
  43. # <vehicle restrict: x, x>
  44. # Players will not be able to move on tiles marked by region x unless the
  45. # player has a "Through" flag on. Draw out the area you want to close the
  46. # player in with the regions and the player will be unable to move past any of
  47. # those tiles marked by region x. If you want to have more regions restrict the
  48. # player, insert multiples of this tag.
  49. #
  50. #==============================================================================
  51. # ▼ Compatibility
  52. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  53. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  54. # it will run with RPG Maker VX without adjusting.
  55. #
  56. #==============================================================================
  57.  
  58. module YEA
  59.   module MOVE_RESTRICT
  60.    
  61.    
  62.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  63.     # - Default Vehicle Restricted Regions -
  64.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  65.     # If you want there to always be a region ID that will forbid the vehicle
  66.     # from passing through, insert that region ID into the array below.
  67.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  68.     DEFAULT_VEHICLE = [59]
  69.    
  70.   end # MOVE_RESTRICT
  71. end # YEA
  72.  
  73. #==============================================================================
  74. # ▼ Editting anything past this point may potentially result in causing
  75. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  76. # halitosis so edit at your own risk.
  77. #==============================================================================
  78.  
  79. module YEA
  80.   module REGEXP
  81.   module MAP
  82.    
  83.     VEHICLE_RESTRICT =
  84.       /<(?:VEHICLE_RESTRICT|vehicle restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  85.    
  86.   end # MAP
  87.   end # REGEXP
  88. end # YEA
  89.  
  90. #==============================================================================
  91. # ■ RPG::Map
  92. #==============================================================================
  93.  
  94. class RPG::Map
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # public instance variables
  98.   #--------------------------------------------------------------------------
  99.   attr_accessor :vehicle_restrict_regions
  100.  
  101.   #--------------------------------------------------------------------------
  102.   # common cache: load_notetags_mrr
  103.   #--------------------------------------------------------------------------
  104.   alias r2_load_notetags_mrr_tnm5j load_notetags_mrr
  105.   def load_notetags_mrr
  106.     r2_load_notetags_mrr_tnm5j
  107.     @vehicle_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_VEHICLE.clone
  108.     #---
  109.     self.note.split(/[\r\n]+/).each { |line|
  110.       case line
  111.       #---
  112.       when YEA::REGEXP::MAP::VEHICLE_RESTRICT
  113.         $1.scan(/\d+/).each { |num|
  114.         @vehicle_restrict_regions.push(num.to_i) if num.to_i > 0 }
  115.       #---
  116.       end
  117.     } # self.note.split
  118.     #---
  119.   end
  120.  
  121. end # RPG::Map
  122.  
  123. #==============================================================================
  124. # ■ Game_Map
  125. #==============================================================================
  126.  
  127. class Game_Map
  128.  
  129.   #--------------------------------------------------------------------------
  130.   # new method: player_restrict_regions
  131.   #--------------------------------------------------------------------------
  132.   def vehicle_restrict_regions
  133.     return @map.vehicle_restrict_regions
  134.   end
  135.  
  136. end # Game_Map
  137.  
  138. #==============================================================================
  139. # ■ Game_CharacterBase
  140. #==============================================================================
  141.  
  142. class Game_CharacterBase
  143.  
  144.   #--------------------------------------------------------------------------
  145.   # alias method: passable?
  146.   #--------------------------------------------------------------------------
  147.   alias r2game_characterbase_passable_mrr passable?
  148.   def passable?(x, y, d)
  149.     return false if vehicle_region_forbid?(x, y, d)
  150.     return r2game_characterbase_passable_mrr(x, y, d)
  151.   end
  152.  
  153.   #--------------------------------------------------------------------------
  154.   # new method: player_region_forbid?
  155.   #--------------------------------------------------------------------------
  156.   def vehicle_region_forbid?(x, y, d)
  157.     return false unless self.is_a?(Game_Character)
  158.     return false if debug_through?
  159.     region = 0
  160.     case d
  161.     when 1; region = $game_map.region_id(x-1, y+1)
  162.     when 2; region = $game_map.region_id(x+0, y+1)
  163.     when 3; region = $game_map.region_id(x+1, y+1)
  164.     when 4; region = $game_map.region_id(x-1, y+0)
  165.     when 5; region = $game_map.region_id(x+0, y+0)
  166.     when 6; region = $game_map.region_id(x+1, y+0)
  167.     when 7; region = $game_map.region_id(x-1, y-1)
  168.     when 8; region = $game_map.region_id(x+0, y-1)
  169.     when 9; region = $game_map.region_id(x+1, y-1)
  170.     end
  171.     return true if $game_map.all_restrict_regions.include?(region)
  172.     return false if @through
  173.     return true if @vehicle_type != :walk && $game_map.vehicle_restrict_regions.include?(region)
  174.   end
  175.  
  176. end # Game_CharacterBase
  177.  
  178. #==============================================================================
  179. #
  180. # ▼ End of File
  181. #
  182. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement