XP 스크립트

제가 쓰려고 간단히 만들어 본 겁니다.

단순히 아이템을 선택해서 아이템의 ID를 변수에 대입하는 기능입니다.
대입된 변수를 통해 여러가지 이벤트를 만들 수 있겠죠 ...

# ★ 아이템 선택 시스템 ★ 2009.1.29
# 제작자 : lepin@naver.com

# 호출 스크립트 : $scene = Scene_Item_Select.new

# 아이템일 경우 : 변수 값 = 아이템의 ID
# 무기일 경우 : 변수 값 = 무기의 ID + 1000
# 방어구일 경우 : 변수 값 = 방어구의 ID + 2000
# 선택하지 않을 경우 : 변수 값 = 0

# 커스터마이즈
module LEPIN
  # 아이템의 ID를 취득하는 변수의 ID
  ITEM_VARIABLE = 9
  # 선택할 수 있는 아이템에 넣는 속성의 이름 (따움표를 지우지 말것)
  ITEM_ELEMENT = "item_select"
  # 선택된 아이템을 소비한다 (true, false)
  ITEM_LOSE = false
end
# 커스터마이즈 끝

#==============================================================================
# ■ Window_Item_Select
#------------------------------------------------------------------------------
#   아이템 선택용 윈도우
#==============================================================================

class Window_Item_Select < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 오브젝트 초기화
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 640, 416)
    @column_max = 2
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # ● 아이템의 취득
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # ● 리프레쉬
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # 아이템을 추가
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        if $data_items[i].element_set.include?($data_system.elements.index(LEPIN::ITEM_ELEMENT))
          @data.push($data_items[i])
        end
      end
    end
    for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0
        if $data_weapons[i].element_set.include?($data_system.elements.index(LEPIN::ITEM_ELEMENT))
          @data.push($data_weapons[i])
        end
      end
    end
    for i in 1...$data_armors.size
      if $game_party.armor_number(i) > 0
        if $data_armors[i].guard_element_set.include?($data_system.elements.index(LEPIN::ITEM_ELEMENT))
          @data.push($data_armors[i])
        end
      end
    end
    # 항목수가 0 이 아니면 비트 맵을 작성해, 전항목을 묘화
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
   #--------------------------------------------------------------------------
  # ● 항목의 묘화
  #     index : 항목 번호
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    self.contents.font.color = normal_color
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # ● 헬프 텍스트 갱신
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end

#==============================================================================
# ■ Scene_Item_Select
#------------------------------------------------------------------------------
#  아이템 아이템 화면의 처리를 실시하는 클래스입니다.
#==============================================================================

class Scene_Item_Select
  #--------------------------------------------------------------------------
  # ● 메인 처리
  #--------------------------------------------------------------------------
  def main
    # 헬프 윈도우, 아이템 윈도우를 작성
    @help_window = Window_Help.new
    @item_window = Window_Item_Select.new
    # 헬프 윈도우를 관련지어
    @item_window.help_window = @help_window
    # 커맨드 윈도우를 작성 (불가시·비액티브하게 설정)
    s1 = "선택한다"
    s2 = "그만둔다"
    @command_window = Window_Command.new(192, [s1, s2])   
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 240 - @command_window.height / 2
    @command_window.visible = false
    @command_window.active = false
    # 트란지션 실행
    Graphics.transition
    # 메인 루프
    loop do
      # 게임 화면을 갱신
      Graphics.update
      # 입력 정보를 갱신
      Input.update
      # 프레임 갱신
      update
      # 화면이 바뀌면 루프를 중단
      if $scene != self
        break
      end
    end
    # 트란지션 준비
    Graphics.freeze
    # 윈도우를 해방
    @help_window.dispose
    @item_window.dispose
    @command_window.dispose
  end
  #--------------------------------------------------------------------------
  # ● 프레임 갱신
  #--------------------------------------------------------------------------
  def update
    # 윈도우를 갱신
    @help_window.update
    @item_window.update
    @command_window.update
    # 아이템 윈도우가 액티브의 경우: update_item 를 부른다
    if @item_window.active
      update_item
      return
    end
    # 커맨드 윈도우가 액티브의 경우: update_command 를 부른다
    if @command_window.active
      update_command
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 프레임 갱신 (아이템 윈도우가 액티브의 경우)
  #--------------------------------------------------------------------------
  def update_item
    # B 버튼이 밀렸을 경우
    if Input.trigger?(Input::B)
      # 캔슬 SE 를 연주
      $game_system.se_play($data_system.cancel_se)
      # 변수 값 = 0
      $game_variables[LEPIN::ITEM_VARIABLE] = 0
      # 메뉴 화면으로 전환해
      $scene = Scene_Map.new     
      return
    end
    # C 버튼이 밀렸을 경우
    if Input.trigger?(Input::C)
      # 아이템 윈도우로 현재 선택되고 있는 데이터를 취득
      @item = @item_window.item
      # 아이템이 없는 경우
      unless @item.is_a?(RPG::Item) or @item.is_a?(RPG::Weapon) or @item.is_a?(RPG::Armor)
        # 버저 SE 를 연주
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 결정 SE 를 연주
      $game_system.se_play($data_system.decision_se)
      # 커맨드 윈도우를 액티브화
      @item_window.active = false
      @command_window.index = 0
      @command_window.visible = true
      @command_window.active = true
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 프레임 갱신 (커맨드 윈도우)
  #--------------------------------------------------------------------------
  def update_command
    # 커멘드 윈도우를 갱신
    @command_window.update
    # B 버튼이 밀렸을 경우
    if Input.trigger?(Input::B)
      # 캔슬 SE 를 연주
      $game_system.se_play($data_system.cancel_se)
      # 커맨드 윈도우를 액티브화
      @item_window.active = true
      @command_window.visible = false
      @command_window.active = false
      return
    end
    # C 버튼이 밀렸을 경우
    if Input.trigger?(Input::C)
      # 커멘드 윈도우의 커서 위치에서 분기
      case @command_window.index
      when 0  # 선택한다
        # 결정 SE 를 연주
        $game_system.se_play($data_system.decision_se)
        # 아이템/무기/방어구 별로 분류
        case @item
        when RPG::Item
          value = 0
          if LEPIN::ITEM_LOSE == true
          $game_party.lose_item(@item.id, 1)
          end
        when RPG::Weapon         
          value = 1000
          if LEPIN::ITEM_LOSE == true
          $game_party.lose_weapon(@item.id, 1)
          end
        when RPG::Armor
          value = 2000
          if LEPIN::ITEM_LOSE == true
          $game_party.lose_armor(@item.id, 1)
          end
        end
        # 변수를 취득
        $game_variables[LEPIN::ITEM_VARIABLE] = @item.id + value
        # 맵 화면으로 전환
        $scene = Scene_Map.new
      when 1  # 그만둔다
        # 결정 SE 를 연주
        $game_system.se_play($data_system.decision_se)
        # 아이템 윈도우를 액티브화
        @item_window.active = true
        @command_window.visible = false
        @command_window.active = false
      end
      return
    end
    if Input.trigger?(Input::UP) or Input.trigger?(Input::L)
      @command_window.index = 0
    end
    if Input.trigger?(Input::DOWN) or Input.trigger?(Input::R)
      @command_window.index = 1
    end
  end
