kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
289
Reaction score
73
First Language
English
Primarily Uses
RMXP
KPocket VX
version 1.0.6

by Kyonides Arkanthes


Introduction

Force the player to keep a reduced inventory while in battle! :eek:
Of course, the player may choose which items he or she will pack in his or her pocket. :wink:
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 KPocket
  SWITCH_ID = 1 # Switch that activates Pocket instead of Bag
  OPEN_BUTTON = Input::CTRL # Open KPocket Menu!
  SEND_ITEM_BUTTON = Input::SHIFT
  HELP_BUTTON = Input::Z
  HELP_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 kind
  class << self
    attr_accessor :slot_limit, :item_limit, :open_item_menu, :show_pocket_msg
  end
end

unless $HIDDENCHEST

module Graphics
  def self.width() 640 end
  def self.height() 480 end
end

end

class RPG::Item
  def type() :item end
end

class Game_Party
  alias :kyon_pocket_gm_party_init :initialize
  alias :kyon_pocket_gm_party_icu? :item_can_use?
  def initialize
    kyon_pocket_gm_party_init
    @pocket = {}
    @pocket.default = 0
  end

  def item_can_use?(item)
    switch_on = $game_switches[KPocket::SWITCH_ID]
    return true if switch_on and item.type == :item and @pocket[item.id] > 0
    kyon_pocket_gm_party_icu?(item)
  end

  def to_pocket(item, n)
    item_id = item.id
    @pocket[item_id] += n
    @pocket.delete(item_id) if @pocket[item_id] == 0
    gain_item(item, -n)
  end

  def pocket_can_use?(item_id)
    return if @pocket[item_id] == 0
    occasion = $data_items[item_id].occasion
    ($game_temp.in_battle and occasion < 2)
  end
  def pocket_number(item_id) @pocket[item_id] end
  attr_reader :pocket
end

class Window_Selectable
  def no_item?() @data[index] == nil end
end

class Window_Item
  alias :kyon_pocket_win_item_up_help :update_help
  def update_help
    kyon_pocket_win_item_up_help unless KPocket.show_pocket_msg
  end
end

class KItemPocketWindow < Window_Selectable
  def 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_battle
  end

  def refresh
    create_contents
    @data = []
    $game_party.pocket.keys.sort.each{|n| @data << $data_items[n] }
    @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) }
  end

  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    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)
  end

  def update_help
    text = no_item? ? "" : @data[@index].description
    @help_window.set_text(text)
  end
  def item() @data[@index] || RPG::Item.new end
end

class KButtonInfoWindow < Window_Base
  def 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[n])
      bit.draw_text(96, by, bw, 24, data[n])
    end
    self.contents = bit
  end
end

class BasicButtonInfoWindow < Window_Base
  def 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[0])
    contents.draw_text(half, 0, half, 24, labels[1])
  end
end

class Scene_Item
  alias :kyon_pocket_scn_item_start :start
  alias :kyon_pocket_scn_item_term :terminate
  alias :kyon_pocket_scn_item_up :update
  alias :kyon_pocket_scn_item_up_item_sel :update_item_selection
  def start
    @button_info = KButtonInfoWindow.new(130, 380)
    @button_info.visible = false
    kyon_pocket_scn_item_start
  end

  def terminate
    kyon_pocket_scn_item_term
    @button_info.dispose
  end

  def update
    kyon_pocket_scn_item_up
    update_help if @stage == :help
  end

  def 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
    end
  end

  def 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)
  end

  def 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
    end
  end
end

class KPocketItem
  def 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.dispose
  end

  def main_loop
    Graphics.update
    Input.update
    update
  end

  def update
    @item_window.update
    if @stage == :main
      update_item
    elsif @stage == :choose
      update_select
    end
  end

  def 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
    end
  end

  def 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
    end
  end

  def to_main
    Sound.play_cancel
    @options.visible = false
    @options.active = false
    @item_window.active = true
    @stage = :main
  end
end

class Scene_Battle
  def start_item_selection
    @help_window = Window_Help.new
    if $game_switches[KPocket::SWITCH_ID]
      @item_window = KItemPocketWindow.new
    else
      Window_Item.new(0, 56, 544, 232)
    end
    @item_window.help_window = @help_window
    @actor_command_window.active = false
  end
end

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.
 
Last edited:

TengHu

Abscond Games
Veteran
Joined
Mar 16, 2012
Messages
469
Reaction score
120
First Language
English
Primarily Uses
RMVX
Can you post some screenshots of this? Sounds like a nifty idea I can use in my project.

Decided to try it out but I got this error when I open the Item menu after gaining an item.
upload_2019-12-17_0-15-45.png
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
289
Reaction score
73
First Language
English
Primarily Uses
RMXP
At the end of the line add (item) yes, parentheses should be included, and that's it! It should be working fine.
 

TengHu

Abscond Games
Veteran
Joined
Mar 16, 2012
Messages
469
Reaction score
120
First Language
English
Primarily Uses
RMVX
Fixed! Thank you!
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm moving on from RMXP finally. I've been stuck in a difficult decision between XP and MZ, and I've given up and moved on to MZ. Overall I'm really liking it, I wish tilesets were easier to setup like XP, but it's actually not that bad!
Have you ever gone full 'Ship of Theseus' while frankenspriting? Because I just did.
I saw my new eye doctor today, he reminds me of Satoru Iwata for some reason
I've been using a modified version of a script called Multiple Messages. It makes my text boxes look like a Mario & Luigi game! There is something about it that bothers me a little bit, but I shouldn't worry about that now.

Side note, Mist's walking animation is almost perfectly in sync with Loose Yourself by Eminem.
Starting work on some stuff for the community. Hopefully it will be fun, and useful to somebody.

Forum statistics

Threads
107,773
Messages
1,032,038
Members
139,915
Latest member
nick7626
Top