Ace 스크립트

링크 : http://arcthunder.blogspot.kr/p/rpg-maker.html

예제 : http://www.mediafire.com/download/xu9i56yi6dpsc4b/%5BACE%5D%5BEN%5D+Khas+Pathfinder+1.0.rar


스크립트

---------------------------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------

# * [ACE] Khas Pathfinder

#-------------------------------------------------------------------------------

# * By Khas Arcthunder - arcthunder.site40.net

# * Version: 1.0 EN

# * Released on: 28/02/2012

#

#-------------------------------------------------------------------------------

# * Terms of Use

#-------------------------------------------------------------------------------

# When using any Khas script, you agree with the following terms:

# 1. You must give credit to Khas;

# 2. All Khas scripts are licensed under a Creative Commons license;

# 3. All Khas scripts are for non-commercial projects. If you need some script 

#    for your commercial project (I accept requests for this type of project), 

#    send an email to nilokruch@live.com with your request;

# 4. All Khas scripts are for personal use, you can use or edit for your own 

#    project, but you are not allowed to post any modified version;

# 5. You can’t give credit to yourself for posting any Khas script;

# 6. If you want to share a Khas script, don’t post the script or the direct 

#    download link, please redirect the user to arcthunder.site40.net

# 7. You are not allowed to convert any of Khas scripts to another engine, 

#    such converting a RGSS3 script to RGSS2 or something of that nature.

# Check all terms at http://arcthunder.site40.net/terms/

#

#-------------------------------------------------------------------------------

# * Features

#-------------------------------------------------------------------------------

# Smart pathfinding

# Fast Algorithm

# Easy to use

# Plug'n'Play

# Game_Character objects compatible

# Log tool

#

#-------------------------------------------------------------------------------

# * Instructions

#-------------------------------------------------------------------------------

# Use the following code inside the "Call Script" box:

# find_path(id,fx,fy)

# Runs the pathfinder.

# id => An integer, use -1 for game player, 0 for the event that the command

# will be called and X for event ID X.

# fx => X destination

# fy => Y destination

#

# find_path(id,fx,fy,true)

# Call this command if you want the game to wait the moving character.

#

# If you want to enable Pathfinder's logs, set "Log" constant to true.

#

#-------------------------------------------------------------------------------

# * Register

#-------------------------------------------------------------------------------

$khas_awesome = [] if $khas_awesome.nil?

$khas_awesome << ["Pathfinder",1.0]

#-------------------------------------------------------------------------------

# * Script

#-------------------------------------------------------------------------------

class Game_Interpreter

  def find_path(char,fx,fy,wait=false)

    $game_map.refresh if $game_map.need_refresh

    character = get_character(char)

    return if character.nil?

    return unless Path_Core.runnable?(character,fx,fy)

    path = Path_Core.run(character,fx,fy)

    return if path.nil?

    route = RPG::MoveRoute.new

    route.repeat = false

    route.wait = wait

    route.skippable = true

    route.list = []

    path << 0x00

    path.each { |code| route.list << RPG::MoveCommand.new(code)}

    character.force_move_route(route)

    @moving_character = character if wait

  end

end

class Path

  attr_accessor :axis

  attr_accessor :from

  attr_accessor :cost

  attr_accessor :dir

  def initialize(x,y,f,c,d)

    @axis = [x,y]

    @from = f

    @cost = c

    @dir = d

  end

end

