Galv’s Item/Bank Storage V.1.9

Demo – Version 1.9 >

#------------------------------------------------------------------------------#
#  Galv's Item/Bank Storage
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.9
#------------------------------------------------------------------------------#
#  2016-06-09 - Version 1.9 - Bug with removing an entire stack fixed
#  2015-11-12 - Version 1.8 - Bug with stored item stacks and counting.
#  2012-10-24 - Version 1.7 - Added multiple storages controlled with variable.
#                           - Changed name to Item/Bank Storage
#                           - changed alias naming for compatibility
#  2012-10-19 - Version 1.6 - Bug fixes
#  2012-10-19 - Version 1.5 - Fixed a max gold and withdrawing issue.
#                           - Added deposit all and withdraw all gold buttons.
#                           - party gold and item limits can now be set or use
#                           - the limit from a limit breaking script. (in theory)
#  2012-10-18 - Version 1.4 - Other small fixes
#  2012-10-18 - Version 1.3 - Added banking SE
#  2012-10-18 - Version 1.2 - Added gold storage and more script calls
#  2012-10-17 - Version 1.1 - Added script calls to control stored items.
#  2012-10-16 - Version 1.0 - Released
#------------------------------------------------------------------------------#
#  An item storage script. Allows the player to store as many items as he/she
#  requires in bank-like storage that can be accessed from anywhere.
#
#  This script differs to my "Multiple Storage containers" script in that you
#  can have "banks" that store items and gold and can be accessed from anywhere.
#  It was designed to be used for one bank, but now has option to have more if
#  required.
#
#  My "Multiple Storage Containers" script stores only items within certain
#  events that can only be accessed by activating the particular event. This was
#  designed for location specific containers like chests, barrels, etc.
#
#  Here are some script calls that might be useful:
#------------------------------------------------------------------------------#
#
#  open_storage                         # Opens the item storage scene
#
#  store_add(type, id, amount)          # creates an item in storage
#  store_rem(type, id, amount)          # destroys an item in storage
#  store_count(type, id)                # returns amount of an item in storage
#
#  bank_add(amount)                     # adds amount of gold to bank
#  bank_rem(amount)                     # removes amount of gold from bank
#  bank_count                           # returns amount of gold in bank
#
#------------------------------------------------------------------------------#
#  EXPLAINATION:
#  type      this can be "weapon", "armor" or "item"
#  id        the ID of the item/armor/weapon
#  amount    the number of the item/armor/weapon/gold you want to remove
#
#  EXAMPLE OF USE:
#  store_add("weapon", 5, 20)
#  store_rem("item", 18, 99)
#  store_count("armor", 1)
#  bank_add(100)
#------------------------------------------------------------------------------#
#  More setup options further down.
#------------------------------------------------------------------------------#
 
$imported = {} if $imported.nil?
$imported["Item_Storage"] = true
 
module Storage
 
#------------------------------------------------------------------------------#
#  SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
 
  # BOX VARIABLE
  BOX_VAR = 3    # This is the variable ID to use to determine which box you are
                 # adding/removing items from. Set the variable to a box number
                 # right before any add/remove or opening storage script calls
                 # to tell them which box they will affect.
                 # Set to 0 if you only want 1 box storage in your game. You
                 # then don't have to change a variable before each script call.
 
  # COMMAND LIST VOCAB
  BANK = "Bank"
  STORE = "Store Item"
  REMOVE = "Remove Item"
  CANCEL = "Cancel"
 
  # OTHER VOCAB
  IN_STORAGE = "In Storage"
  IN_INVENTORY = "In Inventory"
 
  GOLD_INVENTORY = "Party:"
  GOLD_BANKED = "Banked:"
  BANK_HELP = "Hold DOWN to deposit. Hold UP to withdraw." + "\n" +
              "Press R to deposit all. Press L to withdraw all."
 
  # OTHER OPTIONS
  SE = ["Equip2", 90, 100]        # Sound effect when storing/removing an item
  SE_BANK = ["Shop", 50, 150]     # Repeating sound effect when banking gold
                                  # ["SE Name", volume, pitch]
 
  STORE_PRICELESS = true          # Items worth 0 can be stored? true or false
  STORE_KEY = true                # Key items can be stored? true or false
 
  # PARTY LIMITS
  # NOTE: These limits set to 0 will use the default limits. In theory this will
  # be compatible with a limit breaker script by leaving them at 0. Or you can
  # set the party limits below to whatever you like.
 
  MAX_GOLD = 0                    # Max gold your PARTY can carry.
                                  # This will overwrite the default limit.
                                  # 0 means do not use this.
 
  MAX_ITEMS = 0                   # Max items your PARTY can carry.
                                  # This will overwrite the default limit.
                                  # 0 means do not use this.
 
