질문과 답변

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 12391
이벤트 작성 RMMV 이벤트가 반복 실행되어 끝나지 않습니다.(검색완료) 1 file 2022.02.23 183
기타 기타 게임에다 바람을 만들었는데 1 무명시절 2022.06.26 183
플러그인 추천 RMMV 아이템 목록을 플레이 화면에 띄울 수 없을까요? (HUD Maker..?) Gonac 2020.10.02 182
기타 기타 게임 중에 아이콘과 게임 이름을 바꾸는 방법이 있나요? 3 file JDG 2020.04.22 182
기타 RMMV 맵칩은 크기 변경을 할 수 없나요? 1 짓기힘드러 2020.01.24 182
RMVXA 컴퓨터 포멧이후 갑자기 ㅁㅁㅁ 라고 나옵니다 3 file 클로아 2017.12.20 182
RMMV 아이템 선택 처리를 활용, 이벤트를 진행시키고 싶습니다. 3 겐마 2016.10.04 182
기타 RMVX 공격 메세지 바꾸는법 2 걍사람 2022.01.08 182
RMVXA 전투시 배경 문제 6 file 락취한스님 2016.08.27 182
RMVXA 액터의 레벨을 모두 같게 하고 싶습니다 3 코나별 2016.04.19 182
기타 무보수로 그래픽담당을 구인해도 지원자가 있을까요? 1 NyxLee 2016.05.19 182
RMVX 조사하는 방법 기본적인거요! 2 file 데냐 2015.12.12 182
RMVXA 이벤트 겹치기! 2 삡코 2015.08.06 182
RMVXA 길찾기 스크립트에서 변수값을 목표로 설정하고 싶습니다. 4 찬잎 2015.07.03 182
이벤트 작성 RMMV 아이템(포션)을 거부하는 이벤트 Nix 2022.04.06 182
RMVX 액알 만드는데 장거리 질문점요ㅠㅠ 2 코딩이어려워 2015.01.18 182
스크립트 작성 RMMV alert창에 텍스트와 변수값을 같이 띄우는 방법 2 LV 2021.12.21 181
기본툴 사용법 RMMV 마우스커서변경이랑 클릭이동시 치킨무 없애는법 있을까요? 2 슈트라핀스키 2020.09.08 181
플러그인 사용 RMMV 동시 메시지 플러그인 오류 해결법 1 무명시절 2020.07.23 181
이벤트 작성 RMMV 화면내에서 기술 이펙트 효과 나타내게 어떻게 하나요? 3 file 코볼트코 2021.02.07 181
Board Pagination Prev 1 ... 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 ... 516 Next
/ 516