设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2431|回复: 2

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

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24242
在线时间
5033 小时
注册时间
2016-3-8
帖子
1618
发表于 2020-10-1 18:22:06 | 显示全部楼层 |阅读模式

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

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

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

用了Yanfly的Move Restrict Region后,
如果在Game_Map内建立了这样的一个方法:
RUBY 代码复制
  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
RUBY 代码复制
  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. #==============================================================================

Lv6.析梦学徒

老鹰

梦石
40
星屑
33387
在线时间
6550 小时
注册时间
2012-5-26
帖子
3178

极短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 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-19 09:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表