module Path_Core

  Log = false

  Directions = {[1,0] => 3,[-1,0] => 2,[0,-1] => 4,[0,1] => 1}

  def self.runnable?(char,x,y)

    return false unless $game_map.valid?(x,y)

    return false if char.collide_with_characters?(x,y)

    $game_map.all_tiles(x,y).each { |id|

    flag = $game_map.tileset.flags[id]

    next if flag & 0x10 != 0

    return flag & 0x0f != 0x0f}

    return false

  end

  def self.run(char,fx,fy)

    return nil if char.x == fx && char.y == fy

    st = Time.now

    @char = char

    @start = Path.new(@char.x,@char.y,nil,0,nil)

    @finish = Path.new(fx,fy,nil,0,nil)

    @list = []

    @queue = []

    @preference = ((@char.x-fx).abs > (@char.y-fy).abs ? 0x0186aa : 0x01d)

    class << @list

      def new_path?(path_class)

        for path in self

          return false if path.axis == path_class.axis

        end

        return true

      end

    end

    class << @queue

      def new_path?(path_class)

        for path in self

          return false if path.axis == path_class.axis

        end

        return true

      end

    end

    if @preference & 0x02 == 0x02

      @queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)

      @queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)

      @queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)

      @queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)

      @list << @start

      loop do

        break if @queue.empty?

        @cpath = @queue[0]

        if @cpath.axis == @finish.axis

          @finish.cost = @cpath.cost

          @finish.from = @cpath

          break

        end

        @list << @cpath

        @path_array = []

        p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])

        p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])

        p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])

        p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])

        @path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)

        @path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)

        @path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)

        @path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)

        @path_array.each { |path| @queue << path }

        @queue.delete(@cpath)

      end

    else

      @queue << Path.new(@char.x+1,@char.y,@start,1,[1,0]) if @char.passable?(@char.x,@char.y,6)

      @queue << Path.new(@char.x-1,@char.y,@start,1,[-1,0]) if @char.passable?(@char.x,@char.y,4)

      @queue << Path.new(@char.x,@char.y+1,@start,1,[0,1]) if @char.passable?(@char.x,@char.y,2)

      @queue << Path.new(@char.x,@char.y-1,@start,1,[0,-1]) if @char.passable?(@char.x,@char.y,8)

      @list << @start

      loop do

        break if @queue.empty?

        @cpath = @queue[0]

        if @cpath.axis == @finish.axis

          @finish.cost = @cpath.cost

          @finish.from = @cpath

          break

        end

        @list << @cpath

        @path_array = []

        p1 = Path.new(@cpath.axis[0]+1,@cpath.axis[1],@cpath,@cpath.cost+1,[1,0])

        p2 = Path.new(@cpath.axis[0]-1,@cpath.axis[1],@cpath,@cpath.cost+1,[-1,0])

        p3 = Path.new(@cpath.axis[0],@cpath.axis[1]+1,@cpath,@cpath.cost+1,[0,1])

        p4 = Path.new(@cpath.axis[0],@cpath.axis[1]-1,@cpath,@cpath.cost+1,[0,-1])

        @path_array << p1 if @char.passable?(@cpath.axis[0],@cpath.axis[1],6) && @list.new_path?(p1) && @queue.new_path?(p1)

        @path_array << p2 if @char.passable?(@cpath.axis[0],@cpath.axis[1],4) && @list.new_path?(p2) && @queue.new_path?(p2)

        @path_array << p3 if @char.passable?(@cpath.axis[0],@cpath.axis[1],2) && @list.new_path?(p3) && @queue.new_path?(p3)

        @path_array << p4 if @char.passable?(@cpath.axis[0],@cpath.axis[1],8) && @list.new_path?(p4) && @queue.new_path?(p4)

        @path_array.each { |path| @queue << path }

        @queue.delete(@cpath)

      end

    end

    if @finish.from.nil?

      return nil

    else

      steps = [@finish.from]

      loop do

        cr = steps[-1]

        if cr.cost == 1

          @result = []

          steps.each { |s| @result << Directions[s.dir]}

          break

        else

          steps << cr.from

        end

      end

      self.print_log(Time.now-st) if Log

      return @result.reverse

    end

  end

  def self.print_log(time)

    print "\n--------------------\n"

    print "Khas Pathfinder\n"

    print "Time: #{time}\n"

    print "Size: #{@result.size}\n"

    print "--------------------\n"

  end

end





