RPGXP 스크립트

문과 상자를 쉽게 만들수 있는 스크립트

by posted Oct 21, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

#
# 이벤트 이름에 따라 상자 또는 문으로 작동할 수 있도록 합니다.
# 제작자 jinoh67 (nil)
#
# 비밀번호 형식 (xxxx부분) :
#  1714 -> 비밀번호는 1714이다.
#  012345 -> 비밀번호는 012345이다.
#  v32 -> 비밀번호는 32번 변수의 값이다.
#
# 상자 사용 방법 (이벤트 명령 사용 불가능) :
#  이벤트 이름을 다음과 같은 형식으로 지정해준다.
#
#   _CHEST12 -> 12번 아이템을 얻는다.
#   _CHEST12x4 -> 12번 아이템을 4개 얻는다.
#   _CHEST12_PWDxxxx -> 비밀번호를 입력하면 12번 아이템을 얻는다.
#   _CHEST12x4_PWDxxxx -> 비밀번호를 입력하면 12번 아이템을 4개 얻는다.
#   _CHESTPWDxxxx -> 플레이어를 낚는다.
#
# 문 사용 방법 (비밀번호가 맞을 시 이벤트 명령 실행) :
#   이벤트 이름을 다음과 같은 형식으로 지정해준다.
#   _DOORxxxx -> 비밀번호를 입력하면 이벤트 명령을 실행한다.
#


