VX 스크립트

#==============================================================================
#  ■ Path Finding
#==============================================================================
# Near Fantastica
# Version 1
# 29.11.05
#==============================================================================
# Lets the Player or Event draw a path from an desonation to the source. This
# method is very fast and because the pathfinding is imbedded into the Game
# Character the pathfinding can be interrupted or redrawn at any time.
#==============================================================================
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#==============================================================================
# [VX] Simple Mouse System Note: I edited the method
# character.passable?(x, y, direction) to character.passable?(x, y)
# according to change of this method in VX.
#------------------------------------------------------------------------------

class Game_Character
  #--------------------------------------------------------------------------
  alias nf_pf_game_character_initialize initialize
  alias nf_pf_game_character_update update
  #--------------------------------------------------------------------------
  attr_accessor :map
  attr_accessor :runpath
  #--------------------------------------------------------------------------
  def initialize
    nf_pf_game_character_initialize
    @map = nil
    @runpath = false
  end
  #--------------------------------------------------------------------------
  def update
    run_path if @runpath == true
    nf_pf_game_character_update
  end
  #--------------------------------------------------------------------------
  def run_path
    return if moving?
    step = @map[@x,@y]
    if step == 1
      @map = nil
      @runpath = false
      return
    end
    dir = rand(2)
    case dir
    when 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_up if @map[@x,@y-1] == step - 1 and step != 0
    when 1
      move_up if @map[@x,@y-1] == step - 1 and step != 0
      move_left if @map[@x-1,@y] == step -1 and step != 0
      move_down if @map[@x,@y+1] == step - 1 and step != 0
      move_right if @map[@x+1,@y] == step - 1 and step != 0
    end
  end
  #--------------------------------------------------------------------------
  def find_path(x,y)
    sx, sy = @x, @y
    result = setup_map(sx,sy,x,y)
    @runpath = result[0]
    @map = result[1]
    @map[sx,sy] = result[2] if result[2] != nil
  end
  #--------------------------------------------------------------------------
  def clear_path
    @map = nil
    @runpath = false
  end
  #--------------------------------------------------------------------------
  def setup_map(sx,sy,ex,ey)
    map = Table.new($game_map.width, $game_map.height)
    map[ex,ey] = 1
    old_positions = []
    new_positions = []
    old_positions.push([ex, ey])
    depth = 2
    depth.upto(100){|step|
      loop do
        break if old_positions[0] == nil
        x,y = old_positions.shift
        return [true, map, step] if x == sx and y+1 == sy
        if $game_player.passable?(x, y) and map[x,y + 1] == 0
          map[x,y + 1] = step
          new_positions.push([x,y + 1])
        end
        return [true, map, step] if x-1 == sx and y == sy
        if $game_player.passable?(x, y) and map[x - 1,y] == 0
          map[x - 1,y] = step
          new_positions.push([x - 1,y])
        end
        return [true, map, step] if x+1 == sx and y == sy
        if $game_player.passable?(x, y) and map[x + 1,y] == 0
          map[x + 1,y] = step
          new_positions.push([x + 1,y])
        end
        return [true, map, step] if x == sx and y-1 == sy
        if $game_player.passable?(x, y) and map[x,y - 1] == 0
          map[x,y - 1] = step
          new_positions.push([x,y - 1])
        end
      end
      old_positions = new_positions
      new_positions = []
    }
    return [false, nil, nil]
  end
end
 
class Game_Map
  #--------------------------------------------------------------------------
  alias pf_game_map_setup setup
  #--------------------------------------------------------------------------
  def setup(map_id)
    pf_game_map_setup(map_id)
    $game_player.clear_path
  end
end
 
class Game_Player
  #--------------------------------------------------------------------------
  alias pf_game_player_update update
  #--------------------------------------------------------------------------
  def update
    $game_player.clear_path if Input.dir4 != 0
    pf_game_player_update
  end
end
 
class Interpreter
  #--------------------------------------------------------------------------
  def event
    return $game_map.events[@event_id]
  end
end

-여기 까지-
메인 색쉰 위에 그냥 넣으세요.
이러면 캐릭터가 알아서 함

Comment '6'
  • ?
    제스킨 2008.10.08 17:50

    path finding..
    최소한 이 기능의 설명이나 스크린샷을 올려주셔야 어떤 스크립트 인지 알고 사용할것 아닙니까..

  • ?
    FireFighter 2008.10.09 21:13
    네... 해결 해 줄것입니다....
  • ?
    다크아머 2008.10.25 10:42
    옳소;;
  • profile
    모토키 2008.11.22 16:54
    ???
  • ?
    Soul Breaker 2009.01.07 16:15
    어떤 스크립트인가요..;
  • ?
    루시페르 2009.04.18 10:36
    마우스 시스템에서 아무데나 찍으면 주인공이 알아서
    가장 가까운 거리를 찾아가는 스크립트....
    이것만 올리시면 어떡하시라능...

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 3 습작 2012.12.24 5398
497 장비 Multi-Slot Equipment VX 1.6 by DerVVulfman 1 file Alkaid 2010.09.02 1637
496 Multi-threader snippet by Omegazion Man... 2008.10.28 1107
495 메시지 MultiMessage 멀티 메시지 스크립트 9 file 허걱 2010.02.23 4297
494 그래픽 Multiple Fogs 1.0 4 아방스 2008.03.05 2886
493 저장 Neo Save System V by Helladen(Original by Woratana) 8 Alkaid 2010.09.02 2439
492 저장 Neo Save System VI by Helladen 2 Alkaid 2012.01.15 2886
491 온라인 net VX[ RPGVX 온라인 스크립트 ] 19 file 제로스S2 2009.08.03 6389
490 온라인 NETVX 2버전 18 아방스 2009.02.04 3908
489 타이틀/게임오버 New Title Screen 3 Man... 2008.10.28 1832
488 메시지 NMS 3.0 Beta 주석 번역본(한글) 4 인천항 2010.01.13 3369
487 키입력 No F1, F12 and Alt+Return (Kein F1, F12 und Alt+Eingabe) by cremno 습작 2013.04.19 1046
486 퀘스트 Omegas7's Quest System 3.0 퀘스트 스크립트 5 리프네버 2010.01.09 3452
485 전투 ORBS [새로운 전투 방식] 48 file 아방스 2009.03.04 10210
484 전투 ORBS_v1[1].06 전투시스템. 22 file 할렘 2009.02.06 7406
483 기타 OriginalWij's Script Compilation 1.2 2 Alkaid 2010.09.20 1583
482 이동 및 탈것 Paper Mario Walk 7 file 카르와푸딩의아틀리에 2009.08.19 2697
481 파티 Party Changer 3.9 by Dargor 5 file Alkaid 2010.09.12 2364
» Path Finding 6 Man... 2008.10.08 1530
479 액터 Point Spend System 1.05 by Drago del Fato (포인트로 스탯 올리기) 6 Alkaid 2010.09.08 2612
478 전투 PRABS 2.0 액션배틀시스템 58 file RPGbooster 2008.10.08 7575
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 32 Next
/ 32