질문과 답변

Extra Form

=begin
■移動ルート機能ぱわーあっぷ RGSS2 DAIpage■ v0.6

●機能と使い方●
 移動ルートの設定に
  ・最短距離移動(障害物も考慮)
  ・指定エリア内ランダム移動(マップ機能のエリアを使用)
 などを追加します。
 また、移動タイプが「ランダム」でトリガーが「決定ボタン」、プライオリティが
 「通常キャラと同じ」のイベントがプレイヤーに押されていると、
 押された方向に動きます。町中など、狭いところでプレイヤーの通行を邪魔している
 場合などに使えます。

 移動ルートの設定、または自律移動の「カスタム」内のスクリプトで指定します。

【指定位置に向けて最短移動ルートで一歩移動】
 ※ x, yに目標座標を指定。

  target_p_move_auto(x, y)
 
【指定エリア内ランダム移動】お前ここから出てくるなって時に。
 ※ idでエリアを指定。

  move_type_area_random(id)
 
【指定キャラクターに近づく】
 ※ idに目標キャラクターIDを指定。0でプレイヤー。

  target_c_move_auto(id)

 
【通行可能な限り前進、通行不可でランダムに方向転換】

  search_front

 
●再定義している箇所●
  Game_Character、Game_Playerをエイリアス。

 ※同じ箇所を変更するスクリプトと併用した場合は競合する可能性があります。

●参考●
このスクリプトの一部の機能は以下のサイト様のものを参考にVX用に再構築しております。

RPGツクールシステム研究室
http://suppy1632.hp.infoseek.co.jp/

=end
#============================================================================
# カスタマイズポイント
#============================================================================
module DAI_Move
 
  # 指定位置へ最短距離移動時の再計算間隔歩数。
  # 少ないほど精度は高いが重くなる。
  P = 2
 
  # ランダム移動イベントがプレイヤーから遠ざかる機能を使用。
  E = true
 
end