#------------------------------------------------------------------------------#
#  SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
 
end
 
class Scene_ItemBank < Scene_MenuBase
  def start
    super
    check_storage_exists
    create_help_window
    create_command_window
    create_dummy_window
    create_bank_window
    create_number_window
    create_status_window
    create_category_window
    create_take_window
    create_give_window
 
  end
 
  def check_storage_exists
    if $game_party.multi_storage.nil?
      $game_party.create_storage_contents
    end
  end
 
  #--------------------------------------------------------------------------
  # Create Windows
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_BankCommand.new(Graphics.width)
    @command_window.viewport = @viewport
    @command_window.y = @help_window.height
    @command_window.set_handler(:bank,   method(:command_bank))
    @command_window.set_handler(:give,   method(:command_give))
    @command_window.set_handler(:take,    method(:command_take))
    @command_window.set_handler(:cancel, method(:return_scene))
  end
  def create_dummy_window
    wy = @command_window.y + @command_window.height
    wh = Graphics.height - wy
    @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
    @dummy_window.viewport = @viewport
  end
  def create_bank_window
    @bank_window = Window_Bank.new
    @bank_window.viewport = @viewport
    @bank_window.x = 0
    @bank_window.y = @help_window.height + @command_window.height
    @bank_window.hide
    @bank_window.set_handler(:ok,     method(:on_bank_cancel))
    @bank_window.set_handler(:cancel, method(:on_bank_cancel))
 
  end
 
  def create_number_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @number_window = Window_BankNumber.new(0, wy, wh)
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  def create_status_window
    wx = @number_window.width
    wy = @dummy_window.y
    ww = Graphics.width - wx
    wh = @dummy_window.height
    @status_window = Window_BankItems.new(wx, wy, ww, wh)
    @status_window.viewport = @viewport
    @status_window.hide
  end
  def create_category_window
    @category_window = Window_ItemCategory.new
    @category_window.viewport = @viewport
    @category_window.help_window = @help_window
    @category_window.y = @dummy_window.y
    @category_window.hide.deactivate
    @category_window.set_handler(:ok,     method(:on_category_ok))
    @category_window.set_handler(:cancel, method(:on_category_cancel))
  end
  def create_give_window
    wy = @category_window.y + @category_window.height
    wh = Graphics.height - wy
    @give_window = Window_BankGive.new(0, wy, Graphics.width, wh)
    @give_window.viewport = @viewport
    @give_window.help_window = @help_window
    @give_window.hide
    @give_window.set_handler(:ok,     method(:on_give_ok))
    @give_window.set_handler(:cancel, method(:on_give_cancel))
    @category_window.item_window = @give_window
  end
  def create_take_window
    wy = @command_window.y + @command_window.height
    wh = Graphics.height - wy
    @take_window = Window_BankTake.new(0, wy, Graphics.width, wh)
    @take_window.viewport = @viewport
    @take_window.help_window = @help_window
    @take_window.hide
    @take_window.set_handler(:ok,     method(:on_take_ok))
    @take_window.set_handler(:cancel, method(:on_take_cancel))
    @category_window.item_window = @take_window
  end
 
  #--------------------------------------------------------------------------
  # * Activate Windows
  #--------------------------------------------------------------------------
  def activate_give_window
    @category_window.show
    @give_window.refresh
    @give_window.show.activate
    @status_window.hide
  end
  def activate_take_window
    @take_window.select(0)
    @take_window.refresh
    @take_window.show.activate
    @status_window.hide
  end
  def activate_bank_window
    @bank_window.refresh
    @bank_window.show.activate
    @help_window.set_text(Storage::BANK_HELP)
  end
 
  #--------------------------------------------------------------------------
  # HANDLER METHODS
  #--------------------------------------------------------------------------
  def on_category_ok
    activate_give_window
    @give_window.select(0)
  end
  def on_category_cancel
    @command_window.activate
    @dummy_window.show
    @category_window.hide
    @give_window.hide
  end
  def command_give
    @dummy_window.hide
    @category_window.show.activate
    @give_window.show
    @give_window.unselect
    @give_window.refresh
  end
  def on_give_ok
    @item = @give_window.item
    if @item.nil?
      RPG::SE.stop
      Sound.play_buzzer
      @give_window.activate
      @give_window.refresh
      return
    else
      @status_window.item = @item
      @category_window.hide
      @give_window.hide
      @number_window.set(@item, max_give)
      @number_window.show.activate
      @status_window.show
    end
  end
  def on_give_cancel
    @give_window.unselect
    @category_window.activate
    @status_window.item = nil
    @help_window.clear
  end
  def command_take
    @dummy_window.hide
    activate_take_window
    @take_window.show
    @take_window.refresh
  end
  def command_bank
    #@dummy_window.hide
    activate_bank_window
    @bank_window.show
    @bank_window.refresh
  end
  def on_bank_cancel
    @command_window.activate
    @dummy_window.show
    @category_window.hide
    @bank_window.hide
    @help_window.clear
  end
  def on_take_ok
    @item = @take_window.item
    if @item.nil? || $game_party.multi_storage.empty? || $game_party.item_number(@item) == $game_party.max_item_number(@item)
      RPG::SE.stop
      Sound.play_buzzer
      @take_window.activate
      @take_window.refresh
      return
    elsif
      @item = @take_window.item
      @status_window.item = @item
      @take_window.hide
      @number_window.set(@item, max_take)
      @number_window.show.activate
      @status_window.show
    end
  end
  def on_take_cancel
    @take_window.unselect
    @command_window.activate
    @dummy_window.show
    @take_window.hide
    @status_window.item = nil
    @help_window.clear
  end
  def on_number_ok
    RPG::SE.new(Storage::SE[0], Storage::SE[1], Storage::SE[2]).play
    case @command_window.current_symbol
    when :take
      do_take(@number_window.number)
    when :give
      do_give(@number_window.number)
    end
    end_number_input
    @status_window.refresh
  end
  def on_number_cancel
    Sound.play_cancel
    end_number_input
  end
  def end_number_input
    @number_window.hide
    case @command_window.current_symbol
    when :take
      activate_take_window
    when :give
      activate_give_window
    end
  end  
 
  #--------------------------------------------------------------------------
  # * Giving and taking methods
  #--------------------------------------------------------------------------
  def max_take
    if $game_party.multi_storage(@item) > $game_party.max_item_number(@item) - $game_party.item_number(@item)
      $game_party.max_item_number(@item) - $game_party.item_number(@item)
    else
      $game_party.multi_storage(@item)
    end
  end
  def max_give
    $game_party.item_number(@item)
  end
  def do_give(number)
    $game_party.lose_item(@item, number)
    if $game_party.multi_storage(@item).nil? || $game_party.multi_storage(@item) <= 0
      $game_party.multi_storage_set(@item,number)
    else
      $game_party.multi_storage_change(@item,number)
    end
  end
  def do_take(number)
    return if @item.nil?
    $game_party.gain_item(@item, number)
    $game_party.multi_storage_change(@item,-number)
    #$game_party.multi_storage.delete(@item) if $game_party.multi_storage(@item) <= 0
    if $game_party.multi_storage.empty?
      @take_window.activate
    end
  end
 
