질문과 답변

Extra Form



아래와 같은 스크립트를 찾았는데요.


목표지정을 할 때, 특정 숫자로만 할 수 있더군요.


이벤트에 스크립트 입력으로 find_path(이벤트 아이디 ,X좌표,Y좌표) 를 입력하면 됩니다.

그런데 이 목표가 되는 X, Y 값을

특정 변수 값으로 할 순 없을까요?


또한 특정 스위치가 ON 되어있을 때만 이 스크립트가 적용되게 할 수 있을까요?


정리하자면

1. 목표값을 정수입력이 아닌 변수값으로 하고 싶습니다.

2. 특정 스위치가 ON 되었을 때에만 이 스크립트가 적용되게 하고 싶습니다.







------------------------아래는 스크립트 입니다------------------------------------------------------------------


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

# * [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

Comment '4'
  • ?
    lud 2015.07.03 21:23
    특정 스위치가 ON일경우 라는건 find_path를 호출할 때 이벤트에서 조건분기 걸어주면 될거같구요
    변수의 값은 $game_variables[n] 으로 하면 얻을 수 있습니다. n은 변수 번호 적어주면 되구요
    x = $game_variables[nx]; y = $game_variables[ny];
    find_path(event_id, x, y) 하고 nx, ny 에는 각각 변수번호를 적어주면 될것 같네요..^^
  • profile
    찬잎 2015.07.03 22:22
    오오, 답변 감사합니다.
    제가 특정스위치가 ON 되었을때 스크립트가 적용되도록 하고 싶다는 것은
    일단 find_path(-1, x, y)로 스크립트를 호출하면, 플레이어가 x와 y좌표로 완전히 이동할 때까지
    이동이 멈추지 않기 때문이에요.

    플레이어가 x, y좌표로 이동중에 있을 때에 특정 스위치가 ON되면 스크립트 진행이 멈추도록
    하고싶습니다.

    가능할까요?
  • ?
    lud 2015.07.03 23:08

    아...
    그것도 이벤트로 할 수 있어요
    저 스크립트는 이동루트를 만들어 주는거니깐

    커먼이벤트 같은거 만들어서 스위치가 ON 일때 병렬처리로해서
    이동루트설정(내용은 비워두시면 됩니다.)
    스위치OFF

    이런식으로 만들어 주면 멈출거에요..^^

  • profile
    찬잎 2015.07.04 00:03
    아하!
    그런 방법이 있었군요.
    왜 그걸 생각 못했는지;;

    감사합니다, 이외의 뭐라고 드릴 말씀이 없네요 ㅠ

List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12393
RMVXA 인공지능 높이는법 괴물 10 아쳐 2015.07.09 368
RMVXA vx ace 조건분기? 질문입니다/ 1 file 아이디어창고 2015.07.08 150
RMVXA DLC로 받은 음악을 변형해서 사용하는 것이 가능한가요? 1 BioVerLord 2015.07.07 144
RMVXA 게임을 실행하면 검은화면 밖에 안보여요 ;; ㅜㅜ 1 김마루 2015.07.07 284
RMVX srpg2 스크립트의 파티인원증가 file SIES 2015.07.07 151
RMVXA 페이스칩 주위에 배경색이 남아요 2 file 너구리신랑 2015.07.07 203
RMVXA 각자 개인작업하고 합칠 수 있나요? 2 아이디어창고 2015.07.06 165
한글화하는도중 테스트하려는데 막혀버리네요 1 file 뉴클리어비둘기 2015.07.06 201
RMVXA 메시지 스크립트 추천해주세요. 2 maker준 2015.07.05 184
기타 [2d격투2nd] Hit 그래픽이 표시되지 않습니다! 줄기 2015.07.05 115
RMVX 스킬장착 스크립트 제거 file SIES 2015.07.05 136
RMVXA 표시할 수 있는 픽쳐의 제한을 깨는 스크립트는 없을까요? 양갱님 2015.07.04 170
RMVX 특정 이벤트 2 나는인간∀ 2015.07.04 120
RMVXA 길찾기 스크립트에서 변수값을 목표로 설정하고 싶습니다. 4 찬잎 2015.07.03 182
기타 EDGE - 'PNG의 이 파레트 타입에는 대응하지 않습니다' 해결방법 4 file 무브 2015.07.03 188
RMVX 캐릭터 생성의 제한 5 file SIES 2015.07.03 191
RMVXA 전투메시지 스크립트 못찾겠습니다. 2 file 비백 2015.07.02 136
RMVXA 순서변경에서 액터1은 변경할 수 없게 하는 방법(액터1은 무조건 첫번째에) 3 찬잎 2015.07.02 156
RMVXA 턴 당 이동거리 제한 2 강룩희 2015.07.02 172
RMVX 에틴님의 srpg 한글화 ver.100907 스크립트 오류 3 file SIES 2015.07.02 251
Board Pagination Prev 1 ... 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 ... 516 Next
/ 516