질문과 답변

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 21133
RMXP 넷북, 『아수스 Eee PC X101』에서 RMXP가 돌아가나요? 6 Krrrr7 2012.07.24 1449
RMXP 넷 플레이 서버켜는 방법 1 kjh5427 2011.08.20 1573
기타 네트워크 Rpg 1 file 징요팻 2011.01.13 2571
기타 RMMV 네코플레이어로 하려는데 화면이 짤려요 file dwmjinmiw 2019.11.11 1324
Visual Novel 네코노벨로 안드로이드 apk 만드는 방법 2 김훈 2014.10.26 1184
Visual Novel 네코노벨로 미연시를 만드는데 캐릭터 일러스트가 부족하네요 ㅠㅠ 1 AccelHacker 2016.12.04 379
RMVXA 네코rpg alert오류 해결방법 file ksowkdks12 2017.12.24 2908
에러 해결 기타 네코 rpg 칸이랑 이미지랑 안맞아요ㅠ file 망갈릐 2020.02.15 113
기타 네이버 이메일로 보낼려니 이렇게뜨는디... 1 file Kangu 2016.11.01 180
RMXP 네오액알 몬스터끼리 겹침 질문;;; 1 박빙고 2012.01.20 3148
RMVX 네오 세이브 시스템에서 저장슬롯 윈도우의 배치를 다르게 하는 방법 2 file Reverier 2014.04.05 718
RMVX 네오 메시지 시스템 3에서 이름박스에 ":" 표시 없애는 방법... 1 dadadada 2012.09.15 1086
RMXP 내용찼는방법 3 오매갓 2011.11.12 2222
RMVXA 내가 만든게임 다른컴터에 안돌아감 1 도리 2016.11.05 137
RMMV 내 컴에 DLC 이거 있던데 이거 사용해도 되나요? 3 file 해킹당한해커 2018.09.14 168
RMVX 낮과 밤과 빛 스크립트 응용 1 Raychel 2012.02.18 2048
RMMV 낮/밤 설정하는데 질문이 있습니다!! 4 file 돌냥 2018.05.31 722
RMMV 낭떠러지 위에 움직이는 맵타일 만들 수 있나요? (움직이며 탈수 있는 발판) 병달이 2018.03.09 139
플러그인 추천 RMMV 날짜나 시간등을 다루는 플러그인이 있나요? JDG 2020.05.06 126
RMVXA 날씨변경할때 화면색조 2 jindou 2014.08.23 666
Board Pagination Prev 1 ... 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 ... 518 Next
/ 518