사용조건은 크레딧에 Khas 이름을 넣는 것입니다.

  • ?
    비형 2015.07.16 13:23
    혹시 변수값으로 이동도 가능한가요?
  • profile
    찬잎 2015.07.16 15:02
    예를 들어서,
    변수 001 == 목표의 X좌표
    변수 002 == 목표의 Y좌표
    를 대입했다고 치면,

    커맨드의 스크립트에다가

    x = $game_variables[001];
    y = $game_variables[002];
    find_path(id,x,y)

    이렇게 입력해주시면 됩니다.
  • ?
    비형 2015.07.18 03:08
    답변 감사합니다!
    그런데 y에서 오류가 나네요..
    어디서 잘못한건지 ㅜㅜ
  • profile
    찬잎 2015.07.18 21:13
    엥? 저는 이렇게 잘 쓰고 있는데;; 왜 그런지 모르겠네요;;
  • ?
    비형 2015.07.19 18:55
    변수001 -- 목표의 X좌표와,
    변수002 -- 목표의 Y좌표가 이벤트 에디터에서 입력된 상태고,
    조건분기로 스크립트 란에,
    x = $game_variables[001];
    y = $game_variables[002];
    find_path(id,x,y)
    입력했는데, 사용법이 잘못된건가요..?
  • profile
    찬잎 2015.07.19 21:22
    아 설마
    find_path(id,x,y)에서 id를 정말 id로 쓰신건가요!!
    여기서 id는 이벤트 번호입니다.
    움직이고자 하는 이벤트 번호를 써주셔야 되요.
    플레이어라면 -1, 현재 이벤트라면 0,
    그 외에는 해당 이벤트 번호를 써주셔야 합니다.

    그러니까
    1번 이벤트를 움직이고 싶으면
    find_path(1, x, y)로 입력해야죠.
  • ?
    비형 2015.07.19 22:18
    아.. 변수 적을때 [000]세자리를 [0000]로 적어서 오류난 거였어요..
    변수 자릿수가 4자리잖아요.. ㅎ
    답변 일일히 달아주셔서 감사했습니다..^^ 복 많이 받으세요~!!
  • ?
    lud 2015.07.20 22:35
    000빼고 그냥 0,1 해도 변수번호가 됩니다.
    $game_variables[1], $game_variables[2] 이런식으로 할 수 있죠^^
  • ?
    비형 2015.07.21 01:39

    그런 방법도 있었군요..! 알려주셔서 감사합니다 ^^

    혹시 다른 것도 여쭤봐도 될까요..?

    http://avangs.info/index.php?mid=rgss_vx_ace&category=812556&document_srl=1025077 캐릭 머리위에 메세지 띄우는 스크립트인데,
    변수값이 텍스트로 표시되게 할 수 있는 방법이 있을까요..?

  • ?
    lud 2015.07.21 10:25
    이런건 질문답변 게시판에...;;
  • ?
    비형 2015.07.21 11:19
    네 ㅜㅜ
  • ?
    아쳐 2015.07.31 16:21
    길찾기면 공포게임에 사용돼는 그런건가요?
  • ?
    삡코 2015.08.06 06:32

    "사용조건은 크레딧에 Khas 이름을 넣는 것입니다."라는게 무슨뜻인가요? 그리고 이거 그냥 써도 작동이 되네요ㅎ 그런데 렉이 어마무시하게 걸리네요
    제가 뭘 잘못사용하고 있는건가요?

  • profile
    찬잎 2015.08.06 14:52
    이 스크립트를 사용하려면 반드시 제작하고 계신 게임 엔딩 크레딧에
    Khas 를 넣어달라는 겁니다. 저작권이 있는 스크립트니까요.
  • ?
    삡코 2015.08.07 10:08
    아 감사합니다. 그런거군요 ㅇㅇ

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 습작 2012.12.24 5110
공지 RPG VX ACE 유용한 링크 모음 16 아방스 2012.01.03 28925
17 전투 전투시 나오는 메세지 삭제 10 Nintendo 2012.03.03 4358
16 이동 및 탈것 지상 탈것 스크립트 6 file 미루 2013.01.07 4579
15 직업 직업 경험치+능력치 설정 확장 7 file zubako 2015.01.27 3988
14 그래픽 커스텀 아이콘 적용하기 2 file 간로 2015.09.28 2721
13 타이틀/게임오버 코아 코스튬씨의 랜덤 타이틀 스크립트를 VX Ace용으로 변환 (완성판) 2 Alkaid 2012.01.25 3980
12 타이틀/게임오버 코아 코스튬씨의 랜덤 타이틀 출력 스크립트를 VX Ace용으로 변환 (테스트용) 1 Alkaid 2011.12.29 3189
11 전투 콤보 카운팅 시스템 4 아르피쥐 2011.12.18 4589
10 기타 크리스탈 엔진 : 포켓몬 배틀 시스템 7 file 스리아씨 2013.09.24 3894
9 키입력 키 입력 확장 - 전체키 + 마우스입력 40 file 허걱 2012.12.15 5780
8 타이틀/게임오버 타이틀 스크린 커스터마이징 11 file 라실비아 2013.08.12 5153
7 타이틀/게임오버 타이틀 화면 없이 게임을 시작하게 만드는법. 6 마에르드 2012.02.11 4585
6 메시지 텍스트 사운드 이펙트 ( Text Sound Effect ) 10 file 미루 2013.01.10 4284
5 메뉴 파티 개별 인벤토리 스크립트 안나카레리나 2018.06.25 739
4 메시지 한국어 조사 처리 스크립트 (140130) 2 치리 2014.01.31 2647
3 메시지 한국어 조사처리 스크립트 7 Ilike게임 2012.10.09 3603
2 이름입력 한글 이름입력창 23 file 에틴 2012.01.23 11679
1 HUD 화폐단위 표시 구분 5 file 허걱 2014.03.19 2938
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 Next
/ 11