end # Scene_ItemBank < Scene_MenuBase
 
#------------------------------------------------------------------------------#
#  Window Stored Items
#------------------------------------------------------------------------------#
 
class Window_StoreList_Bank < Window_Selectable
  def initialize(x, y, width, height)
    super
    @category = :none
    @data = []
  end
  def category=(category)
    return if @category == category
    @category = category
    refresh
    self.oy = 0
  end
  def col_max
    return 2
  end
  def item_max
    @data ? @data.size : 1
  end
  def item
    @data && index >= 0 ? @data[index] : nil
  end
  def current_item_enabled?
    enable?(@data[index])
  end
  def include?(item)
    case @category
    when :item
      item.is_a?(RPG::Item) && !item.key_item?
    when :weapon
      item.is_a?(RPG::Weapon)
    when :armor
      item.is_a?(RPG::Armor)
    when :key_item
      item.is_a?(RPG::Item) && item.key_item?
    else
      false
    end
  end
  def enable?(item)
    $game_party.multi_storage.has_key?(item)
  end
  def make_item_list
    @data = $game_party.multi_storage_all.keys {|item| include?(item) }
    @data.push(nil) if include?(nil)
  end
  def select_last
    select(@data.index($game_party.last_item.object) || 0)
  end
  def draw_item(index)
    item = @data[index]
    if item
      rect = item_rect(index)
      rect.width -= 4
      draw_item_name(item, rect.x, rect.y, enable?(item))
      draw_item_number(rect, item)
    end
  end
  def draw_item_number(rect, item)
    draw_text(rect, sprintf(":%2d", $game_party.multi_storage(item)), 2)
  end
  def update_help
    @help_window.set_item(item)
  end
  def refresh
    make_item_list
    create_contents
    draw_all_items
  end