end


 

Comment '5'
  • ?
    백년술사 2009.01.29 15:59
    어떻게 하는거죠?
    근데 제가 방금 보고 온 아이템 선택하기 같은데...<제목만>
    게임 공작소 치거면 출처를..
  • ?
    백년술사 2009.01.29 16:02
    그리고 이거 어떻게 사용?
  • ?
    레핀 2009.01.29 18:13

    게임공작소에 올린 사람이랑 동일인물이고요 ;
    수정했으니 다시 받아주세요 .....
    이벤트 커맨드 -> 스크립에 $scene = Scene_Item_Select.new 라고 입력해주시면 됩니다.

     
  • ?
    RMdude 2009.02.13 12:05
    이거 오류뜨는 데요
    74 행에 Undefined method 'size' for nil:NilClass 라고
  • ?
    내로미 2010.05.19 21:56

    그런건 어떤 스크립트와 충돌이 일어나서 생긴 문제인데요.

    그건 스크립트의 위치를 바꾸면 될것같습니다.


List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 습작 2012.12.24 6153
921 기타 Defining Encounter Areas by RPG Advocate (사용법 첨부) file 백호 2009.02.22 1201
920 전투 DerVVulfman's addons for Mr.Mo's ABS file Alkaid 2010.09.10 1645
919 기타 Difficulty Options by SephirothSpawn 백호 2009.02.22 869
918 기타 Drago - Custom Resolution by LiTTleDRAgo Alkaid 2014.02.13 1110
917 그래픽 Drago - Custom Resolution II 1 Alkaid 2014.09.10 1004
916 기타 Dynamic Stores by Astro_mech@rmxp.net 1 file 백호 2009.02.22 878
915 아이템 Easy Item & Gold Gain by SephirothSpawn (SDK호환) 백호 2009.02.22 880
914 기타 Economy System by Nick@Creation Asylum 1 file 백호 2009.02.22 934
913 맵/타일 Editor Tiles by PK8 (XP/VX/VXA) Alkaid 2012.09.11 1868
912 기타 Encounter Control by SephirothSpawn (SDK호환) 4 file 백호 2009.02.22 1157
911 기타 endroll 주석 번역 6 file insertend 2010.05.15 1638
910 스킬 Equipment Skills 2.0 by SephirothSpawn file 백호 2009.02.22 1007
909 장비 Equipment Upgrade System 1.1 by Charlie Fleed Alkaid 2010.11.18 1928
908 기타 Etude87_Bone_Animation_Character ver.1.2 4 습작 2012.07.06 1255
907 전투 Etude87_Custom_Slip_Damage_XP ver.1.0 5 습작 2012.08.26 1857
906 메뉴 Etude87_Horror_Menu_XP ver.1.1 15 file 습작 2012.08.04 2762
905 메시지 Etude87_Item_Choice_XP ver.1.10 13 file 습작 2013.05.19 2178
904 맵/타일 Etude87_Map_Remember_XP ver.1.2 2 습작 2012.07.17 1614
903 변수/스위치 Etude87_Variables_XP 2 습작 2011.12.26 2104
902 메뉴 Event Spawner 1 file 백호 2009.02.22 980
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 52 Next
/ 52