查看: 1732|回复: 7

[已经过期] 鼠标脚本经常报错(可以有偿)

[复制链接]
梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
发表于 2016-10-22 16:07:42 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 452234679 于 2016-11-2 19:39 编辑

游戏中经常报这样的错误:
脚本'Plugin_Mouse01'的39行发生了NoMethodError。undefined method 'size' for nil:NilClass
请问如何解决

附脚本:

  1. #==============================================================================
  2. # ■ 完整鼠标系统(四方向)
  3. #------------------------------------------------------------------------------
  4. #  使用时务必配合专用寻路算法
  5. #   By whbm
  6. #==============================================================================
  7. #下面做一下介绍与使用说明:
  8. #    在屏幕上单击鼠标的时候,会自动进行寻路,这里为了速度更快并且为了进行迷
  9. #宫时的难度寻路被限定在当时的屏幕内部。(否则玩家直接点到终点,呵呵....知道
  10. #后果了吧)
  11. #    在角色移动过程中再次单击鼠标(即双击)并在单击第二次鼠标的时候不松手,
  12. #角色将会跟随鼠标方向移动。(这个应该好理解,不用多说吧)当角色贴着欲被启动
  13. #的事件的时候,单击NPC即可启动事件。若未贴着,将会产生自动寻路到NPC附近的某
  14. #点,那时在单击NPC即可。
  15. #    当鼠标停在某些事件上时候会发现有不同的图标,设置方法为:宝箱事件请在事
  16. #件的执行内容中添加 注释,注释内容为 Item 注意大小写。NPC事件请在事件的执行
  17. #内容中添加 注释注释内容为 NPC 注意大小写。若不箱改变某事件的图标,则不要写
  18. #那两个注释。
  19. #    当把脚本转到您工程的时候千万别忘了那个寻路用的脚本。
  20. #==============================================================================
  21. class Game_Event
  22.   attr_accessor :flag
  23. end
  24. #==============================================================================
  25. # ■ Game_Map
  26. #------------------------------------------------------------------------------
  27. #  处理地图的类。包含卷动以及可以通行的判断功能。
  28. # 本类的实例请参考 $game_map 。
  29. #==============================================================================
  30. class Game_Map
  31.   #--------------------------------------------------------------------------
  32.   # ● 检查鼠标处是否有自定义的事件并返回类型
  33.   #--------------------------------------------------------------------------
  34.   def check_event_custom(mouse_x, mouse_y)
  35.     for event in $game_map.events.values #循环所有事件检查
  36.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / 4
  37.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 4
  38.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  39.         for i in 0...event.list.size
  40.           if event.list.size > 0
  41.           if event.list[i].parameters[0] == "Item" #类型判断
  42.             event.flag = 1
  43.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  44.             event.flag = 2
  45.           elsif event.list[i].parameters[0] == "Enemy" #类型判断
  46.             event.flag = 3
  47.           else
  48.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  49.           end
  50.           return event.flag #返回事件类型标志
  51.           end
  52.         end
  53.       end
  54.     end
  55.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  56.     return $mouse_icon_id #使鼠标图不变化
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 检查鼠标处是否有事件可以开启
  60.   #--------------------------------------------------------------------------
  61.   def check_event_custom_start(mouse_x, mouse_y)
  62.     for event in $game_map.events.values #循环所有事件检查
  63.       #事件角色图片宽度、高度
  64.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  65.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  66.       #判断是否鼠标在事件上
  67.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  68.         way_x = $game_player.x - event.x
  69.         way_y = $game_player.y - event.y
  70.         if ([1, -1].include?($game_player.x-event.x) and $game_player.y-event.y == 0) or ([1, -1].include?($game_player.y-event.y) and $game_player.x-event.x == 0)
  71.           for i in 0...event.list.size
  72.             if ["Item","Npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  73.               #判断主角朝向
  74.               if way_x == -1
  75.                 p_direction = 6 if way_y == 0
  76.               elsif way_x == 0
  77.                 p_direction = 2 if way_y == -1
  78.                 p_direction = 8 if way_y == 1
  79.               else
  80.                 p_direction = 4 if way_y == 0
  81.               end
  82.               event.start #开启事件
  83.               return 1, p_direction #返回即将开启事件以及角色朝向
  84.             end
  85.           end
  86.         end
  87.       end
  88.     end
  89.     return 0, 5 #返回不会开启事件以及角色朝向不变
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  93.   #--------------------------------------------------------------------------
  94.   def check_event_custom_exist(mouse_x, mouse_y)
  95.     for event in $game_map.events.values #循环所有事件检查
  96.       #事件角色图片宽度、高度
  97.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  98.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  99.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  100.         for i in 0...event.list.size
  101.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  102.         end
  103.       end
  104.     end
  105.     return 0, event #返回不存在自定义事件,以及事件体
  106.   end
  107. end


  108. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  109. $敌人选框扩大 = 20
  110. $角色选框扩大 = 30


  111. #==============================================================================
  112. # ● API调用
  113. #==============================================================================
  114. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  115. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  116. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  117. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  118. $Window_HWND = $GetActiveWindow.call
  119. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  120. module Mouse  
  121. LEFT = 0x01
  122. RIGHT = 0x02

  123. def self.init(sprite = nil)
  124.    $ShowCursor.call(0)
  125.    
  126.    @show_cursor = false
  127.    
  128.    @mouse_sprite = Sprite.new
  129.    @mouse_sprite.z = 99999
  130.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Mouse01.png')

  131.    @left_press = false
  132.    @right_press = false
  133.    @left_trigger = false
  134.    @right_trigger = false
  135.    @left_repeat = false
  136.    @right_repeat = false
  137.    @click_lock = false
  138.    
  139.    update
  140. end
  141. def self.exit
  142.    @mouse_sprite.bitmap.dispose
  143.    @mouse_sprite.dispose
  144.    @show_cursor = true
  145.    $ShowCursor.call(1)
  146. end
  147. def self.mouse_debug
  148.    return @mouse_debug.bitmap
  149. end
  150. def self.update
  151.    left_down = $GetKeyState.call(0x01)
  152.    right_down = $GetKeyState.call(0x02)
  153.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  154.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  155.      @a = !@a
  156.    end
  157.    if $scene.is_a?(Scene_Map) == false
  158.      $mouse_icon_id = 0
  159.    end
  160.    if $mouse_icon_id != $mouse_icon_id_last
  161.      case $mouse_icon_id
  162.      when 1
  163.        if @a
  164.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseGetItem01')
  165.        else
  166.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseGetItem02')
  167.        end
  168.      when 2
  169.        if @a
  170.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseTalkTo01')
  171.        else
  172.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseTalkTo02')
  173.        end
  174.      when 3
  175.        if @a
  176.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseEnemy01')
  177.        else
  178.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseEnemy02')
  179.        end
  180.      when 11
  181.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseLowerLeft')
  182.      when 12
  183.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseDown')
  184.      when 13
  185.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseLowerRight')
  186.      when 14
  187.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseLeft')
  188.      when 16
  189.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseRight')
  190.      when 17
  191.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseUpperLeft')
  192.      when 18
  193.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseUp')
  194.      when 19
  195.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-MouseUpperRight')
  196.      when 0
  197.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Mouse01')
  198.      end
  199.      $mouse_icon_id_last = $mouse_icon_id
  200.    end
  201.    @click_lock = false
  202.    mouse_x, mouse_y = self.get_mouse_pos
  203.    if @mouse_sprite != nil
  204.      @mouse_sprite.x = mouse_x
  205.      @mouse_sprite.y = mouse_y
  206.    end
  207.    if left_down[7] == 1
  208.      @left_repeat = (not @left_repeat)
  209.      @left_trigger = (not @left_press)
  210.      @left_press = true
  211.    else
  212.      @left_press = false
  213.      @left_trigger = false
  214.      @left_repeat = false
  215.    end
  216.    if right_down[7] == 1
  217.      @right_repeat = (not @right_repeat)
  218.      @right_trigger = (not @right_press)
  219.      @right_press = true
  220.    else
  221.      @right_press = false
  222.      @right_trigger = false
  223.      @right_repeat = false
  224.    end
  225. end
  226. def self.get_mouse_pos
  227.    point_var = [0, 0].pack('ll')
  228.    if $GetCursorPos.call(point_var) != 0
  229.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  230.        x, y = point_var.unpack('ll')
  231.        if (x < 0) or (x > 10000) then x = 0 end
  232.        if (y < 0) or (y > 10000) then y = 0 end
  233.        if x > 640 then x = 640 end
  234.        if y > 480 then y = 480 end
  235.        return x, y
  236.      else
  237.        return 0, 0
  238.      end
  239.    else
  240.      return 0, 0
  241.    end
  242. end
  243. def self.press?(mouse_code)
  244.    if mouse_code == LEFT
  245.      if @click_lock
  246.        return false
  247.      else
  248.        return @left_press
  249.      end
  250.    elsif mouse_code == RIGHT
  251.      return @right_press
  252.    else
  253.      return false
  254.    end
  255. end
  256. def self.trigger?(mouse_code)
  257.    if mouse_code == LEFT
  258.      if @click_lock
  259.        return false
  260.      else
  261.        return @left_trigger
  262.      end
  263.    elsif mouse_code == RIGHT
  264.      return @right_trigger
  265.    else
  266.      return false
  267.    end
  268. end
  269. def self.repeat?(mouse_code)
  270.    if mouse_code == LEFT
  271.      if @click_lock
  272.        return false
  273.      else
  274.        return @left_repeat
  275.      end
  276.    elsif mouse_code == RIGHT
  277.      return @right_repeat
  278.    else
  279.      return false
  280.    end
  281. end
  282. def self.click_lock?
  283.    return @click_lock
  284. end
  285. def self.click_lock
  286.    @click_lock = true
  287. end
  288. def self.click_unlock
  289.    @click_lock = false
  290. end
  291. end
  292. module Input
  293. if @self_update == nil
  294.    @self_update = method('update')
  295.    @self_press = method('press?')
  296.    @self_trigger = method('trigger?')
  297.    @self_repeat = method('repeat?')
  298. end
  299. def self.update
  300.    @self_update.call
  301.    Mouse.update
  302. end
  303. def self.press?(key_code)
  304.    if @self_press.call(key_code)
  305.      return true
  306.    end
  307.    if key_code == C
  308.      return Mouse.press?(Mouse::LEFT)
  309.    elsif key_code == B
  310.      return Mouse.press?(Mouse::RIGHT)
  311.    else
  312.      return @self_press.call(key_code)
  313.    end
  314. end
  315. def self.trigger?(key_code)
  316.    if @self_trigger.call(key_code)
  317.      return true
  318.    end
  319.    if key_code == C
  320.      return Mouse.trigger?(Mouse::LEFT)
  321.    elsif key_code == B
  322.      return Mouse.trigger?(Mouse::RIGHT)
  323.    else
  324.      return @self_trigger.call(key_code)
  325.    end
  326. end
  327. def self.repeat?(key_code)
  328.    if @self_repeat.call(key_code)
  329.      return true
  330.    end
  331.    if key_code == C
  332.      return Mouse.repeat?(Mouse::LEFT)
  333.    elsif key_code == B
  334.      return Mouse.repeat?(Mouse::RIGHT)
  335.    else
  336.      return @self_repeat.call(key_code)
  337.    end
  338. end
  339. end
  340. class Window_Selectable
  341. if @self_alias == nil
  342.    alias self_update update
  343.    @self_alias = true
  344. end
  345. def update
  346.    self_update
  347.    if self.active and @item_max > 0
  348.      index_var = @index
  349.      tp_index = @index
  350.      mouse_x, mouse_y = Mouse.get_mouse_pos
  351.      mouse_not_in_rect = true
  352.      for i in 0...@item_max
  353.        @index = i
  354.        update_cursor_rect
  355.        top_x = self.cursor_rect.x + self.x + 16
  356.        top_y = self.cursor_rect.y + self.y + 16
  357.        bottom_x = top_x + self.cursor_rect.width
  358.        bottom_y = top_y + self.cursor_rect.height
  359.        if (mouse_x > top_x) and (mouse_y > top_y) and
  360.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  361.          mouse_not_in_rect = false
  362.          if tp_index != @index
  363.            tp_index = @index
  364.            $game_system.se_play($data_system.cursor_se)
  365.          end
  366.          break
  367.        end
  368.      end
  369.      if mouse_not_in_rect
  370.        @index = index_var
  371.        update_cursor_rect
  372.        Mouse.click_lock
  373.      else
  374.        Mouse.click_unlock               
  375.      end
  376.    end
  377. end
  378. end
  379. class Window_NameInput
  380. if @self_alias == nil
  381.    alias self_update update
  382.    @self_alias = true
  383. end
  384. def update
  385.    self_update
  386.    if self.active
  387.      index_var = @index
  388.      mouse_x, mouse_y = Mouse.get_mouse_pos
  389.      mouse_not_in_rect = true
  390.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  391.        @index = i
  392.        update_cursor_rect
  393.        top_x = self.cursor_rect.x + self.x + 16
  394.        top_y = self.cursor_rect.y + self.y + 16
  395.        bottom_x = top_x + self.cursor_rect.width
  396.        bottom_y = top_y + self.cursor_rect.height
  397.        if (mouse_x > top_x) and (mouse_y > top_y) and
  398.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  399.          mouse_not_in_rect = false
  400.          break
  401.        end
  402.      end
  403.      if mouse_not_in_rect
  404.        @index = index_var
  405.        update_cursor_rect
  406.        Mouse.click_lock
  407.      else
  408.        Mouse.click_unlock
  409.      end
  410.    end
  411. end
  412. end
  413. class Window_InputNumber
  414. if @self_alias == nil
  415.    alias self_update update
  416.    @self_alias = true
  417. end
  418. def update
  419.    self_update
  420.    mouse_x, mouse_y = Mouse.get_mouse_pos
  421.    if self.active and @digits_max > 0
  422.      index_var = @index
  423.      mouse_not_in_rect = true
  424.      for i in 0...@digits_max
  425.        @index = i
  426.        update_cursor_rect
  427.        top_x = self.cursor_rect.x + self.x + 16
  428.        bottom_x = top_x + self.cursor_rect.width
  429.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  430.          mouse_not_in_rect = false
  431.          break
  432.        end
  433.      end
  434.      if mouse_not_in_rect
  435.        @index = index_var
  436.        update_cursor_rect
  437.        Mouse.click_lock
  438.      else
  439.        Mouse.click_unlock
  440.      end
  441.    end
  442.    if @last_mouse_y == nil
  443.      @last_mouse_y = mouse_y
  444.    end
  445.    check_pos = (@last_mouse_y - mouse_y).abs
  446.    if check_pos > 10
  447.      $game_system.se_play($data_system.cursor_se)
  448.      place = 10 ** (@digits_max - 1 - @index)
  449.      n = @number / place % 10
  450.      @number -= n * place
  451.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  452.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  453.      @number += n * place
  454.      refresh
  455.      @last_mouse_y = mouse_y
  456.    end
  457. end
  458. end
  459. class Scene_File
  460. if @self_alias == nil
  461.    alias self_update update
  462.    @self_alias = true
  463. end
  464. def update
  465.    mouse_x, mouse_y = Mouse.get_mouse_pos
  466.    Mouse.click_lock
  467.    idx = 0
  468.    for i in @savefile_windows
  469.      top_x = i.x + 16
  470.      top_y = i.y + 16
  471.      bottom_x = top_x + i.width
  472.      bottom_y = top_y + i.height
  473.      if (mouse_x > top_x) and (mouse_y > top_y) and
  474.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  475.        i.selected = true
  476.        if @file_index != idx
  477.          @file_index = idx
  478.          $game_system.se_play($data_system.cursor_se)
  479.        end            
  480.        Mouse.click_unlock
  481.      else
  482.        i.selected = false
  483.      end
  484.      idx += 1
  485.    end
  486.    self_update
  487. end
  488. end
  489. class Arrow_Enemy
  490. if @self_alias == nil
  491.    alias self_update update
  492.    @self_alias = true
  493. end
  494. def update
  495.    mouse_x, mouse_y = Mouse.get_mouse_pos
  496.    idx = 0
  497.    for i in $game_troop.enemies do
  498.      if i.exist?
  499.        top_x = i.screen_x - self.ox
  500.        top_y = i.screen_y - self.oy
  501.        bottom_x = top_x + self.src_rect.width
  502.        bottom_y = top_y + self.src_rect.height
  503.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  504.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  505.          if @index != idx
  506.            $game_system.se_play($data_system.cursor_se)
  507.            @index = idx
  508.          end
  509.        end
  510.      end
  511.      idx += 1
  512.    end
  513.    self_update
  514. end
  515. end
  516. class Arrow_Actor
  517. if @self_alias == nil
  518.    alias self_update update
  519.    @self_alias = true
  520. end
  521. def update
  522.    mouse_x, mouse_y = Mouse.get_mouse_pos
  523.    idx = 0
  524.    for i in $game_party.actors do
  525.      if i.exist?
  526.        top_x = i.screen_x - self.ox
  527.        top_y = i.screen_y - self.oy
  528.        bottom_x = top_x + self.src_rect.width
  529.        bottom_y = top_y + self.src_rect.height
  530.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  531.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  532.          if @index != idx
  533.            $game_system.se_play($data_system.cursor_se)
  534.            @index = idx
  535.          end
  536.        end
  537.      end
  538.      idx += 1
  539.    end
  540.    self_update
  541. end
  542. end
  543. #==============================================================================
  544. # ■ Game_Player
  545. #------------------------------------------------------------------------------
  546. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  547. # 本类的实例请参考 $game_player。
  548. #   鼠标控制角色的主程序
  549. #==============================================================================
  550. class Game_Player
  551. if @self_alias == nil
  552.    alias self_update update
  553.    @self_alias = true
  554. end
  555. #--------------------------------------------------------------------------
  556. # ● 得到鼠标的状态
  557. #--------------------------------------------------------------------------
  558. def get_mouse_sta
  559.    return @mouse_sta
  560. end
  561. #--------------------------------------------------------------------------
  562. # ● 完整鼠标系统
  563. #--------------------------------------------------------------------------
  564. def update
  565.    mouse_x, mouse_y = Mouse.get_mouse_pos
  566.    @mtp_x = mouse_x
  567.    @mtp_y = mouse_y
  568.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  569.      #得到鼠标图标方向
  570.      $mouse_icon_id = $game_map.check_event_custom(mouse_x,mouse_y)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  571.    else
  572.      #令鼠标图标为正常
  573.      $mouse_icon_id = 0 if @mouse_sta != 2
  574.    end
  575.    
  576.    #单击鼠标时进行判断寻路或跟随
  577.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  578.      unless $game_system.map_interpreter.running? or
  579.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  580.        #初始化
  581.        @mouse_sta = 1
  582.        p_direction = 5
  583.        #检查鼠标处能否开启事件
  584.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  585.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  586.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  587.        if @mouse_sta != 2
  588.          #鼠标状态不为跟随状态则取数据并初始化路径
  589.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  590.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  591.          @paths = []
  592.          @paths_id = 0
  593.          if event_start == 0 #若不能开启事件
  594.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  595.              find_path = Find_Path.new
  596.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  597.            end
  598.          else #若能开启事件则改变角色朝向
  599.            @direction = p_direction
  600.          end
  601.        end
  602.      end
  603.    end

  604.    #开始移动
  605.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  606.      unless moving? or $game_system.map_interpreter.running? or
  607.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  608.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  609.          case @paths[@paths_id] #判断路径
  610.          when 6
  611.            @last_move_x = true
  612.            move_right
  613.            @paths_id += 1
  614.            @direction = 6
  615.          when 4
  616.            @last_move_x = true
  617.            move_left
  618.            @paths_id += 1
  619.            @direction = 4
  620.          when 2
  621.            @last_move_x = false
  622.            move_down
  623.            @direction = 2
  624.            @paths_id += 1
  625.          when 8
  626.            @last_move_x = false
  627.            move_up
  628.            @direction = 8
  629.            @paths_id += 1
  630.          end
  631.        end
  632.      end
  633.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  634.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  635.        unless moving? or $game_system.map_interpreter.running? or
  636.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  637.          #跟随方向判断并跟随
  638.          if @mtp_x > self.screen_x
  639.            if @mtp_y - self.screen_y > - ( @mtp_x - self.screen_x ) and
  640.               @mtp_y - self.screen_y < @mtp_x - self.screen_x
  641.              move_right
  642.              $mouse_icon_id = 16
  643.              @direction = 6
  644.            end
  645.            if @mtp_y - self.screen_y > @mtp_x - self.screen_x
  646.              move_down
  647.              $mouse_icon_id = 12
  648.              @direction = 2
  649.            end
  650.            if @mtp_y - self.screen_y < - ( @mtp_x - self.screen_x )
  651.              move_up
  652.              $mouse_icon_id = 18
  653.              @direction = 8
  654.            end
  655.          end
  656.          if @mtp_x < self.screen_x
  657.            if @mtp_y - self.screen_y > - ( self.screen_x - @mtp_x ) and
  658.               @mtp_y - self.screen_y < self.screen_x - @mtp_x
  659.              move_left
  660.              $mouse_icon_id = 14
  661.              @direction = 4
  662.            end
  663.            if @mtp_y - self.screen_y > self.screen_x - @mtp_x
  664.              move_down
  665.              $mouse_icon_id = 12
  666.              @direction = 2
  667.            end
  668.            if @mtp_y - self.screen_y < - ( self.screen_x - @mtp_x )
  669.              move_up
  670.              $mouse_icon_id = 18
  671.              @direction = 8
  672.            end
  673.          end
  674.        end
  675.      else #没状态的情况
  676.        $mouse_icon_id = 0
  677.        @mouse_sta = 0
  678.        @paths_id = @paths.size #终止寻路移动
  679.      end
  680.    end
  681. self_update
  682. end
  683. end
  684. Mouse.init
  685. END { Mouse.exit }
复制代码

点评

把那行改成:for i in 0...event.pages[0].list.size 试试  发表于 2016-10-22 22:34
梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-10-22 23:30:49 | 显示全部楼层
还是会报错:undefined method 'pages' for #<Game_Event:0x242f340>

点评

要么在35行后面加一句:next if event.nil? 试试  发表于 2016-10-23 11:08
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-10-23 20:34:43 | 显示全部楼层
452234679 发表于 2016-10-22 23:30
还是会报错:undefined method 'pages' for #

您好,感谢您的回复。不过还是有问题:undefined method 'size' for nil:NilClass
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-11-2 19:39:34 | 显示全部楼层
请问哪位大神愿意帮忙解决一下吗,愿意有偿解决

点评

你发一下工程看看  发表于 2016-11-3 01:29
回复

使用道具 举报

梦石
0
星屑
1392
在线时间
604 小时
注册时间
2011-4-30
回帖
4

开拓者

发表于 2016-11-17 13:05:22 | 显示全部楼层
在39行前加上  if event.list != nil
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部