查看: 2043|回复: 2

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

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

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

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

×
本帖最后由 y967 于 2016-9-23 17:42 编辑

[pre lang="ruby"]#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
#==============================================================================
#
# XP版八方向移动及遇到障碍自动转向脚本整合 by 7408,使用和转载请保留此信息
# 效果:实现手感加强的八方向移动,遇到障碍自动绕开
# 使用:将此脚本插入到Main前即可,面对事件不进行自动转向,
#      对于个别需要自动转向的事件,在该事件的第一页
#      第一行写一句注释"not_npc"(不含引号),
#      如不需要自动转向功能请删掉354行到593行的内容(就是保留最后一个end)
#
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 画面更新
  #--------------------------------------------------------------------------
  def update
    # 本地变量记录移动信息
    last_moving = moving?
    # 移动中、事件执行中、强制移动路线中、
    # 信息窗口一个也不显示的时候
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # 如果方向键被按下、主角就朝那个方向移动
      case Input.dir8
      when 1
        move_lower_left
      when 2
        move_down
      when 3
        move_lower_right
      when 4
        move_left
      when 6
        move_right
      when 7
        move_upper_left
      when 8
        move_up
      when 9
        move_upper_right
      end
    end

    # 本地变量记忆坐标
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # 角色向下移动、画面上的位置在中央下方的情况下
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # 画面向下卷动
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # 角色向左移动、画面上的位置在中央左方的情况下
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # 画面向左卷动
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # 角色向右移动、画面上的位置在中央右方的情况下
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # 画面向右卷动
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # 角色向上移动、画面上的位置在中央上方的情况下
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # 画面向上卷动
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # 不在移动中的情况下
    unless moving?
      # 上次主角移动中的情况
      if last_moving
        # 与同位置的事件接触就判定为事件启动
        result = check_event_trigger_here([1,2])
        # 没有可以启动的事件的情况下
        if result == false
          # 调试模式为 ON 并且按下 CTRL 键的情况下除外
          unless $DEBUG and Input.press?(Input::CTRL)
            # 遇敌计数下降
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # 按下 C 键的情况下
      if Input.trigger?(Input::C)
        # 判定为同位置以及正面的事件启动
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end
class Game_Character
  #--------------------------------------------------------------------------
  # ● 向左下移动
  #--------------------------------------------------------------------------
  def move_lower_left
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
    end
    # 下→左、左→下 的通道可以通行的情况下
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # 更新坐标
      @x -= 1
      @y += 1
      # 增加步数
      increase_steps
    # 下→左能够通行的情况下
    elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
      # 向下移动后向左移动
      move_down
      move_left
    # 左→下能够通行的情况下
    elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # 向左移动后向下移动
      move_left
      move_down
    # 如果移动的对象是角色且非强制移动
    elsif self.is_a?(Game_Player) and not @move_route_forcing
      # 面向左时
      if @direction = 4
        # 左方可以通行时
        if passable?(@x, @y, 4)
          # 向左移动
          move_left
        # 不能通行时
        else
          # 左面接触事件启动
          result = check_event_trigger_touch(@x-1, @y)
          # 没有事件的情况下
          unless result
            # 向下移动
            move_down
          end
        end
      # 不面向左时
      else
        # 下方可以通行时
        if passable?(@x, @y, 2)
          # 向下移动
          move_down
        # 不能通行时
        else
          # 下面接触事件启动
          result = check_event_trigger_touch(@x, @y+1)
          # 没有事件的情况下
          unless result
            # 向左移动
            move_left
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 向右下移动
  #--------------------------------------------------------------------------
  def move_lower_right
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
    end
    # 下→右、右→下 的通道可以通行的情况下
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # 更新坐标
      @x += 1
      @y += 1
      # 增加步数
      increase_steps
    # 下→右能够通行的情况下
    elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6))
      # 向下移动后向右移动
      move_down
      move_right
    # 右→下能够通行的情况下
    elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # 向右移动后向下移动
      move_right
      move_down
    # 如果移动的对象是角色且非强制移动
    elsif self.is_a?(Game_Player) and not @move_route_forcing
      # 面向右时
      if @direction = 6
        # 右方可以通行时
        if passable?(@x, @y, 6)
          # 向右移动
          move_right
        # 不能通行时
        else
          # 右面接触事件启动
          result = check_event_trigger_touch(@x+1, @y)
          # 没有事件的情况下
          unless result
            # 向下移动
            move_down
          end
        end
      # 不面向右时
      else
        # 下方可以通行时
        if passable?(@x, @y, 2)
          # 向下移动
          move_down
        # 不能通行时
        else
          # 下面接触事件启动
          result = check_event_trigger_touch(@x, @y+1)
          # 没有事件的情况下
          unless result
            # 向右移动
            move_right
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 向左上移动
  #--------------------------------------------------------------------------
  def move_upper_left
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
    end
    # 上→左、左→上 的通道可以通行的情况下
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # 更新坐标
      @x -= 1
      @y -= 1
      # 增加步数
      increase_steps
    # 上→左能够通行的情况下
    elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4))
      # 向上移动后向左移动
      move_up
      move_left
    # 左→上能够通行的情况下
    elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # 向左移动后向上移动
      move_left
      move_up
    # 如果移动的对象是角色且非强制移动
    elsif self.is_a?(Game_Player) and not @move_route_forcing
      # 面向左时
      if @direction = 4
        # 左方可以通行时
        if passable?(@x, @y, 4)
          # 向左移动
          move_left
        # 不能通行时
        else
          # 左面接触事件启动
          result = check_event_trigger_touch(@x-1, @y)
          # 没有事件的情况下
          unless result
            # 向上移动
            move_up
          end
        end
      # 不面向左时
      else
        # 上方可以通行时
        if passable?(@x, @y, 8)
          # 向上移动
          move_up
        # 不能通行时
        else
          # 上面接触事件启动
          result = check_event_trigger_touch(@x, @y-1)
          # 没有事件的情况下
          unless result
            # 向左移动
            move_left
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 向右上移动
  #--------------------------------------------------------------------------
  def move_upper_right
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
    end
    # 上→右、右→上 的通道可以通行的情况下
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # 更新坐标
      @x += 1
      @y -= 1
      # 增加步数
      increase_steps
    # 上→右能够通行的情况下
    elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6))
      # 向上移动后向右移动
      move_up
      move_right
    # 右→上能够通行的情况下
    elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # 向右移动后向上移动
      move_right
      move_up
    # 如果移动的对象是角色且非强制移动
    elsif self.is_a?(Game_Player) and not @move_route_forcing
      # 面向右时
      if @direction = 6
        # 右方可以通行时
        if passable?(@x, @y, 6)
          # 向右移动
          move_right
        # 不能通行时
        else
          # 右面接触事件启动
          result = check_event_trigger_touch(@x+1, @y)
          # 没有事件的情况下
          unless result
            # 向上移动
            move_up
          end
        end
      # 不面向右时
      else
        # 上方可以通行时
        if passable?(@x, @y, 8)
          # 向上移动
          move_up
        # 不能通行时
        else
          # 上面接触事件启动
          result = check_event_trigger_touch(@x, @y-1)
          # 没有事件的情况下
          unless result
            # 向右移动
            move_right
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 可以通行判定
  #     x : X 坐标
  #     y : Y 坐标
  #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  #--------------------------------------------------------------------------   
  def passable?(x, y, d)
    #---------------------------
    $isnpc = true
    #---------------------------
    # 求得新的坐标
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # 坐标在地图以外的情况
    unless $game_map.valid?(new_x, new_y)
      # 不能通行
      return false
    end
    # 穿透是 ON 的情况下
    if @through
      # 可以通行
      return true
    end
    # 移动者的元件无法来到指定方向的情况下
    unless $game_map.passable?(x, y, d, self)
      # 通行不可
      return false
    end
    # 从指定方向不能进入到移动处的元件的情况下
    unless $game_map.passable?(new_x, new_y, 10 - d)
      # 不能通行
      return false
    end
    # 循环全部事件
    for event in $game_map.events.values
      # 事件坐标于移动目标坐标一致的情况下
      if event.x == new_x and event.y == new_y
        # 穿透为 ON
        unless event.through
          # 自己就是事件的情况下
          if self != $game_player
            # 不能通行
            #---------------------------
            $isnpc = false #if event.list[0].parameters[0] != "not_npc"
            if event.list[0].parameters[0].is_a?(String)
              if event.list[0].parameters[0].include?("not_npc")
                $isnpc = true
              end
            end
            #---------------------------
            return false
          end
          # 自己是主角、对方的图形是角色的情况下
          if event.character_name != ""
            # 不能通行
            #---------------------------
            $isnpc = false #if event.list[0].parameters[0] != "not_npc"
            if event.list[0].parameters[0].is_a?(String)
              if event.list[0].parameters[0].include?("not_npc")
                $isnpc = true
              end
            end
            #---------------------------
            return false
          end
        end
      end
    end
    # 主角的坐标与移动目标坐标一致的情况下
    if $game_player.x == new_x and $game_player.y == new_y
      # 穿透为 ON
      unless $game_player.through
        # 自己的图形是角色的情况下
        if @character_name != ""
          # 不能通行
          return false
        end
      end
    end
    # 可以通行
    return true
  end
   
  #--------------------------------------------------------------------------
  # ● 向下移动
  #     turn_enabled : 本场地位置更改许可标志
  #--------------------------------------------------------------------------
  def move_down(turn_enabled = true)
    #---------------------------
    direct = @direction
    #---------------------------
    # 面向下
    if turn_enabled
      turn_down
    end
    # 可以通行的场合
    if passable?(@x, @y, 2)
      # 面向下
      turn_down
      # 更新坐标
      @y += 1
      # 增加步数
      increase_steps
    # 不能通行的情况下
    else
      
     #---------------------------  
    if $isnpc
      if passable?(@x, @y, 6) and passable?(@x+1, @y, 2) and passable?(@x, @y, 4) and passable?(@x-1, @y, 2)
        move_left if direct == 4
        move_right if direct == 6
        if direct == 2 or direct == 8
          randtra = rand(2)
          randtra == 0 ? move_left : move_right
        end
      else
        move_left if passable?(@x, @y, 4) and passable?(@x-1, @y, 2)
        move_right if passable?(@x, @y, 6) and passable?(@x+1, @y, 2)
      end
    end
    #---------------------------
      # 接触事件的启动判定
      check_event_trigger_touch(@x, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # ● 向左移动
  #     turn_enabled : 本场地位置更改许可标志
  #--------------------------------------------------------------------------
  def move_left(turn_enabled = true)
    #---------------------------
    direct = @direction
    #---------------------------
    # 面向左
    if turn_enabled
      turn_left
    end
    # 可以通行的情况下
    if passable?(@x, @y, 4)
      # 面向左
      turn_left
      # 更新坐标
      @x -= 1
      # 增加步数
      increase_steps
    # 不能通行的情况下
    else
      
      #---------------------------
      if $isnpc
      if passable?(@x, @y, 8) and passable?(@x, @y-1, 4) and passable?(@x, @y, 2) and passable?(@x, @y+1, 4)
        move_up if direct == 8
        move_down if direct == 2
        if direct == 4 or direct == 6
          randtra = rand(2)
          randtra == 0 ? move_up : move_down
        end
      else
        move_up if passable?(@x, @y, 8) and passable?(@x, @y-1, 4)
        move_down if passable?(@x, @y, 2) and passable?(@x, @y+1, 4)
      end
      end
      #---------------------------
      
      # 接触事件的启动判定
      check_event_trigger_touch(@x-1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # ● 向右移动
  #     turn_enabled : 本场地位置更改许可标志
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    #---------------------------
    direct = @direction
    #---------------------------
    # 面向右
    if turn_enabled
      turn_right
    end
    # 可以通行的场合
    if passable?(@x, @y, 6)
      # 面向右
      turn_right
      # 更新坐标
      @x += 1
      # 增加部数
      increase_steps
    # 不能通行的情况下
    else
      #---------------------------
      if $isnpc
      if passable?(@x, @y, 8) and passable?(@x, @y-1, 6) and passable?(@x, @y, 2) and passable?(@x, @y+1, 6)
        move_up if direct == 8
        move_down if direct == 2
        if direct == 4 or direct == 6
          randtra = rand(2)
          randtra == 0 ? move_up : move_down
        end
      else
        move_up if passable?(@x, @y, 8) and passable?(@x, @y-1, 6)
        move_down if passable?(@x, @y, 2) and passable?(@x, @y+1, 6)
      end
      end
      #---------------------------
      # 接触事件的启动判定
      check_event_trigger_touch(@x+1, @y)
    end
  end
  #--------------------------------------------------------------------------
  # ● 向上移动
  #     turn_enabled : 本场地位置更改许可标志
  #--------------------------------------------------------------------------
  def move_up(turn_enabled = true)
    #---------------------------
    direct = @direction
    #---------------------------
    # 面向上
    if turn_enabled
      turn_up
    end
    # 可以通行的情况下
    if passable?(@x, @y, 8)
      # 面向上
      turn_up
      # 更新坐标
      @y -= 1
      # 歩数増加
      increase_steps
    # 不能通行的情况下
    else
      #---------------------------
      if $isnpc
      if passable?(@x, @y, 6) and passable?(@x+1, @y, 8) and passable?(@x, @y, 4) and passable?(@x-1, @y, 8)
        move_left if direct == 4
        move_right if direct == 6
        if direct == 2 or direct == 8
          randtra = rand(2)
          randtra == 0 ? move_left : move_right
        end
      else
        move_left if passable?(@x, @y, 4) and passable?(@x-1, @y, 8)
        move_right if passable?(@x, @y, 6) and passable?(@x+1, @y, 8)
      end
      end
      #---------------------------
      # 接触事件的启动判定
      check_event_trigger_touch(@x, @y-1)
    end
  end
end[/pre]


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

点评

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

本版积分规则

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

在本版发帖返回顶部