#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :move_type
  attr_reader   :stop_count
  attr_reader   :move_frequency
  #--------------------------------------------------------------------------
  # ● 目的地までの最短経路を作成
  #--------------------------------------------------------------------------
  def search_route(target_x, target_y, type = 0)
    @route_count = 0
    @target_route = []
    return false if target_x == @x and target_y == @y
    @openlist = [@x * 1000 + @y, target_x * 1000 + target_y]
    @closelist = {@x * 1000 + @y=>0, target_x * 1000 + target_y=>1}
    @lootlist = [[],[]]
    @pointer = 0
    while @pointer < @openlist.length
      for i in 1..4
        a = way(i)
        b = @openlist[@pointer]
        c = @lootlist[@pointer]
        if @closelist.include?(a)
          if @closelist[a] != @closelist[b]
            if @closelist[a] == 0
              half_route = c
              half_route.push 5 - i
              perfect_route = @lootlist[@openlist.index(a)]
            else
              half_route = @lootlist[@openlist.index(a)]
              perfect_route = c
              perfect_route.push i
            end
            half_route.reverse!
            perfect_route += half_route
            @target_route = perfect_route
            return @target_route
          end
        else
          if type == 0
            newloot(a, b, c, i) if dir_passable?(b / 1000, b % 1000, i * 2)
          else
            newloot(a, b, c, i) if dir_e_passable?(b / 1000, b % 1000, i * 2)
          end
        end
      end
      @pointer += 1
    end
    return false
  end
  #--------------------------------------------------------------------------
  # ● 座標変換
  #--------------------------------------------------------------------------
  def way(i)
    case i
    when 1 ; a = @openlist[@pointer] + 1
    when 2 ; a = @openlist[@pointer] - 1000
    when 3 ; a = @openlist[@pointer] + 1000
    when 4 ; a = @openlist[@pointer] - 1
    end
    return a
  end
  #--------------------------------------------------------------------------
  # ● 経路追加
  #--------------------------------------------------------------------------
  def newloot(a, b, c, i)
    @openlist.push a
    @closelist[a] = @closelist[b]
    loot = c.dup
    if @closelist[a] == 0
      loot.push i
    else
      loot.push 5 - i
    end
    @lootlist.push loot
  end
  #--------------------------------------------------------------------------
  # ● 指定座標から指定方向への通行可能判定
  #--------------------------------------------------------------------------
  def dir_passable?(x, y, d)
    case d
    when 2 ; a = passable?(x, y + 1)
    when 4 ; a = passable?(x - 1, y)
    when 6 ; a = passable?(x + 1, y)
    when 8 ; a = passable?(x, y - 1)
    end
    return a
  end
  #--------------------------------------------------------------------------
  # ● キャラクターとの衝突を考えない指定方向への通行可能判定
  #--------------------------------------------------------------------------
  def dir_e_passable?(x, y, d)
    case d
    when 2 ; a = e_passable?(x, y + 1)
    when 4 ; a = e_passable?(x - 1, y)
    when 6 ; a = e_passable?(x + 1, y)
    when 8 ; a = e_passable?(x, y - 1)
    end
    return a
  end
  #--------------------------------------------------------------------------
  # ● キャラクターとの衝突を考えない通行可能判定
  #--------------------------------------------------------------------------
  def e_passable?(x, y)
    x = $game_map.round_x(x)
    y = $game_map.round_y(y)
    return false unless $game_map.valid?(x, y)
    return true if @through or debug_through?
    return false unless map_passable?(x, y)
    return true
  end
  #--------------------------------------------------------------------------
  # ● 最短移動ルートの配列に従い移動(イベントコマンド:スクリプト専用)
  #--------------------------------------------------------------------------
  def target_route_move(x, y)
    if search_route(x, y, 0) == false
      search_route(x, y, 1)
    else
      search_route(x, y)
    end
    move_route = RPG::MoveRoute.new
    for i in 0...@target_route.length
      move_route.list[i] = RPG::MoveCommand.new
      move_route.list[i].code = @target_route[i]
    end
    force_move_route(move_route)
    @target_route = []
    return
  end
  #--------------------------------------------------------------------------
  # ● 最短移動ルートの配列に従い一歩だけ移動(移動ルートの指定専用)
  #--------------------------------------------------------------------------
  def target_p_move_auto(x, y)
    if @route_count == DAI_Move::P or @target_route == nil
      if search_route(x, y, 0) == false
        search_route(x, y, 1)
      else
        search_route(x, y)
      end
    end
    case @target_route[@route_count]
    when 1 ; move_down
    when 2 ; move_left
    when 3 ; move_right
    when 4 ; move_up
    end
    @route_count += 1
    return
  end
  #--------------------------------------------------------------------------
  # ● 指定キャラクターに近づく(移動ルートの指定専用)
  #--------------------------------------------------------------------------
  def target_c_move_auto(id)
    if id == 0
      target = $game_player
    else
      target = $game_map.events[id]
    end
    return if target == nil
    target_p_move_auto(target.x, target.y)
  end
  #--------------------------------------------------------------------------
  # ● 通行可能な限り前進、通行不可でランダムに方向転換
  #--------------------------------------------------------------------------
  def search_front
    unless moving?
      if dir_passable?(@x, @y, @direction)
        move_forward
      else
        turn_random
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 移動タイプ : エリア内ランダム
  #--------------------------------------------------------------------------
  def move_type_area_random(id)
    case rand(6)
    when 0..1;  move_area_random(id)
    when 2..4;  move_forward if dir_passable_in_area?(@direction, id)
    when 5;     @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # ● エリア内をランダムに移動
  #--------------------------------------------------------------------------
  def move_area_random(id)
    a = in_area_passable?(id)
    return if a.empty?
    b = rand(a.size)
    case a[b]
    when 2 ; move_down(false)
    when 4 ; move_left(false)
    when 6 ; move_right(false)
    when 8 ; move_up(false)
    end
  end
  #--------------------------------------------------------------------------
  # ● エリア内の通行可能な方向を取得
  #--------------------------------------------------------------------------
  def in_area_passable?(id)
    a = []
    a.push 2 if dir_passable_in_area?(2, id)
    a.push 4 if dir_passable_in_area?(4, id)
    a.push 6 if dir_passable_in_area?(6, id)
    a.push 8 if dir_passable_in_area?(8, id)
    return a
  end
  #--------------------------------------------------------------------------
  # ● 指定方向がエリア内で通行可能か?
  #--------------------------------------------------------------------------
  def dir_passable_in_area?(d, id)
    case d
    when 2
      return $game_map.in_area?(id, @x, @y + 1) && dir_passable?(@x, @y, 2)
    when 4
      return $game_map.in_area?(id, @x - 1, @y) && dir_passable?(@x, @y, 4)
    when 6
      return $game_map.in_area?(id, @x + 1, @y) && dir_passable?(@x, @y, 4)
    when 8
      return $game_map.in_area?(id, @x, @y - 1) && dir_passable?(@x, @y, 8)
    end
  end
  #--------------------------------------------------------------------------
  # ● 移動タイプ : カスタム
  #--------------------------------------------------------------------------
  alias dai_custom_move_move_type_custom move_type_custom
  def move_type_custom
    return if @move_route.list[@move_route_index] == nil
    dai_custom_move_move_type_custom
  end
end
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 接触イベントの起動判定
  #--------------------------------------------------------------------------
  alias dai_custom_move_check_event_trigger_touch check_event_trigger_touch
  def check_event_trigger_touch(x, y)
    for event in $game_map.events_xy(x, y)
      if event.trigger == 0 && event.priority_type == 1 && DAI_Move::E &&
      event.move_type == 1 && event.stop_count > 30 * (4 - event.move_frequency)
        event.move_away_from_player
      end
    end
    dai_custom_move_check_event_trigger_touch(x, y)
  end