end # Window_StoreList_Bank < Window_Selectable
 
#------------------------------------------------------------------------------#
#  Window Stored Item amount
#------------------------------------------------------------------------------#
 
class Window_BankNumber < Window_Selectable
  attr_reader :number
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
    @max = 1
    @number = 1
  end
  def window_width
    return 304
  end
  def set(item, max)
    @item = item
    @max = max
    @number = 1
    refresh
  end
  def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
  end
  def draw_number
    change_color(normal_color)
    draw_text(cursor_x - 28, item_y, 22, line_height, "×")
    draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  end
  def item_y
    contents_height / 2 - line_height * 3 / 2
  end
  def cursor_width
    figures * 10 + 12
  end
  def cursor_x
    contents_width - cursor_width - 4
  end
  def figures
    return 2
  end
  def update
    super
    if active
      last_number = @number
      update_number
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
  def update_number
    change_number(1)   if Input.repeat?(:RIGHT)
    change_number(-1)  if Input.repeat?(:LEFT)
    change_number(10)  if Input.repeat?(:UP)
    change_number(-10) if Input.repeat?(:DOWN)
  end
  def change_number(amount)
    @number = [[@number + amount, @max].min, 1].max
  end
  def update_cursor
    cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  end
 
end # Window_BankNumber < Window_Selectable
 
#------------------------------------------------------------------------------#
#  Window Store Item Status
#------------------------------------------------------------------------------#
 
