Project1

标题: 这个八方向脚本为什么触发不了战斗 [打印本页]

作者: y967    时间: 2016-9-23 17:41
标题: 这个八方向脚本为什么触发不了战斗
本帖最后由 y967 于 2016-9-23 17:42 编辑

RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4. #==============================================================================
  5. #
  6. # XP版八方向移动及遇到障碍自动转向脚本整合 by 7408,使用和转载请保留此信息
  7. # 效果:实现手感加强的八方向移动,遇到障碍自动绕开
  8. # 使用:将此脚本插入到Main前即可,面对事件不进行自动转向,
  9. #      对于个别需要自动转向的事件,在该事件的第一页
  10. #      第一行写一句注释"not_npc"(不含引号),
  11. #      如不需要自动转向功能请删掉354行到593行的内容(就是保留最后一个end)
  12. #
  13. #==============================================================================
  14. class Game_Player < Game_Character
  15.   #--------------------------------------------------------------------------
  16.   # ● 画面更新
  17.   #--------------------------------------------------------------------------
  18.   def update
  19.     # 本地变量记录移动信息
  20.     last_moving = moving?
  21.     # 移动中、事件执行中、强制移动路线中、
  22.     # 信息窗口一个也不显示的时候
  23.     unless moving? or $game_system.map_interpreter.running? or
  24.            @move_route_forcing or $game_temp.message_window_showing
  25.       # 如果方向键被按下、主角就朝那个方向移动
  26.       case Input.dir8
  27.       when 1
  28.         move_lower_left
  29.       when 2
  30.         move_down
  31.       when 3
  32.         move_lower_right
  33.       when 4
  34.         move_left
  35.       when 6
  36.         move_right
  37.       when 7
  38.         move_upper_left
  39.       when 8
  40.         move_up
  41.       when 9
  42.         move_upper_right
  43.       end
  44.     end
  45.  
  46.     # 本地变量记忆坐标
  47.     last_real_x = @real_x
  48.     last_real_y = @real_y
  49.     super
  50.     # 角色向下移动、画面上的位置在中央下方的情况下
  51.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  52.       # 画面向下卷动
  53.       $game_map.scroll_down(@real_y - last_real_y)
  54.     end
  55.     # 角色向左移动、画面上的位置在中央左方的情况下
  56.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  57.       # 画面向左卷动
  58.       $game_map.scroll_left(last_real_x - @real_x)
  59.     end
  60.     # 角色向右移动、画面上的位置在中央右方的情况下
  61.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  62.       # 画面向右卷动
  63.       $game_map.scroll_right(@real_x - last_real_x)
  64.     end
  65.     # 角色向上移动、画面上的位置在中央上方的情况下
  66.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  67.       # 画面向上卷动
  68.       $game_map.scroll_up(last_real_y - @real_y)
  69.     end
  70.     # 不在移动中的情况下
  71.     unless moving?
  72.       # 上次主角移动中的情况
  73.       if last_moving
  74.         # 与同位置的事件接触就判定为事件启动
  75.         result = check_event_trigger_here([1,2])
  76.         # 没有可以启动的事件的情况下
  77.         if result == false
  78.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  79.           unless $DEBUG and Input.press?(Input::CTRL)
  80.             # 遇敌计数下降
  81.             if @encounter_count > 0
  82.               @encounter_count -= 1
  83.             end
  84.           end
  85.         end
  86.       end
  87.       # 按下 C 键的情况下
  88.       if Input.trigger?(Input::C)
  89.         # 判定为同位置以及正面的事件启动
  90.         check_event_trigger_here([0])
  91.         check_event_trigger_there([0,1,2])
  92.       end
  93.     end
  94.   end
  95. end
  96. class Game_Character
  97.   #--------------------------------------------------------------------------
  98.   # ● 向左下移动
  99.   #--------------------------------------------------------------------------
  100.   def move_lower_left
  101.     # 没有固定面向的场合
  102.     unless @direction_fix
  103.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  104.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  105.     end
  106.     # 下→左、左→下 的通道可以通行的情况下
  107.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
  108.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  109.       # 更新坐标
  110.       @x -= 1
  111.       @y += 1
  112.       # 增加步数
  113.       increase_steps
  114.     # 下→左能够通行的情况下
  115.     elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
  116.       # 向下移动后向左移动
  117.       move_down
  118.       move_left
  119.     # 左→下能够通行的情况下
  120.     elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  121.       # 向左移动后向下移动
  122.       move_left
  123.       move_down
  124.     # 如果移动的对象是角色且非强制移动
  125.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  126.       # 面向左时
  127.       if @direction = 4
  128.         # 左方可以通行时
  129.         if passable?(@x, @y, 4)
  130.           # 向左移动
  131.           move_left
  132.         # 不能通行时
  133.         else
  134.           # 左面接触事件启动
  135.           result = check_event_trigger_touch(@x-1, @y)
  136.           # 没有事件的情况下
  137.           unless result
  138.             # 向下移动
  139.             move_down
  140.           end
  141.         end
  142.       # 不面向左时
  143.       else
  144.         # 下方可以通行时
  145.         if passable?(@x, @y, 2)
  146.           # 向下移动
  147.           move_down
  148.         # 不能通行时
  149.         else
  150.           # 下面接触事件启动
  151.           result = check_event_trigger_touch(@x, @y+1)
  152.           # 没有事件的情况下
  153.           unless result
  154.             # 向左移动
  155.             move_left
  156.           end
  157.         end
  158.       end
  159.     end
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● 向右下移动
  163.   #--------------------------------------------------------------------------
  164.   def move_lower_right
  165.     # 没有固定面向的场合
  166.     unless @direction_fix
  167.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  168.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  169.     end
  170.     # 下→右、右→下 的通道可以通行的情况下
  171.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  172.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  173.       # 更新坐标
  174.       @x += 1
  175.       @y += 1
  176.       # 增加步数
  177.       increase_steps
  178.     # 下→右能够通行的情况下
  179.     elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6))
  180.       # 向下移动后向右移动
  181.       move_down
  182.       move_right
  183.     # 右→下能够通行的情况下
  184.     elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  185.       # 向右移动后向下移动
  186.       move_right
  187.       move_down
  188.     # 如果移动的对象是角色且非强制移动
  189.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  190.       # 面向右时
  191.       if @direction = 6
  192.         # 右方可以通行时
  193.         if passable?(@x, @y, 6)
  194.           # 向右移动
  195.           move_right
  196.         # 不能通行时
  197.         else
  198.           # 右面接触事件启动
  199.           result = check_event_trigger_touch(@x+1, @y)
  200.           # 没有事件的情况下
  201.           unless result
  202.             # 向下移动
  203.             move_down
  204.           end
  205.         end
  206.       # 不面向右时
  207.       else
  208.         # 下方可以通行时
  209.         if passable?(@x, @y, 2)
  210.           # 向下移动
  211.           move_down
  212.         # 不能通行时
  213.         else
  214.           # 下面接触事件启动
  215.           result = check_event_trigger_touch(@x, @y+1)
  216.           # 没有事件的情况下
  217.           unless result
  218.             # 向右移动
  219.             move_right
  220.           end
  221.         end
  222.       end
  223.     end
  224.   end
  225.   #--------------------------------------------------------------------------
  226.   # ● 向左上移动
  227.   #--------------------------------------------------------------------------
  228.   def move_upper_left
  229.     # 没有固定面向的场合
  230.     unless @direction_fix
  231.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  232.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  233.     end
  234.     # 上→左、左→上 的通道可以通行的情况下
  235.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  236.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  237.       # 更新坐标
  238.       @x -= 1
  239.       @y -= 1
  240.       # 增加步数
  241.       increase_steps
  242.     # 上→左能够通行的情况下
  243.     elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4))
  244.       # 向上移动后向左移动
  245.       move_up
  246.       move_left
  247.     # 左→上能够通行的情况下
  248.     elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  249.       # 向左移动后向上移动
  250.       move_left
  251.       move_up
  252.     # 如果移动的对象是角色且非强制移动
  253.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  254.       # 面向左时
  255.       if @direction = 4
  256.         # 左方可以通行时
  257.         if passable?(@x, @y, 4)
  258.           # 向左移动
  259.           move_left
  260.         # 不能通行时
  261.         else
  262.           # 左面接触事件启动
  263.           result = check_event_trigger_touch(@x-1, @y)
  264.           # 没有事件的情况下
  265.           unless result
  266.             # 向上移动
  267.             move_up
  268.           end
  269.         end
  270.       # 不面向左时
  271.       else
  272.         # 上方可以通行时
  273.         if passable?(@x, @y, 8)
  274.           # 向上移动
  275.           move_up
  276.         # 不能通行时
  277.         else
  278.           # 上面接触事件启动
  279.           result = check_event_trigger_touch(@x, @y-1)
  280.           # 没有事件的情况下
  281.           unless result
  282.             # 向左移动
  283.             move_left
  284.           end
  285.         end
  286.       end
  287.     end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # ● 向右上移动
  291.   #--------------------------------------------------------------------------
  292.   def move_upper_right
  293.     # 没有固定面向的场合
  294.     unless @direction_fix
  295.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  296.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  297.     end
  298.     # 上→右、右→上 的通道可以通行的情况下
  299.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  300.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  301.       # 更新坐标
  302.       @x += 1
  303.       @y -= 1
  304.       # 增加步数
  305.       increase_steps
  306.     # 上→右能够通行的情况下
  307.     elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6))
  308.       # 向上移动后向右移动
  309.       move_up
  310.       move_right
  311.     # 右→上能够通行的情况下
  312.     elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  313.       # 向右移动后向上移动
  314.       move_right
  315.       move_up
  316.     # 如果移动的对象是角色且非强制移动
  317.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  318.       # 面向右时
  319.       if @direction = 6
  320.         # 右方可以通行时
  321.         if passable?(@x, @y, 6)
  322.           # 向右移动
  323.           move_right
  324.         # 不能通行时
  325.         else
  326.           # 右面接触事件启动
  327.           result = check_event_trigger_touch(@x+1, @y)
  328.           # 没有事件的情况下
  329.           unless result
  330.             # 向上移动
  331.             move_up
  332.           end
  333.         end
  334.       # 不面向右时
  335.       else
  336.         # 上方可以通行时
  337.         if passable?(@x, @y, 8)
  338.           # 向上移动
  339.           move_up
  340.         # 不能通行时
  341.         else
  342.           # 上面接触事件启动
  343.           result = check_event_trigger_touch(@x, @y-1)
  344.           # 没有事件的情况下
  345.           unless result
  346.             # 向右移动
  347.             move_right
  348.           end
  349.         end
  350.       end
  351.     end
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● 可以通行判定
  355.   #     x : X 坐标
  356.   #     y : Y 坐标
  357.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  358.   #--------------------------------------------------------------------------   
  359.   def passable?(x, y, d)
  360.     #---------------------------
  361.     $isnpc = true
  362.     #---------------------------
  363.     # 求得新的坐标
  364.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  365.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  366.     # 坐标在地图以外的情况
  367.     unless $game_map.valid?(new_x, new_y)
  368.       # 不能通行
  369.       return false
  370.     end
  371.     # 穿透是 ON 的情况下
  372.     if @through
  373.       # 可以通行
  374.       return true
  375.     end
  376.     # 移动者的元件无法来到指定方向的情况下
  377.     unless $game_map.passable?(x, y, d, self)
  378.       # 通行不可
  379.       return false
  380.     end
  381.     # 从指定方向不能进入到移动处的元件的情况下
  382.     unless $game_map.passable?(new_x, new_y, 10 - d)
  383.       # 不能通行
  384.       return false
  385.     end
  386.     # 循环全部事件
  387.     for event in $game_map.events.values
  388.       # 事件坐标于移动目标坐标一致的情况下
  389.       if event.x == new_x and event.y == new_y
  390.         # 穿透为 ON
  391.         unless event.through
  392.           # 自己就是事件的情况下
  393.           if self != $game_player
  394.             # 不能通行
  395.             #---------------------------
  396.             $isnpc = false #if event.list[0].parameters[0] != "not_npc"
  397.             if event.list[0].parameters[0].is_a?(String)
  398.               if event.list[0].parameters[0].include?("not_npc")
  399.                 $isnpc = true
  400.               end
  401.             end
  402.             #---------------------------
  403.             return false
  404.           end
  405.           # 自己是主角、对方的图形是角色的情况下
  406.           if event.character_name != ""
  407.             # 不能通行
  408.             #---------------------------
  409.             $isnpc = false #if event.list[0].parameters[0] != "not_npc"
  410.             if event.list[0].parameters[0].is_a?(String)
  411.               if event.list[0].parameters[0].include?("not_npc")
  412.                 $isnpc = true
  413.               end
  414.             end
  415.             #---------------------------
  416.             return false
  417.           end
  418.         end
  419.       end
  420.     end
  421.     # 主角的坐标与移动目标坐标一致的情况下
  422.     if $game_player.x == new_x and $game_player.y == new_y
  423.       # 穿透为 ON
  424.       unless $game_player.through
  425.         # 自己的图形是角色的情况下
  426.         if @character_name != ""
  427.           # 不能通行
  428.           return false
  429.         end
  430.       end
  431.     end
  432.     # 可以通行
  433.     return true
  434.   end
  435.  
  436.   #--------------------------------------------------------------------------
  437.   # ● 向下移动
  438.   #     turn_enabled : 本场地位置更改许可标志
  439.   #--------------------------------------------------------------------------
  440.   def move_down(turn_enabled = true)
  441.     #---------------------------
  442.     direct = @direction
  443.     #---------------------------
  444.     # 面向下
  445.     if turn_enabled
  446.       turn_down
  447.     end
  448.     # 可以通行的场合
  449.     if passable?(@x, @y, 2)
  450.       # 面向下
  451.       turn_down
  452.       # 更新坐标
  453.       @y += 1
  454.       # 增加步数
  455.       increase_steps
  456.     # 不能通行的情况下
  457.     else
  458.  
  459.      #---------------------------  
  460.     if $isnpc
  461.       if passable?(@x, @y, 6) and passable?(@x+1, @y, 2) and passable?(@x, @y, 4) and passable?(@x-1, @y, 2)
  462.         move_left if direct == 4
  463.         move_right if direct == 6
  464.         if direct == 2 or direct == 8
  465.           randtra = rand(2)
  466.           randtra == 0 ? move_left : move_right
  467.         end
  468.       else
  469.         move_left if passable?(@x, @y, 4) and passable?(@x-1, @y, 2)
  470.         move_right if passable?(@x, @y, 6) and passable?(@x+1, @y, 2)
  471.       end
  472.     end
  473.     #---------------------------
  474.       # 接触事件的启动判定
  475.       check_event_trigger_touch(@x, @y+1)
  476.     end
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # ● 向左移动
  480.   #     turn_enabled : 本场地位置更改许可标志
  481.   #--------------------------------------------------------------------------
  482.   def move_left(turn_enabled = true)
  483.     #---------------------------
  484.     direct = @direction
  485.     #---------------------------
  486.     # 面向左
  487.     if turn_enabled
  488.       turn_left
  489.     end
  490.     # 可以通行的情况下
  491.     if passable?(@x, @y, 4)
  492.       # 面向左
  493.       turn_left
  494.       # 更新坐标
  495.       @x -= 1
  496.       # 增加步数
  497.       increase_steps
  498.     # 不能通行的情况下
  499.     else
  500.  
  501.       #---------------------------
  502.       if $isnpc
  503.       if passable?(@x, @y, 8) and passable?(@x, @y-1, 4) and passable?(@x, @y, 2) and passable?(@x, @y+1, 4)
  504.         move_up if direct == 8
  505.         move_down if direct == 2
  506.         if direct == 4 or direct == 6
  507.           randtra = rand(2)
  508.           randtra == 0 ? move_up : move_down
  509.         end
  510.       else
  511.         move_up if passable?(@x, @y, 8) and passable?(@x, @y-1, 4)
  512.         move_down if passable?(@x, @y, 2) and passable?(@x, @y+1, 4)
  513.       end
  514.       end
  515.       #---------------------------
  516.  
  517.       # 接触事件的启动判定
  518.       check_event_trigger_touch(@x-1, @y)
  519.     end
  520.   end
  521.   #--------------------------------------------------------------------------
  522.   # ● 向右移动
  523.   #     turn_enabled : 本场地位置更改许可标志
  524.   #--------------------------------------------------------------------------
  525.   def move_right(turn_enabled = true)
  526.     #---------------------------
  527.     direct = @direction
  528.     #---------------------------
  529.     # 面向右
  530.     if turn_enabled
  531.       turn_right
  532.     end
  533.     # 可以通行的场合
  534.     if passable?(@x, @y, 6)
  535.       # 面向右
  536.       turn_right
  537.       # 更新坐标
  538.       @x += 1
  539.       # 增加部数
  540.       increase_steps
  541.     # 不能通行的情况下
  542.     else
  543.       #---------------------------
  544.       if $isnpc
  545.       if passable?(@x, @y, 8) and passable?(@x, @y-1, 6) and passable?(@x, @y, 2) and passable?(@x, @y+1, 6)
  546.         move_up if direct == 8
  547.         move_down if direct == 2
  548.         if direct == 4 or direct == 6
  549.           randtra = rand(2)
  550.           randtra == 0 ? move_up : move_down
  551.         end
  552.       else
  553.         move_up if passable?(@x, @y, 8) and passable?(@x, @y-1, 6)
  554.         move_down if passable?(@x, @y, 2) and passable?(@x, @y+1, 6)
  555.       end
  556.       end
  557.       #---------------------------
  558.       # 接触事件的启动判定
  559.       check_event_trigger_touch(@x+1, @y)
  560.     end
  561.   end
  562.   #--------------------------------------------------------------------------
  563.   # ● 向上移动
  564.   #     turn_enabled : 本场地位置更改许可标志
  565.   #--------------------------------------------------------------------------
  566.   def move_up(turn_enabled = true)
  567.     #---------------------------
  568.     direct = @direction
  569.     #---------------------------
  570.     # 面向上
  571.     if turn_enabled
  572.       turn_up
  573.     end
  574.     # 可以通行的情况下
  575.     if passable?(@x, @y, 8)
  576.       # 面向上
  577.       turn_up
  578.       # 更新坐标
  579.       @y -= 1
  580.       # 歩数増加
  581.       increase_steps
  582.     # 不能通行的情况下
  583.     else
  584.       #---------------------------
  585.       if $isnpc
  586.       if passable?(@x, @y, 6) and passable?(@x+1, @y, 8) and passable?(@x, @y, 4) and passable?(@x-1, @y, 8)
  587.         move_left if direct == 4
  588.         move_right if direct == 6
  589.         if direct == 2 or direct == 8
  590.           randtra = rand(2)
  591.           randtra == 0 ? move_left : move_right
  592.         end
  593.       else
  594.         move_left if passable?(@x, @y, 4) and passable?(@x-1, @y, 8)
  595.         move_right if passable?(@x, @y, 6) and passable?(@x+1, @y, 8)
  596.       end
  597.       end
  598.       #---------------------------
  599.       # 接触事件的启动判定
  600.       check_event_trigger_touch(@x, @y-1)
  601.     end
  602.   end
  603. end



怪物设置为事件接触进入战斗,这个八方向脚本为什么不启动事件进入战斗,怪就在身边转,一定要人按方向才可以战斗,而不用这个脚本就正常进入战斗了。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1