class Game_Event
  def str2num (str, offset = 0, var = nil, bdg = nil, final = nil)
    i = offset
    if final == nil
      final = str.size
    end
    val = 0
    while i < final && '0'[0] <= str[i] && str[i] <= '9'[0]
      val = val * 10 + (str[i] - '0'[0])
      i += 1
    end
    if var != nil && bdg != nil
      eval "#{var} = " + i.to_s, bdg
    end
    return val
  end
  
  def self.setup2
    waitCmd = RPG::MoveCommand.new(15, [2])
    stopCmd = RPG::MoveCommand.new(0, [])
    k = RPG::MoveRoute.new
    k.repeat = false
    k.skippable = false
    k.list = []
    for i in 16..19 do
      k.list.push (RPG::MoveCommand.new(i))
      k.list.push (waitCmd)
    end
    k.list.push (stopCmd)
    @@openChestMoveRoute = k
    k = RPG::MoveRoute.new
    k.repeat = false
    k.skippable = false
    k.list = []
    for i in 0..3 do
      k.list.push (RPG::MoveCommand.new(19 - i))
      if i < 3
        k.list.push (waitCmd)
      end
    end
    k.list.push (stopCmd)
    @@closeChestMoveRoute = k
    k = RPG::MoveRoute.new
    k.repeat = false
    k.skippable = false
    k.list = [RPG::MoveCommand.new(16), stopCmd]
    @@initalChestMoveRoute = k
    @@chest_array = [];
  end

  self.setup2
  
  def scan_pwd (str, offset, var = nil, bdg = nil)
    @pwd_len = 4
    @pwd_type = 0
    @pwd = nil
    if str[offset] == 'v'[0]
      @pwd_type = 1
      @pwd = str2num (str, offset + 1, var, bdg)
    else
      @pwd_type = 2
      k = nil
      @pwd = str2num (str, offset, :k, binding)
      if var != nil && bdg != nil
        eval "#{var} = " + k.to_s, bdg
      end
      @pwd_len = k - offset
      if @pwd_len <= 0
        @pwd_type = 0
        @pwd = nil
        @pwd_len = 0
      end
    end
  end
  
  alias :refresh_old :refresh

  def refresh # call this method at last in refresh method
    refresh_old
    cn = @event.name
    if cn.index ('_CHEST') == 0
      # get chest number
      @chest_id = @@chest_array.index (self)
      if @chest_id == nil
        @chest_id = @@chest_array.push (self).size - 1
      end
      @chest_id += $chest_start
      
      # scan
      i = 0
      @chest_item = str2num (cn, 6, :i, binding)
      if @chest_item <= 0 || $data_items.size <= @chest_item
        @chest_item = nil
      else
        @item_name = $data_items[@chest_item].name
        k = cn.index('x', i)
        if k != nil
          @chest_quantity = str2num (cn, k + 1, :i, binding)
        else
          @chest_quantity = 1
        end
      end
      i = cn.index('_PW', i) # _CHEST_PW
      @pwd_len = 4
      if i == nil
        @pwd_type = 0 # No password
        @pwd = nil
      else
        scan_pwd (cn, i + 3, :i, binding)
      end
      
      # setup
      @walk_anime = false
      @direction_fix = false
      
      # generate
      @list = [
        RPG::EventCommand.new(209, 0, [0, @@initalChestMoveRoute]),
        RPG::EventCommand.new(111, 0, [2, 0, 0]),
          RPG::EventCommand.new(209, 1, [0, @@openChestMoveRoute]),
          RPG::EventCommand.new(250, 1, [RPG::AudioFile.new("044-Chest01")]),
          RPG::EventCommand.new(210, 1, []),
          RPG::EventCommand.new(101, 1, ["상자가 비었다."]),
          RPG::EventCommand.new(209, 1, [0, @@closeChestMoveRoute]),
          RPG::EventCommand.new(250, 1, [RPG::AudioFile.new("024-Door01")]),
        RPG::EventCommand.new(411, 0, [])
        ];
      ind = 1
      if @pwd_type > 0
        @list.push (RPG::EventCommand.new(101, ind, ["비밀번호가 걸려있다."]))
        @list.push (RPG::EventCommand.new(122, ind, [$tmp_id, $tmp_id, 0, 0, 0]))
        @list.push (RPG::EventCommand.new(103, ind, [$tmp_id, @pwd_len]))
        if @pwd_type == 2
          @list.push (RPG::EventCommand.new(111, ind, [1, $tmp_id, 0, @pwd, 0]))
        else
          @list.push (RPG::EventCommand.new(111, ind, [1, $tmp_id, 1, @pwd, 0]))
        end
        ind += 1
      end
      @list.push(RPG::EventCommand.new(209, ind, [0, @@openChestMoveRoute]))
      @list.push(RPG::EventCommand.new(250, ind,
        [RPG::AudioFile.new("044-Chest01")]))
      @list.push(RPG::EventCommand.new(210, ind, []))
      @list.push(RPG::EventCommand.new(123, ind, [0, 0]))
      if @chest_item == nil
        @list.push(RPG::EventCommand.new(101, ind,
          [(@pwd_type > 0 ? "비밀번호까지 걸렸는데 " : "") + "상자가 비었다."]))
      else
        @list.push(RPG::EventCommand.new(126, ind,
          [@chest_item, 0, 0, @chest_quantity]))
        @list.push(RPG::EventCommand.new(101, ind,
          [@item_name + "을 " + @chest_quantity.to_s + "개 얻었다."]))
      end
      @list.push(RPG::EventCommand.new(209, ind, [0, @@closeChestMoveRoute]))
      @list.push(RPG::EventCommand.new(250, ind,
        [RPG::AudioFile.new("024-Door01")]))
      if @pwd_type > 0
        @list.push (RPG::EventCommand.new(411, ind - 1, []))
        @list.push (RPG::EventCommand.new(101, ind, ["비밀번호가 틀린 듯하다."]))
      end
      for i in 0..(ind-1)
        @list.push (RPG::EventCommand.new(0, i, []))
      end
      # @page.list = @list
    elsif cn.index ("_DOOR") == 0
      # get door number
      list_bkup = @list
      scan_pwd (cn, 5)
      if @pwd_type == 0
        return
      end
      @list = [
        RPG::EventCommand.new(111, 0, [2, 0, 1]),
          RPG::EventCommand.new(101, 1, ["비밀번호가 걸려있다."]),
          RPG::EventCommand.new(122, 1, [$tmp_id, $tmp_id, 0, 0, 0]),
          RPG::EventCommand.new(103, 1, [$tmp_id, @pwd_len]),
          RPG::EventCommand.new(111, 1, [1, $tmp_id, 0, @pwd, 5]),
            RPG::EventCommand.new(101, 2, ["비밀번호가 틀린 듯하다."]),
            RPG::EventCommand.new(115, 2, []),
          RPG::EventCommand.new(123, 1, [0, 0]),
        RPG::EventCommand.new(0, 0, [])
      ]
      if (@pwd_type == 1)
        @list[4] = RPG::EventCommand.new(111, 1, [1, $tmp_id, 1, @pwd, 5])
      end
      @list.concat(list_bkup)
    end
  end
end