class Window_BankItems < Window_Base
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @item = nil
    @page_index = 0
    refresh
  end
  def refresh
    contents.clear
    draw_possession(4, 0)
    draw_stored(4, line_height)
    draw_equip_info(4, line_height * 2) if @item.is_a?(RPG::EquipItem)
  end
  def item=(item)
    @item = item
    refresh
  end
  def draw_possession(x, y)
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    change_color(system_color)
    draw_text(rect, Storage::IN_INVENTORY)
    change_color(normal_color)
    draw_text(rect, $game_party.item_number(@item), 2)
  end
  def draw_stored(x, y)
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    change_color(system_color)
    draw_text(rect, Storage::IN_STORAGE)
    change_color(normal_color)
    stored_amount = $game_party.multi_storage(@item)
    stored_amount = 0 if stored_amount.nil?
    draw_text(rect, stored_amount, 2)
  end
  def draw_equip_info(x, y)
    status_members.each_with_index do |actor, i|
      draw_actor_equip_info(x, y + line_height * (i * 2.4), actor)
    end
  end
  def status_members
    $game_party.members[@page_index * page_size, page_size]
  end
  def page_size
    return 4
  end
  def page_max
    ($game_party.members.size + page_size - 1) / page_size
  end
  def draw_actor_equip_info(x, y, actor)
    enabled = actor.equippable?(@item)
    change_color(normal_color, enabled)
    draw_text(x, y, 112, line_height, actor.name)
    item1 = current_equipped_item(actor, @item.etype_id)
    draw_actor_param_change(x, y, actor, item1) if enabled
    draw_item_name(item1, x, y + line_height, enabled)
  end
  def draw_actor_param_change(x, y, actor, item1)
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    change = @item.params[param_id] - (item1 ? item1.params[param_id] : 0)
    change_color(param_change_color(change))
    draw_text(rect, sprintf("%+d", change), 2)
  end
  def param_id
    @item.is_a?(RPG::Weapon) ? 2 : 3
  end
  def current_equipped_item(actor, etype_id)
    list = []
    actor.equip_slots.each_with_index do |slot_etype_id, i|
      list.push(actor.equips[i]) if slot_etype_id == etype_id
    end
    list.min_by {|item| item ? item.params[param_id] : 0 }
  end
  def update
    super
    update_page
  end
  def update_page
    if visible && Input.trigger?(:A) && page_max > 1
      @page_index = (@page_index + 1) % page_max
      refresh
    end
  end
 
end # Window_BankItems < Window_Base
 
#------------------------------------------------------------------------------#
#  Window Give Item
#------------------------------------------------------------------------------#
 
class Window_BankGive < Window_ItemList
  def initialize(x, y, width, height)
    super(x, y, width, height)
  end
  def current_item_enabled?
 
    enable?(@data[index])
  end
  def enable?(item)
    if item.is_a?(RPG::Item)
      return false if item.key_item? && !Storage::STORE_KEY
    end
    if Storage::STORE_PRICELESS
      true
    else
      item && item.price > 0
    end
  end
end
 
#------------------------------------------------------------------------------#
#  Window Take Item
#------------------------------------------------------------------------------#
 
class Window_BankTake < Window_StoreList_Bank
  def initialize(x, y, width, height)
    super(x, y, width, height)
  end
  def current_item_enabled?
    enable?(@data[index])
  end
  def enable?(item)
    $game_party.multi_storage[item] != 0 && $game_party.item_number(item) < $game_party.max_item_number(@item)
  end
end
 
#------------------------------------------------------------------------------#
#  Window Command
#------------------------------------------------------------------------------#
 
class Window_BankCommand < Window_HorzCommand
  def initialize(window_width)
    @window_width = window_width
    super(0, 0)
  end
  def window_width
    @window_width
  end
  def col_max
    return 4
  end
  def make_command_list
    add_command(Storage::BANK, :bank)
    add_command(Storage::STORE,    :give)
    add_command(Storage::REMOVE,   :take)
    add_command(Storage::CANCEL, :cancel)
  end
end
 
#------------------------------------------------------------------------------#
#  Window Bank
#------------------------------------------------------------------------------#
 