end
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
  #--------------------------------------------------------------------------
  # ● エリア内判定
  #--------------------------------------------------------------------------
  def in_area?(id, x, y)
    area = $data_areas[id]
    return false if area == nil
    return false if $game_map.map_id != area.map_id
    return false if x < area.rect.x
    return false if y < area.rect.y
    return false if x >= area.rect.x + area.rect.width
    return false if y >= area.rect.y + area.rect.height
    return true
  end
end


여기에서 어디가 오류가 있는지 그리고 혹시 가능하시다면 오류수정하신걸 댓글로 알려주세요.

Comment '4'
  • ?
    AltusZeon 2014.08.07 17:41

    해당 스크립트는 RGSS2(VX) 스크립트입니다.
    일반적으로 VX Ace에서는 사용이 불가능합니다.

    도움될만한 스레가 있기에 아래에 링크를 적어둡니다.
    http://forums.rpgmakerweb.com/index.php?/topic/11130-is-it-possible-convert-this-script-for-rgss3-for-example-there-is-in-the-witchs-house/

  • ?
    고투더퓨처 2014.08.08 00:36
    아.....
    한번 홈페이지에 들어가 봤는데 영어라 해석이 잘 안되네요....ㅠㅠ
    내용을 어느정도 보니 어떤 외국분이 이문제 때문에 해결이 되었다는 내용은 있네요...ㅜㅜ
    혹시 어떻게 해야하는지 나중에 한번 가르켜 줄수 있나요????........
  • ?
    AltusZeon 2014.08.08 03:00

    해당 스크립트를 대체할 수 있는 비슷한 Path Finding System Script가 VX Ace에도 있다는 내용입니다.
    http://forums.rpgmakerweb.com/index.php?/topic/1640-near-fantasticas-path-finder-v1-for-rpg-maker-vx-ace/
    http://forums.rpgmakerweb.com/index.php?/topic/7659-ses-event-movement-path-finding-patrol-routes-and-more/

  • ?
    고투더퓨처 2014.08.10 17:39
    아 답이 늦었네요....
    감사합니다 ^^.
    한번 시도해버고 나중에 안되면 글을 올리겠습니다...^^

List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12451
이벤트 작성 RMVXA 리셋되는 이벤트를 만들고 싶습니다. 환경사랑 2021.02.12 91
이벤트 작성 RMVXA vx ace 이벤트를 실행하면 이벤트 그래픽이 멋대로 이상하게 바껴요 ㅠㅠ 2 체어링2 2020.01.17 58
이벤트 작성 RMVXA 전투시 캐릭터가 죽었을때 자동으로 파티에서도 사라지게 할수 있나요? 2 겜만들고싶다앙 2021.02.10 93
이벤트 작성 RMVXA 이벤트가 이벤트로 가게 하기 ㅠㅠ 재질문이요 1 수학의정석 2018.12.31 85
이벤트 작성 RMVXA 체력에 따라 자신의 이동속도 감소 이벤트 만드는 법 1 슈필러 2019.02.18 124
이벤트 작성 RMVXA 전투 도중 문장 5 박열정 2019.02.14 73
이벤트 작성 RMVXA 맵을 계속 이동해도 추격자가 자꾸 쫒아오게 하는 방법 4 슈필러 2019.02.21 417
이벤트 작성 RMVXA 일회성 이벤트 만들기 8 file 김꼬비 2019.05.08 210
이벤트 작성 RMVXA 날라오는 투사체 구현 2 힘들다 2019.06.12 169
이벤트 작성 RMVXA 의자를 특정 장소로 이동시킨 후 올라타는 이벤트를 만들고 싶습니다. 5 MAYO 2019.08.17 155
이벤트 작성 RMVXA 확인버튼 눌렀을때 그림 삭제하기 2 MAYO 2019.09.20 350
이벤트 작성 RMVXA 액터 파티를 수시로 변경 하는 법 6 MAYO 2019.10.07 105
이벤트 작성 RMVXA 맵 위에 이미지 얹을수 있나요??ㅠㅠㅠ제발제발요 5 file nucnuc 2019.12.17 122
이벤트 작성 RMVXA 캐릭터가................안 자요................... 2 file nucnuc 2019.12.17 169
이벤트 작성 RMVXA ㅠㅠㅠㅠ이벤트를 플레이어로 전환하고 싶은데요ㅠㅠㅠ☆☆☆☆☆☆☆☆도와주세요☆☆☆☆☆☆☆☆ 3 file nucnuc 2019.12.20 103
이벤트 작성 RMVXA 메이플같은 포탈 만드는법 1 Nam 2020.04.12 78
이벤트 작성 RMVXA 이미 물어본 질문은 선택 못하게 하는 방법 있을까요 ㅠㅠ? 1 체어링2 2020.04.17 93
이벤트 작성 RMVXA 이벤트만 대기시키는 법이 있나요 3 이경로 2020.05.24 114
이벤트 작성 RMVXA 캐릭터가 끌려가는 연출, 제자리 점프하는 연출 어떻게 하나요? 4 코볼트코 2020.10.13 547
이벤트 작성 RMVXA 대화 랜덤문장을 나오게 하기 3 file 코볼트코 2020.10.17 218
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Next
/ 19