じ☆ve冰风 发表于 5 天前

KPocket VX

KPocket VX
version 1.0.6

by Kyonides Arkanthes​


Introduction

Force the player to keep a reduced inventory while in battle!

Of course, the player may choose which items he or she will pack in his or her pocket.

It is possible to call the Pocket menu from the Item menu or the map! :grin:For more information, please read the comments I have included in my script.


VX Script
                Code:       
# * KPocket VX#   Scripter : Kyonides Arkanthes#   v1.0.6 - 2019-12-01# This script allows the player to send specific items, no weapons nor armors# included, to a pocket with a limited storage space. You can open this new menu# via a script call or open the item menu and hitting the OPEN_BUTTON. If the# player opened the new Pocket menu, the player will be able to replenish items# or send them back to their inventory.# Pressing the SEND_ITEM_BUTTON will send an item to the pocket. The amount is# fixed based on the current value of the KPocket.item_limit variable.# * Script Calls *# $scene = KPocketItem.new#   Opens the Pocket Menu!# KPocket.slot_limit = Integer#   Set a new slot limit for your pocket.# KPocket.item_limit = Integer#   Set a new limit for items of the same kind.module KPocketSWITCH_ID = 1 # Switch that activates Pocket instead of BagOPEN_BUTTON = Input::CTRL # Open KPocket Menu!SEND_ITEM_BUTTON = Input::SHIFTHELP_BUTTON = Input::ZHELP_BUTTON_TITLE = 'Available Buttons'HELP_BUTTONS = %w{SHIFT CTRL Z B}HELP_BUTTON_DATA = [    'Send items to your pocket',    'Open Pocket Menu',    'Open this help window',    'Cancel or Close any menu']SENT_ITEM_LABEL = "Sent %s %s to your pocket!"OPTIONS = ['Refill', 'To Bag', 'Cancel']OPEN_CLOSE_INFO = ['C: Show options', 'B: Close or Exit']@slot_limit = 10 # How many different items will be allowed?@item_limit = 10 # Maximum number of items of the same kindclass << self    attr_accessor :slot_limit, :item_limit, :open_item_menu, :show_pocket_msgendendunless $HIDDENCHESTmodule Graphicsdef self.width() 640 enddef self.height() 480 endendendclass RPG::Itemdef type() :item endendclass Game_Partyalias :kyon_pocket_gm_party_init :initializealias :kyon_pocket_gm_party_icu? :item_can_use?def initialize    kyon_pocket_gm_party_init    @pocket = {}    @pocket.default = 0enddef item_can_use?(item)    switch_on = $game_switches    return true if switch_on and item.type == :item and @pocket > 0    kyon_pocket_gm_party_icu?(item)enddef to_pocket(item, n)    item_id = item.id    @pocket += n    @pocket.delete(item_id) if @pocket == 0    gain_item(item, -n)enddef pocket_can_use?(item_id)    return if @pocket == 0    occasion = $data_items.occasion    ($game_temp.in_battle and occasion < 2)enddef pocket_number(item_id) @pocket endattr_reader :pocketendclass Window_Selectabledef no_item?() @data == nil endendclass Window_Itemalias :kyon_pocket_win_item_up_help :update_helpdef update_help    kyon_pocket_win_item_up_help unless KPocket.show_pocket_msgendendclass KItemPocketWindow < Window_Selectabledef initialize    wh = $game_temp.in_battle ? 232 : 304    super(0, 56, Graphics.width, wh)    @column_max = 2    self.index = 0    refresh    self.back_opacity = 160 if $game_temp.in_battleenddef refresh    create_contents    @data = []    $game_party.pocket.keys.sort.each{|n| @data << $data_items }    @item_max = @data.size    return if @item_max == 0    self.contents = Bitmap.new(width - 32, row_max * 32)    @item_max.times{|pos| draw_item(pos) }enddef draw_item(index)    rect = item_rect(index)    self.contents.clear_rect(rect)    item = @data    return unless item    number = $game_party.pocket_number(item.id)    enabled = $game_party.pocket_can_use?(item.id)    rect.width -= 4    draw_item_name(item, rect.x, rect.y, enabled)    self.contents.draw_text(rect, sprintf(":%2d", number), 2)enddef update_help    text = no_item? ? "" : @data[@index].description    @help_window.set_text(text)enddef item() @data[@index] || RPG::Item.new endendclass KButtonInfoWindow < Window_Basedef initialize(x, w)    super(x, 56, w, 320)    bit = Bitmap.new(width - 32, height - 32)    bw = bit.width    bit.font.size = 24    bit.draw_text(0, 0, bw, 26, KPocket::HELP_BUTTON_TITLE, 1)    bit.fill_rect(8, 27, bw - 14, 4, Color.new(0, 0, 0))    bit.fill_rect(8, 28, bw - 16, 2, normal_color)    bit.font.size = 22    data = KPocket::HELP_BUTTON_DATA    buttons = KPocket::HELP_BUTTONS    buttons.size.times do |n|      by = 34 + n * 24      bit.draw_text(0, by, bw, 24, buttons)      bit.draw_text(96, by, bw, 24, data)    end    self.contents = bitendendclass BasicButtonInfoWindow < Window_Basedef initialize    super(0, Graphics.height - 56, Graphics.width, 56)    self.contents = Bitmap.new(width - 32, height - 32)    half = width / 2    labels = KPocket::OPEN_CLOSE_INFO    contents.draw_text(0, 0, half, 24, labels)    contents.draw_text(half, 0, half, 24, labels)endendclass Scene_Itemalias :kyon_pocket_scn_item_start :startalias :kyon_pocket_scn_item_term :terminatealias :kyon_pocket_scn_item_up :updatealias :kyon_pocket_scn_item_up_item_sel :update_item_selectiondef start    @button_info = KButtonInfoWindow.new(130, 380)    @button_info.visible = false    kyon_pocket_scn_item_startenddef terminate    kyon_pocket_scn_item_term    @button_info.disposeenddef update    kyon_pocket_scn_item_up    update_help if @stage == :helpenddef update_item_selection    kyon_pocket_scn_item_up_item_sel    if Input.trigger?(KPocket::OPEN_BUTTON)      return Sound.play_buzzer if $game_party.pocket.empty?      Sound.play_decision      return $scene = KPocketItem.new    elsif Input.trigger?(KPocket::SEND_ITEM_BUTTON)      @item = @item_window.item      return Sound.play_buzzer unless @item      return send_item2pocket    elsif Input.trigger?(KPocket::HELP_BUTTON)      Sound.play_decision      @item_window.active = false      @button_info.z = 200      @button_info.visible = true      return @stage = :help    elsif Input.trigger?(Input::C) or Input.dir4 > 0      KPocket.show_pocket_msg = false    endenddef send_item2pocket    item_id = @item.id    packed = KPocket.item_limit - $game_party.pocket_number(item_id)    return Sound.play_buzzer if packed == 0    Sound.play_decision    number = $game_party.item_number(@item)    number = packed if number > packed    $game_party.to_pocket(@item, number)    KPocket.show_pocket_msg = true    @item_window.refresh    text = sprintf(KPocket::SENT_ITEM_LABEL, number, @item.name)    @help_window.set_text(text, 1)enddef update_help    if Input.trigger?(Input::B) or Input.trigger?(Input::C)      Sound.play_cancel      @stage = nil      @button_info.z = 0      @button_info.visible = false      @item_window.active = true    endendendclass KPocketItemdef main    @stage = :main    @help_window = Window_Help.new    @item_window = KItemPocketWindow.new    @item_window.help_window = @help_window    @button_window = BasicButtonInfoWindow.new    @options = Window_Command.new(192, KPocket::OPTIONS)    @options.visible = false    @options.active = false    @options.x = (Graphics.width - 192) / 2    @options.y = (Graphics.height - 128) / 2    Graphics.transition    main_loop while @stage    Graphics.freeze    @options.dispose    @button_window.dispose    @help_window.dispose    @item_window.disposeenddef main_loop    Graphics.update    Input.update    updateenddef update    @item_window.update    if @stage == :main      update_item    elsif @stage == :choose      update_select    endenddef update_item    if Input.trigger?(Input::B)      Sound.play_cancel      $scene = KPocket.open_item_menu ? Scene_Item.new : Scene_Map.new      KPocket.open_item_menu = nil      return @stage = nil    elsif Input.trigger?(Input::C)      return Sound.play_buzzer if @item_window.no_item?      @item = @item_window.item      @current = $game_party.pocket_number(@item.id)      full = $game_party.pocket.size == KPocket.slot_limit      return Sound.play_buzzer if full or KPocket.item_limit == @current      Sound.play_decision      @item_window.active = false      @options.active = true      @options.visible = true      @stage = :choose    endenddef update_select    @options.update    if Input.trigger?(Input::B)      return to_main    elsif Input.trigger?(Input::C)      pos = @options.index      return to_main if pos == 2      Sound.play_decision      if pos == 0      packed = KPocket.item_limit - @current      number = [$game_party.item_number(@item), packed].min      $game_party.to_pocket(@item, number)      else      $game_party.to_pocket(@item, -@current)      end      @item_window.refresh      @item_window.active = true      @options.visible = false      @options.active = false      @stage = :main    endenddef to_main    Sound.play_cancel    @options.visible = false    @options.active = false    @item_window.active = true    @stage = :mainendendclass Scene_Battledef start_item_selection    @help_window = Window_Help.new    if $game_switches      @item_window = KItemPocketWindow.new    else      Window_Item.new(0, 56, 544, 232)    end    @item_window.help_window = @help_window    @actor_command_window.active = falseendend


Terms & Conditions

You must include my nickname and the current website's URL in your game credits. Do not repost it anywhere else!
Free for non commercial games.


本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/kpocket-vx.115850/
页: [1]
查看完整版本: KPocket VX