class Window_Bank < Window_Selectable
  def initialize
    super(0, 0, window_width, fitting_height(2))
    refresh
    @deposit_rate = 1
    @withdraw_rate = 1
  end
  def window_width
    return Graphics.width / 2
  end
  alias galv_bank_update update
  def update
    galv_bank_update
    gold_transfer if self.active
  end
  def gold_transfer
    if Input.repeat?(:DOWN) && $game_party.gold > 0 || Input.repeat?(:UP) && $game_party.gold_stored > 0 && $game_party.gold < $game_party.max_gold
        RPG::SE.new(Storage::SE_BANK[0], Storage::SE_BANK[1], Storage::SE_BANK[2]).play
    end
    if Input.press?(:DOWN)
      before = $game_party.gold
      $game_party.lose_gold(@deposit_rate)
      after = $game_party.gold
      $game_party.gold_stored += before - after
      @deposit_rate += 1
      refresh
    end
    if Input.trigger?(:R) && !Input.press?(:DOWN) && !Input.press?(:UP)
      return if $game_party.gold == 0
      before = $game_party.gold
      $game_party.lose_gold($game_party.gold)
      after = $game_party.gold
      $game_party.gold_stored += before - after
      refresh
      RPG::SE.new(Storage::SE_BANK[0], Storage::SE_BANK[1], Storage::SE_BANK[2]).play
    end
    if !Input.press?(:DOWN)
      @deposit_rate = 1
    end
    if Input.press?(:UP)
      return if $game_party.gold == $game_party.max_gold
      @withdraw_rate = $game_party.gold_stored if @withdraw_rate >= $game_party.gold_stored
      if @withdraw_rate + $game_party.gold > $game_party.max_gold
        @withdraw_rate = $game_party.max_gold - $game_party.gold
      end
      before = $game_party.gold_stored
      $game_party.gold_stored -= @withdraw_rate
      after = $game_party.gold_stored
      $game_party.gain_gold(before - after)
      if $game_party.gold_stored == 0
        return refresh
      end
      @withdraw_rate += 1
      refresh
    end
 
    if Input.trigger?(:L) && !Input.press?(:DOWN) && !Input.press?(:UP)
      take_all_gold = $game_party.gold_stored
      return if $game_party.gold == $game_party.max_gold || $game_party.gold_stored == 0
      if take_all_gold + $game_party.gold > $game_party.max_gold
        take_all_gold = $game_party.max_gold - $game_party.gold
      end
      before = $game_party.gold_stored
      $game_party.gold_stored -= take_all_gold
      after = $game_party.gold_stored
      $game_party.gain_gold(before - after)
      refresh
      RPG::SE.new(Storage::SE_BANK[0], Storage::SE_BANK[1], Storage::SE_BANK[2]).play
    end
    if !Input.press?(:UP)
      @withdraw_rate = 1
    end
  end
  def refresh
    contents.clear
    draw_gold_location(Storage::GOLD_INVENTORY, 0, 0, 250)
    draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
    draw_gold_location(Storage::GOLD_BANKED, 0, line_height * 1, 250)
    draw_currency_value(value_stored, currency_unit, 4, line_height * 1, contents.width - 8)
  end
  def draw_gold_location(vocab, x, y, width)
    change_color(system_color)
    draw_text(x, y, width, line_height, vocab)
  end
  def value
    $game_party.gold
  end
  def value_stored
    $game_party.gold_stored
  end
  def currency_unit
    Vocab::currency_unit
  end
  def open
    refresh
    super
  end
end
 
#------------------------------------------------------------------------------#
#  Game Party Additions
#------------------------------------------------------------------------------#
 
class Game_Party < Game_Unit
  attr_accessor :multi_storage
  attr_accessor :gold_stored
 
  alias galv_bank_init_all_items init_all_items
  def init_all_items
    galv_bank_init_all_items
    @storage = {}
    @gold_stored = 0
  end
 
  def multi_storage(item = nil)
    # Test for storage, create if not there.
    @storage[$game_variables[Storage::BOX_VAR]] ||= {:w => {},:a => {}, :i => {}}
 
    if !item
      return @storage[$game_variables[Storage::BOX_VAR]]
    else
      type = mstore_type(item)
      @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
      return @storage[$game_variables[Storage::BOX_VAR]][type][item.id]
    end
  end
 
  def multi_storage_all
    all = {}
 
    @storage[$game_variables[Storage::BOX_VAR]][:i].each { |id|
      all[$data_items[id[0]]] = id[1] if id[1] > 0
    }
    @storage[$game_variables[Storage::BOX_VAR]][:w].each { |id|
      all[$data_weapons[id[0]]] = id[1] if id[1] > 0
    }
    @storage[$game_variables[Storage::BOX_VAR]][:a].each { |id|
      all[$data_armors[id[0]]] = id[1] if id[1] > 0
    }
    return all
  end
 
  def mstore_type(item)
    if item.is_a?(RPG::Weapon)
      return :w
    elsif item.is_a?(RPG::Armor)
      return :a
    else
      return :i
    end
  end
 
  def multi_storage_change(item,amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] += amount
 
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        value <= 0
      }
    end
 
  end
 
  def multi_storage_set(item, amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] = amount
 
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        key >= 0
      }
    end
  end
 
  def gold_stored
    @gold_stored
  end
 
  alias galv_bank_max_gold max_gold
  def max_gold
    return Storage::MAX_GOLD if Storage::MAX_GOLD > 0
    galv_bank_max_gold
  end
 
  alias galv_bank_max_item_number max_item_number
  def max_item_number(item)
    return Storage::MAX_ITEMS if Storage::MAX_ITEMS > 0
    return 99 if item.nil?
    galv_bank_max_item_number(item)
  end
 
