查看: 2917|回复: 2

[已经解决] 一句脚本使all_restrict_regions成了nil, 如何重建?

[复制链接]
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-10-1 18:22:06 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 alexncf125 于 2020-10-1 18:36 编辑

用了Yanfly的Move Restrict Region后,
如果在Game_Map内建立了这样的一个方法:
  1. class Game_Map
  2.   def reset_map
  3.     @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
  4.   end
  5. end
复制代码
在其他地方调用$game_map.reset_map会报错238行all_restrict_regions为nil
求问如何重新建立all_restrict_regions
  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. $imported = {} if $imported.nil?
  10. $imported["YEA-MoveRestrictRegion"] = true

  11. #==============================================================================
  12. # ▼ Updates
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # 2012.23.08 - Added Feature: <all restrict: x>
  15. # 2012.01.03 - Added Feature: <all restrict: x>
  16. # 2011.12.26 - Bug Fixed: Player Restricted Regions.
  17. # 2011.12.15 - Started Script and Finished.
  18. #
  19. #==============================================================================
  20. # ▼ Introduction
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # Not everybody wants NPC's to travel all over the place. With this script, you
  23. # can set NPC's to be unable to move pass tiles marked by a specified Region.
  24. # Simply draw out the area you want to enclose NPC's in on and they'll be
  25. # unable to move past it unless they have Through on. Likewise, there are
  26. # regions that you can prevent the player from moving onto, too!
  27. #
  28. #==============================================================================
  29. # ▼ Instructions
  30. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  31. # To install this script, open up your script editor and copy/paste this script
  32. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  33. #
  34. # -----------------------------------------------------------------------------
  35. # Map Notetags - These notetags go in the map notebox in a map's properties.
  36. # -----------------------------------------------------------------------------
  37. # <all restrict: x>
  38. # <all restrict: x, x>
  39. # Players and NPC's on the map will be unable to move past region x even if
  40. # they have the "through" flag set. The only thing that can go past is if the
  41. # player is using the debug through flag. Draw out the area you want to close
  42. # the player and NPC's in with the regions and both will be unable to move onto
  43. # any of those tiles marked by region x. If you want to have more regions
  44. # restrict NPC's, insert multiples of this tag.
  45. #
  46. # <npc restrict: x>
  47. # <npc restrict: x, x>
  48. # NPC's on that map will be unable to move past regions x unless they have a
  49. # "Through" flag on. Draw out the area you want to close NPC's in with the
  50. # regions and the NPC's will be unable to move onto any of those tiles marked
  51. # by region x. If you want to have more regions restrict NPC's, insert
  52. # multiples of this tag.
  53. #
  54. # <player restrict: x>
  55. # <player restrict: x, x>
  56. # Players will not be able to move on tiles marked by region x unless the
  57. # player has a "Through" flag on. Draw out the area you want to close the
  58. # player in with the regions and the player will be unable to move past any of
  59. # those tiles marked by region x. If you want to have more regions restrict the
  60. # player, insert multiples of this tag.
  61. #
  62. #==============================================================================
  63. # ▼ Compatibility
  64. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  65. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  66. # it will run with RPG Maker VX without adjusting.
  67. #
  68. #==============================================================================

  69. module YEA
  70.   module MOVE_RESTRICT
  71.    
  72.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  73.     # - Default Completely Restricted Regions -
  74.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  75.     # If you want there to always be a region ID that will forbid both the
  76.     # player and NPC's from passing through, insert that region ID into the
  77.     # array below. This effect will completely block out both players and NPC's
  78.     # even if they have the "through" flag. However, it does not block the
  79.     # debug_through flag for players.
  80.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  81.     DEFAULT_ALL = [61]
  82.    
  83.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  84.     # - Default Player Restricted Regions -
  85.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86.     # If you want there to always be a region ID that will forbid the player
  87.     # from passing through, insert that region ID into the array below.
  88.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  89.     DEFAULT_PLAYER = [62]
  90.    
  91.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  92.     # - Default NPC Restricted Regions -
  93.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  94.     # If you want there to always be a region ID that will forbid NPC's from
  95.     # passing through, insert that region ID into the array below.
  96.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  97.     DEFAULT_NPC = [63]
  98.    
  99.   end # MOVE_RESTRICT
  100. end # YEA

  101. #==============================================================================
  102. # ▼ Editting anything past this point may potentially result in causing
  103. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  104. # halitosis so edit at your own risk.
  105. #==============================================================================

  106. module YEA
  107.   module REGEXP
  108.   module MAP
  109.    
  110.     ALL_RESTRICT =
  111.       /<(?:ALL_RESTRICT|all restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  112.     NPC_RESTRICT =
  113.       /<(?:NPC_RESTRICT|npc restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  114.     PLAYER_RESTRICT =
  115.       /<(?:PLAYER_RESTRICT|player restrict):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  116.    
  117.   end # MAP
  118.   end # REGEXP
  119. end # YEA

  120. #==============================================================================
  121. # ■ RPG::Map
  122. #==============================================================================

  123. class RPG::Map
  124.   
  125.   #--------------------------------------------------------------------------
  126.   # public instance variables
  127.   #--------------------------------------------------------------------------
  128.   attr_accessor :all_restrict_regions
  129.   attr_accessor :npc_restrict_regions
  130.   attr_accessor :player_restrict_regions
  131.   
  132.   #--------------------------------------------------------------------------
  133.   # common cache: load_notetags_mrr
  134.   #--------------------------------------------------------------------------
  135.   def load_notetags_mrr
  136.     @all_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_ALL.clone
  137.     @npc_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_NPC.clone
  138.     @player_restrict_regions = YEA::MOVE_RESTRICT::DEFAULT_PLAYER.clone
  139.     #---
  140.     self.note.split(/[\r\n]+/).each { |line|
  141.       case line
  142.       #---
  143.       when YEA::REGEXP::MAP::ALL_RESTRICT
  144.         $1.scan(/\d+/).each { |num|
  145.         @all_restrict_regions.push(num.to_i) if num.to_i > 0 }
  146.       when YEA::REGEXP::MAP::NPC_RESTRICT
  147.         $1.scan(/\d+/).each { |num|
  148.         @npc_restrict_regions.push(num.to_i) if num.to_i > 0 }
  149.       when YEA::REGEXP::MAP::PLAYER_RESTRICT
  150.         $1.scan(/\d+/).each { |num|
  151.         @player_restrict_regions.push(num.to_i) if num.to_i > 0 }
  152.       #---
  153.       end
  154.     } # self.note.split
  155.     #---
  156.   end
  157.   
  158. end # RPG::Map

  159. #==============================================================================
  160. # ■ Game_Map
  161. #==============================================================================

  162. class Game_Map
  163.   
  164.   #--------------------------------------------------------------------------
  165.   # alias method: setup
  166.   #--------------------------------------------------------------------------
  167.   alias game_map_setup_mrr setup
  168.   def setup(map_id)
  169.     game_map_setup_mrr(map_id)
  170.     @map.load_notetags_mrr
  171.   end
  172.   
  173.   #--------------------------------------------------------------------------
  174.   # new method: all_restrict_regions
  175.   #--------------------------------------------------------------------------
  176.   def all_restrict_regions
  177.     return @map.all_restrict_regions
  178.   end
  179.   
  180.   #--------------------------------------------------------------------------
  181.   # new method: npc_restrict_regions
  182.   #--------------------------------------------------------------------------
  183.   def npc_restrict_regions
  184.     return @map.npc_restrict_regions
  185.   end
  186.   
  187.   #--------------------------------------------------------------------------
  188.   # new method: player_restrict_regions
  189.   #--------------------------------------------------------------------------
  190.   def player_restrict_regions
  191.     return @map.player_restrict_regions
  192.   end
  193.   
  194. end # Game_Map

  195. #==============================================================================
  196. # ■ Game_CharacterBase
  197. #==============================================================================

  198. class Game_CharacterBase
  199.   
  200.   #--------------------------------------------------------------------------
  201.   # alias method: passable?
  202.   #--------------------------------------------------------------------------
  203.   alias game_characterbase_passable_mrr passable?
  204.   def passable?(x, y, d)
  205.     return false if npc_region_forbid?(x, y, d)
  206.     return false if player_region_forbid?(x, y, d)
  207.     return game_characterbase_passable_mrr(x, y, d)
  208.   end
  209.   
  210.   #--------------------------------------------------------------------------
  211.   # new method: npc_forbid?
  212.   #--------------------------------------------------------------------------
  213.   def npc_region_forbid?(x, y, d)
  214.     return false unless self.is_a?(Game_Event)
  215.     region = 0
  216.     case d
  217.     when 1; region = $game_map.region_id(x-1, y+1)
  218.     when 2; region = $game_map.region_id(x+0, y+1)
  219.     when 3; region = $game_map.region_id(x+1, y+1)
  220.     when 4; region = $game_map.region_id(x-1, y+0)
  221.     when 5; region = $game_map.region_id(x+0, y+0)
  222.     when 6; region = $game_map.region_id(x+1, y+0)
  223.     when 7; region = $game_map.region_id(x-1, y-1)
  224.     when 8; region = $game_map.region_id(x+0, y-1)
  225.     when 9; region = $game_map.region_id(x+1, y-1)
  226.     end
  227.     return true if $game_map.all_restrict_regions.include?(region)
  228.     return false if @through
  229.     return $game_map.npc_restrict_regions.include?(region)
  230.   end
  231.   
  232.   #--------------------------------------------------------------------------
  233.   # new method: player_region_forbid?
  234.   #--------------------------------------------------------------------------
  235.   def player_region_forbid?(x, y, d)
  236.     return false unless self.is_a?(Game_Player)
  237.     return false if debug_through?
  238.     region = 0
  239.     case d
  240.     when 1; region = $game_map.region_id(x-1, y+1)
  241.     when 2; region = $game_map.region_id(x+0, y+1)
  242.     when 3; region = $game_map.region_id(x+1, y+1)
  243.     when 4; region = $game_map.region_id(x-1, y+0)
  244.     when 5; region = $game_map.region_id(x+0, y+0)
  245.     when 6; region = $game_map.region_id(x+1, y+0)
  246.     when 7; region = $game_map.region_id(x-1, y-1)
  247.     when 8; region = $game_map.region_id(x+0, y-1)
  248.     when 9; region = $game_map.region_id(x+1, y-1)
  249.     end
  250.     return true if $game_map.all_restrict_regions.include?(region)
  251.     return false if @through
  252.     return $game_map.player_restrict_regions.include?(region)
  253.   end
  254.   
  255. end # Game_CharacterBase

  256. #==============================================================================
  257. #
  258. # ▼ End of File
  259. #
  260. #==============================================================================
复制代码

老鹰

梦石
40
星屑
38044
在线时间
7127 小时
注册时间
2012-5-26
回帖
3306

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2020-10-1 19:02:54 | 显示全部楼层
你这个就是把 @map 又自己生成了一个,那就检查它这个脚本里对于map生成时,附加了什么处理

比如可以看到 setup 里,它新增了 @map.load_notetags_mrr 处理

然后搜索 load_notetags_mrr ,看到它是给地图数据类新增的处理,然后里面也包含你报错的变量

于是你也新增这个处理就好

点评

感谢帮忙~~中秋节快乐~~  发表于 2020-10-1 19:16

评分

参与人数 3星屑 +100 赞 +2 收起 理由
VIPArcher + 100 认可答案
MCCF + 1 塞糖
alexncf125 + 1 认可答案

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部