查看: 2088|回复: 2

[已经过期] 这个八方向脚本为什么触发不了战斗

[复制链接]
梦石
0
星屑
17566
在线时间
4250 小时
注册时间
2013-7-18
回帖
2491
发表于 2016-9-23 17:41:01 | 显示全部楼层 |阅读模式

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

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

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



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

点评

什么配合的脚本  发表于 2016-9-23 21:01
不用就能进入战斗了? 那个配合的脚本发一下。我用四方向也试试  发表于 2016-9-23 19:41
退隐....
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部