end # Game_Party < Game_Unit
 
class Game_Interpreter
  def store_add(type, id, amount)
    if $game_party.multi_storage.nil?
      $game_party.create_storage_contents
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    if $game_party.multi_storage(@item).nil?
      $game_party.multi_storage_set(@item,amount)
    else
      $game_party.multi_storage_change(@item,amount)
    end
  end
  def store_rem(type, id, amount)
    if $game_party.multi_storage.nil?
      $game_party.create_storage_contents
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    return if $game_party.multi_storage(@item).nil?
    if $game_party.multi_storage(@item) <= amount
      #$game_party.multi_storage.delete(@item)
      $game_party.multi_storage_set(@item,-amount)
    else
      $game_party.multi_storage_change(@item,-amount)
    end
  end
 
  def store_count(type, id)
    if $game_party.multi_storage.nil?
      $game_party.create_storage_contents
    end
    case type
    when "weapon"
      @item = $data_weapons[id]
    when "item"
      @item = $data_items[id]
    when "armor"
      @item = $data_armors[id]
    end
    # Issue here with item instance being different when game saves - therefore
    # the count is incorrect.
    # This issue is also persistant when adding things to storage
    # needs fixing
    p "Store item referring issue"
    return 0 if $game_party.multi_storage(@item).nil?
    $game_party.multi_storage(@item)
  end
 
  def bank_add(amount)
    $game_party.gold_stored += amount
  end
  def bank_rem(amount)
    $game_party.gold_stored -= amount
    $game_party.gold_stored = 0 if $game_party.gold_stored < 0
  end
  def bank_count
    $game_party.gold_stored
  end
  def open_storage
    SceneManager.call(Scene_ItemBank)
  end
end

