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
37 버그픽스 Graphical Object Global Reference ACE (세부적인 에러메세지 없는 RGSS Player 크래쉬 디버거) by Mithran 1 Alkaid 2014.03.03 1522
36 HUD 화폐단위 표시 구분 5 file 허걱 2014.03.19 2938
35 메시지 ListBox - 선택지 확장 스크립트 11 file 허걱 2014.04.03 3368
34 그래픽 Mirror: EvenNumber Pictures - 짝수번호 그림 반전표시 by 허걱 1 file 허걱 2014.05.10 1775
33 메뉴 스텟을 랭크로 나타내기 7 file Yeolde 2014.05.10 3536
32 전투 사이드뷰 배틀 스크립트 (Animated Battlers By Jet10985) 6 file Rebiart 2014.05.18 4517
31 메뉴 Etude87's Menu Editor 44 file 습작 2014.07.17 6993
30 메시지 Message Skip [메세지 스킵] 5 file Lisky 2014.09.09 4168
29 기타 Hurt Faces V1.2 (상처에 고통스러워하는 액터의 얼굴을 출력해봅시다.) 5 file spice 2014.09.19 3003
28 전투 GTBS 2.4 버전 에코 2014.11.28 1889
27 타이틀/게임오버 시작 전 로고 띄우기 7 file 냐냐 2014.12.04 3368
26 기타 메시지 표시 중에 자동으로 타이머 멈추기 1 file Bunny_Boy 2014.12.07 1026
25 전투 theolized 사이드뷰 스크립트 2 하늘바라KSND 2014.12.19 2486
24 기타 Gamepad Extender 습작 2015.01.02 717
23 기타 Improved Input System 1 습작 2015.01.02 976
22 직업 직업 경험치+능력치 설정 확장 7 file zubako 2015.01.27 3988
21 미니맵 Etude87's KMS MiniMap Add-on ver.1.1.4 2 file 습작 2015.04.23 1959
20 메시지 아이템 정보 메세지가 뜨는 아이템 획득 1 폴라 2015.05.21 2229
» 이동 및 탈것 Khas Pathfinder(길찾기 스크립트) 15 찬잎 2015.07.10 1961
18 버그픽스 RGSS3 Unofficial Bug Fix Snippets Alkaid 2015.09.09 662
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 Next
/ 11