34 thoughts on “Galv’s Item/Bank Storage V.1.9

  1. StavRock says:

    it’s perfect :D , can i ask you something ??? what extract program are u using ???

    • Galv says:

      Not sure what you are asking – rpgmaker vx ace

      • hey does this work for nil characters I have been trying to get it to work but it wont like my game is a real rpg pick a race and a class and all that it works if I am playing on a norm but not a nil what can I do to fix that (I should post a vid if you dont understand)

      • Galv says:

        I don’t know what you mean exactly but assuming you start with no characters.
        An easy solution would be to start with a character, make them transparent so player cannot see it.

  2. Suroh says:

    You’ve got some truly amazing scripts, thanks for all the hard work mate :) I hate to say this ( I’m c++/perl guy myself ) I’m having a horrific brain fart and can not for the life of me figure out how to set this up it’s actually really sad on my part and I feel really bad even asking it : (

    • Suroh says:

      Hey sorry I know the comments are awaiting approval, Hopefully I catch ya in time The issue I was having turned out to be a problem with one of my own common events ( I looked for days and missed the error ) sorry mate, and ty again for creating some wonderful scripts :)

  3. Can you please post a video showing how its done I am being a retard about this everything I do it wont work I think I’m setting something up wrong.

    • Galv says:

      Download the demo (like is at the top of this page. Click on where it says “Demo – Version 1.7 >”)

      You can see how it’s done there.

  4. izycoder says:

    Can you make only Bank system ? only money without item ?

  5. Dimz says:

    how to use this script? i mean what Event used for this Script?

  6. Jourdan says:

    This script is awesome, and does everything I need it to! One quick question, is there a way to get rid of the categories when giving items to the storage? So, when I click on “Store Item”, it just jumps strait to the inventory instead of the Items\Weapons\Armor\Key Items menu?

    Thanks so much!

    • Galv says:

      Would need a change in the script. Unfortunately I dont have time to do requests, but I recommend asking in an rpgmaker maker forum for someone to help :)

  7. Jeremy says:

    Is there an option in this script to add multiple banks, if so, how would I achieve that? I’m defining the variable for each container and the items are working however the bank stays the same for all containers.

  8. Wendell says:

    Hello, is there a way to use only the item storage, without the bank options?

  9. roderick brown says:

    how do u use install the plugin for mv???

  10. Raxmo says:

    Hey glav, I’m making a game and I’m doing a room for the credits where the player can talk to the creators of the verious scripts I’m using, think you could help me out and give me something you’d say? I’m looking for a quick introduction and maybe a blurb about the script, I’ll handle everything else. If not, I’ll figure something out, but would be much appreciated!

  11. SnapGuy1337 says:

    Hey um… Is there a fatal bug in the script? When I put a bunch of items into the chest, say Potion x88, Holy Water x17, Luck Up x10 and Full Potion x3. When I take any one of the item (doesn’t matter which one) in it’s full stack, all the other items disappear and cannot be retrieved! Is that a bug or is one of my scripts interfering with it?

    • Galv says:

      There is unfortunately a bug in the script that was found recently (after years of having written this haha). I can’t say for sure if it’s the cause of your issue. I am very busy and have not yet found time to look into it, but I will soon.

    • Galv says:

      Hmm okay, it seems I had already fixed the bug I was talking about. I cannot reproduce your issue – can you reproduce this issue in a new project? It could still be a bug I don’t know about or It could be another script interfering with it. You’ll have to do some tests.

      • Prech says:

        I am having the same issue. Whenever a stack is depleted, the entire storage is wiped. The problem occurs in the demo too so you should be able to recreate it. Please please fix this, I love the script but it’s broken as of now, haha.

  12. Galv says:

    Ahhh I see – yes I can replicate this now – a full stack being removed. I will fix this up when I get the chance.

    Okay, had a quick look and it was a tiny error – this is fixed now.

  13. Nate says:

    What line would you eliminate to get rid of the gold banking? I only want the items, armour, etc., not the gold.

    • Galv says:

      Unfortunately I don’t have time for personal edits (it would be more than one line edit). I recommend asking in a forum to see if someone can help out

  14. Dark says:

    Hi, I tried to implement the script but something is wrong… I mean BOX_VAR has syntax error but there is none. I checked the demo version and it works there… on my project it doesn’t. Now I have no clue why. I mean I’ve changed nothing and it works on demo project. Could other scripts make it not work? as I have couple such as Yanfly message system or journal etc. I can’t start a new project which is already 2 years in making. (I could start new project and copy everything there… but I don’t have time for that stuff so I’m posting here on occasion to check if someone knows something. if I can’t fix it then no storage, or I could try someone else’s) Anyway thanks, and hope to hear from you guys soon.

    • Galv says:

      It may not be compatible with other scripts. Here’s a checklist you could use to try to error trap the issue:

      Errors Using VX/VX Ace Scripts

      • Dark says:

        FUUUUUUUUUUUUUUU** it works sorry. I copied it from the note above and it did some stupid spaces in the script so it didn’t want to work. I corrected all the spaces and works perfectly fine. I suggest downloading implemented script already (i.e. via the demo version, this way when you copy from there you have 100% chance it works). Sorry for the trouble and thanks for the script. This will add some more features to my game :D

  15. lucabicono says:

    Hello! I recently ran into a bug with the script — removing an item using the store_rem script call deletes the entire storage. Not sure if it’s a problem with the script call itself, or if it’s because I’m using a variable to store the ID of the item I want to remove.

  16. Shaz says:

    Heya Galv, I believe line 859 should say
    value <= 0

    If you use store_rem to remove all of an item, it wipes out the entire storage contents instead of just deleting that one item.

Leave a comment