The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: pacdiggity on August 15, 2011, 11:20:37 AM

Title: Item Cap
Post by: pacdiggity on August 15, 2011, 11:20:37 AM
Item Cap
Version: 2.3
Author: Pacman
Date: December 29th, 2011

Version History



Planned Future Versions


Description


There are quite a few scripts that serve a similar purpose to this one, but to my knowledge this is the only one that does this specifically: gives each item, weapon or armor it's own possession cap, that is displayed in shop, equip and item screens. You can also set (and change in-game) the maximum amount of gold attainable. You can also now set certain items to not have their cap drawn in the windows.

Features


Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi55.tinypic.com%2Frkv4op.jpg&hash=487af6c1de37026a25578fbda2db1d371270aa6d)
Screenshot of rgangsta's CyberDrive. (http://rmrk.net/index.php/topic,43825.msg497992.html#msg497992)

Instructions

See script header.

Script


Code: [Select]
#===============================================================================
#
# Item Cap - Pacman (29/12/2011)
# Version 2.3
# Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
# Suggestion by Scalinger2
# Use the tag <item cap: x> to set the cap of an item to number x.
# Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
# item and shop scenes.
# Set the default maximum gold in the module below.
# Set the default caps of items (when not set through notebox) in the module.
# Change the TEXT if you want for some reason.
# You can change the maximum amount of gold with the script call:
# $game_system.gold_max = x
# Where x is the maximum amount of gold.
# Set which items can have their item cap drawn in the below module. The
# available options are:
#   :items
#   :weapons
#   :armors
# New in 2.1: no longer crashes upon entering equip scene.
# New in 2.2: no longer crashes upon entering shop scene.
# New in 2.3: draws item name more efficiently.
#
#===============================================================================
#
# CONFIGURATION
#
#===============================================================================

module ITEM_CAP
  GOLD_MAX = 40000    # Maximum amount of gold
  DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  TEXT = ": %s / %s"    # Text to display the cap
  SHOW_CAP = [        # Show cap of which items?
    :items,           # Items
    :weapons,         # Weapons
    :armors,          # Armors
  ]
end

#===============================================================================
#
# NO EDITING >:D
#
#===============================================================================

#==============================================================================
# ** RPG::BaseItem
#------------------------------------------------------------------------------
# Superclass of Skill, Item, Weapon, and Armor.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Maximum possession of item
  #--------------------------------------------------------------------------
  def item_cap
    return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
    return @item_cap if @item_cap != nil  # Don't perform if already set
    @item_cap = ITEM_CAP::DEFAULT_LIMIT
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
        @item_cap = $1.to_i
      end
    }
    return @item_cap
  end
  #--------------------------------------------------------------------------
  # * Don't draw the item's cap
  #--------------------------------------------------------------------------
  def exempt_cap?
    return if self.is_a?(RPG::Skill)
    return @exempt if @exempt != nil
    @exempt = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /\\EXEMPT_CAP/i
        @exempt = true
      end
    }
    return @exempt
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :gold_cap
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    item_max_initialize
    @gold_cap = ITEM_CAP::GOLD_MAX
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_gain_gold gain_gold
  alias item_max_gain_item gain_item
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    new_gold = item_max_gain_gold(n)
    @gold = [new_gold, $game_system.gold_cap].min
  end
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item          : Item
  #     n             : Number
  #     include_equip : Include equipped items
  #--------------------------------------------------------------------------
  def gain_item(item, n, include_equip = false)
    unless $scene.is_a?(Scene_Equip)
      number = item_number(item)
      cap = item.item_cap
      case item
      when RPG::Item
        @items[item.id] = [[number + n, 0].max, cap].min
      when RPG::Weapon
        @weapons[item.id] = [[number + n, 0].max, cap].min
      when RPG::Armor
        @armors[item.id] = [[number + n, 0].max, cap].min
      end
      n += number
      if include_equip and n < 0
        for actor in members
          while n < 0 and actor.equips.include?(item)
            actor.discard_equip(item)
            n += 1
          end
        end
      end
    else
      item_max_gain_item(item, n, include_equip)
    end
  end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This is a superclass of all windows in the game.
#==============================================================================

class Window_Base
  #--------------------------------------------------------------------------
  # * Draw Item Name
  #     item    : Item (skill, weapon, armor are also possible)
  #     x       : draw spot x-coordinate
  #     y       : draw spot y-coordinate
  #     enabled : Enabled flag. When false, draw semi-transparently.
  #     ctext   : Text to display the cap.
  #--------------------------------------------------------------------------
  def draw_item_name(item, x, y, enabled = true, ctext = "")
    if item != nil
      w = self.contents.text_size(ctext).width - 48
      draw_icon(item.icon_index, x, y, enabled)
      self.contents.font.color = normal_color
      self.contents.font.color.alpha = enabled ? 255 : 128
      self.contents.draw_text(x + 24, y, 172 - w, WLH, item.name)
    end
  end
end

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays a list of inventory items for the item screen, etc.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_cap_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    if draw_cap?(index)
      rect = item_rect(index)
      self.contents.clear_rect(rect)
      item = @data[index]
      if item != nil
        number1 = $game_party.item_number(item); number2 = item.item_cap
        enabled = enable?(item)
        rect.width -= 4
        ctext = sprintf(ITEM_CAP::TEXT, number1, number2)
        draw_item_name(item, rect.x, rect.y, enabled, ctext)
        self.contents.draw_text(rect, ctext, 2)
      end
    else
      item_cap_draw_item(index)
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return true if item == nil and $scene.is_a?(Scene_Equip)
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < item.item_cap)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
end

#==============================================================================
# ** Window_ShopStatus
#------------------------------------------------------------------------------
#  This window displays number of items in possession and the actor's equipment
# on the shop screen.
#==============================================================================

class Window_ShopStatus < Window_Base
  #--------------------------------------------------------------------------
  # Alias listing
  #--------------------------------------------------------------------------
  alias item_cap_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if draw_cap?(@item)
      self.contents.clear
      if @item != nil
        number = $game_party.item_number(@item); cap = @item.item_cap
        text = sprintf(ITEM_CAP::TEXT, number, cap)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 200, WLH, text, 2)
        for actor in $game_party.members
          x = 4
          y = WLH * (2 + actor.index * 2)
          draw_actor_parameter_change(actor, x, y)
        end
      end
    else
      item_cap_refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @item
    return true unless item
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or
       number == @item.item_cap
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
        max = [max, @item.item_cap - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
end

#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================

Credit



Thanks


Support


Post here. No matter how old the topic is.

Known Compatibility Issues

I overwrote some methods, but I don't know if that was avoidable. Paste at the top of your script list for improved compatibility. If you discover an issue, post it here.

Author's Notes


This script took me little more than half an hour and a bowl of ice cream to write.

Restrictions

Free for use (with credit) in non-commercial games. If you want to use it in a commercial game, contact me via PM or here.
Title: Re: Item Cap
Post by: Mushu on August 20, 2011, 04:28:22 AM
How do you modify this to where it only shows  amount/max # only beside items?
cuz the weapons and armor look wierd with that next to it xD
Title: Re: Item Cap
Post by: pacdiggity on August 20, 2011, 05:00:34 AM
Updated to cater for that idea.
Title: Re: Item Cap
Post by: Mushu on August 20, 2011, 05:19:54 AM
nifty
Title: Re: Item Cap
Post by: pacdiggity on September 19, 2011, 05:43:07 AM
Updated to 2.0.
Title: Re: Item Cap
Post by: Mushu on September 19, 2011, 02:57:13 PM
I got this
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi1188.photobucket.com%2Falbums%2Fz415%2FScalinger2%2FA9.png&hash=bc7ad5e3ab26b13659d721d3b7ab543d12392848)
Title: Re: Item Cap
Post by: pacdiggity on September 20, 2011, 09:04:37 AM
I can't seem to recreate the error, but try this:
Code: [Select]
#===============================================================================
#
# Item Cap - Pacman (19/9/2011)
# Version 2.0
# Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
# Suggestion by Scalinger2
# Use the tag <item cap: x> to set the cap of an item to number x.
# Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
# item and shop scenes.
# Set the default maximum gold in the module below.
# Set the default caps of items (when not set through notebox) in the module.
# Change the TEXT if you want for some reason.
# You can change the maximum amount of gold with the script call:
# $game_system.gold_max = x
# Where x is the maximum amount of gold.
# Set which items can have their item cap drawn in the below module. The
# available options are:
#   :items
#   :weapons
#   :armors
#
#===============================================================================
#
# CONFIGURATION
#
#===============================================================================

module ITEM_CAP
  GOLD_MAX = 40000    # Maximum amount of gold
  DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  TEXT = "%s / %s"    # Text to display the cap
  SHOW_CAP = [        # Show cap of which items?
    :items,           # Items
    :weapons,         # Weapons
    :armors,          # Armors
  ]
end

#===============================================================================
#
# NO EDITING >:D
#
#===============================================================================

#==============================================================================
# ** RPG::BaseItem
#------------------------------------------------------------------------------
# Superclass of Skill, Item, Weapon, and Armor.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Maximum possession of item
  #--------------------------------------------------------------------------
  def item_cap
    return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
    return @item_cap if @item_cap != nil  # Don't perform if already set
    @item_cap = ITEM_CAP::DEFAULT_LIMIT
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
        @item_cap = $1.to_i
      end
    }
    return @item_cap
  end
  #--------------------------------------------------------------------------
  # * Don't draw the item's cap
  #--------------------------------------------------------------------------
  def exempt_cap?
    return if self.is_a?(RPG::Skill)
    return @exempt if @exempt != nil
    @exempt = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /\\EXEMPT_CAP/i
        @exempt = true
      end
    }
    return @exempt
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :gold_cap
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    item_max_initialize
    @gold_cap = ITEM_CAP::GOLD_MAX
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_gain_gold gain_gold
  alias item_max_gain_item gain_item
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    new_gold = item_max_gain_gold(n)
    @gold = [new_gold, $game_system.gold_cap].min
  end
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item          : Item
  #     n             : Number
  #     include_equip : Include equipped items
  #--------------------------------------------------------------------------
  def gain_item(item, n, include_equip = false)
    unless $scene.is_a?(Scene_Equip)
      number = item_number(item)
      cap = item.item_cap
      case item
      when RPG::Item
        @items[item.id] = [[number + n, 0].max, cap].min
      when RPG::Weapon
        @weapons[item.id] = [[number + n, 0].max, cap].min
      when RPG::Armor
        @armors[item.id] = [[number + n, 0].max, cap].min
      end
      n += number
      if include_equip and n < 0
        for actor in members
          while n < 0 and actor.equips.include?(item)
            actor.discard_equip(item)
            n += 1
          end
        end
      end
    else
      item_max_gain_item(item, n, include_equip)
    end
  end
end

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays a list of inventory items for the item screen, etc.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_cap_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    if draw_cap?(index)
      rect = item_rect(index)
      self.contents.clear_rect(rect)
      item = @data[index]
      if item != nil
        number1 = $game_party.item_number(item); number2 = item.item_cap
        enabled = enable?(item)
        rect.width -= 4
        draw_item_name(item, rect.x, rect.y, enabled)
        self.contents.draw_text(rect, sprintf(ITEM_CAP::TEXT, number1,
        number2), 2)
      end
    else
      item_cap_draw_item(index)
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return false if item.exempt_cap? unless $scene.is_a?(Scene_Equip)
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < item.item_cap)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
end

#==============================================================================
# ** Window_ShopStatus
#------------------------------------------------------------------------------
#  This window displays number of items in possession and the actor's equipment
# on the shop screen.
#==============================================================================

class Window_ShopStatus < Window_Base
  #--------------------------------------------------------------------------
  # Alias listing
  #--------------------------------------------------------------------------
  alias item_cap_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if draw_cap?(@item)
      self.contents.clear
      if @item != nil
        number = $game_party.item_number(@item); cap = @item.item_cap
        text = sprintf(ITEM_CAP::TEXT, number, cap)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 200, WLH, text, 2)
        for actor in $game_party.members
          x = 4
          y = WLH * (2 + actor.index * 2)
          draw_actor_parameter_change(actor, x, y)
        end
      end
    else
      item_cap_refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or
       number == @item.item_cap
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
        max = [max, @item.item_cap - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
end

#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
I actually don't know if that's different from the one you had.
Title: Re: Item Cap
Post by: Mushu on September 20, 2011, 01:55:46 PM
I got the same error. It might be another script creating problems with it, ill check.
Title: Re: Item Cap
Post by: rgangsta on September 20, 2011, 02:36:02 PM
I get the same error when using BigEd's Item Backup and Restore found HERE (http://www.rpgrevolution.com/forums/lofiversion/index.php/t19844.html)

Whenever I restore the player's equipment, I get that same error.
Title: Re: Item Cap
Post by: pacdiggity on September 21, 2011, 09:11:13 AM
Success!
Code: [Select]
#===============================================================================
#
# Item Cap - Pacman (21/9/2011)
# Version 2.1
# Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
# Suggestion by Scalinger2
# Use the tag <item cap: x> to set the cap of an item to number x.
# Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
# item and shop scenes.
# Set the default maximum gold in the module below.
# Set the default caps of items (when not set through notebox) in the module.
# Change the TEXT if you want for some reason.
# You can change the maximum amount of gold with the script call:
# $game_system.gold_max = x
# Where x is the maximum amount of gold.
# Set which items can have their item cap drawn in the below module. The
# available options are:
#   :items
#   :weapons
#   :armors
# New in 2.1: no longer crashes upon entering equip scene.
#
#===============================================================================
#
# CONFIGURATION
#
#===============================================================================

module ITEM_CAP
  GOLD_MAX = 40000    # Maximum amount of gold
  DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  TEXT = ": %s / %s"    # Text to display the cap
  SHOW_CAP = [        # Show cap of which items?
    :items,           # Items
    :weapons,         # Weapons
    :armors,          # Armors
  ]
end

#===============================================================================
#
# NO EDITING >:D
#
#===============================================================================

#==============================================================================
# ** RPG::BaseItem
#------------------------------------------------------------------------------
# Superclass of Skill, Item, Weapon, and Armor.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Maximum possession of item
  #--------------------------------------------------------------------------
  def item_cap
    return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
    return @item_cap if @item_cap != nil  # Don't perform if already set
    @item_cap = ITEM_CAP::DEFAULT_LIMIT
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
        @item_cap = $1.to_i
      end
    }
    return @item_cap
  end
  #--------------------------------------------------------------------------
  # * Don't draw the item's cap
  #--------------------------------------------------------------------------
  def exempt_cap?
    return if self.is_a?(RPG::Skill)
    return @exempt if @exempt != nil
    @exempt = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /\\EXEMPT_CAP/i
        @exempt = true
      end
    }
    return @exempt
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :gold_cap
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    item_max_initialize
    @gold_cap = ITEM_CAP::GOLD_MAX
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_gain_gold gain_gold
  alias item_max_gain_item gain_item
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    new_gold = item_max_gain_gold(n)
    @gold = [new_gold, $game_system.gold_cap].min
  end
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item          : Item
  #     n             : Number
  #     include_equip : Include equipped items
  #--------------------------------------------------------------------------
  def gain_item(item, n, include_equip = false)
    unless $scene.is_a?(Scene_Equip)
      number = item_number(item)
      cap = item.item_cap
      case item
      when RPG::Item
        @items[item.id] = [[number + n, 0].max, cap].min
      when RPG::Weapon
        @weapons[item.id] = [[number + n, 0].max, cap].min
      when RPG::Armor
        @armors[item.id] = [[number + n, 0].max, cap].min
      end
      n += number
      if include_equip and n < 0
        for actor in members
          while n < 0 and actor.equips.include?(item)
            actor.discard_equip(item)
            n += 1
          end
        end
      end
    else
      item_max_gain_item(item, n, include_equip)
    end
  end
end

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays a list of inventory items for the item screen, etc.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_cap_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    if draw_cap?(index)
      rect = item_rect(index)
      self.contents.clear_rect(rect)
      item = @data[index]
      if item != nil
        number1 = $game_party.item_number(item); number2 = item.item_cap
        enabled = enable?(item)
        rect.width -= 4
        draw_item_name(item, rect.x, rect.y, enabled)
        self.contents.draw_text(rect, sprintf(ITEM_CAP::TEXT, number1, number2),
         2)
      end
    else
      item_cap_draw_item(index)
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return true if item == nil and $scene.is_a?(Scene_Equip)
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < item.item_cap)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
end

#==============================================================================
# ** Window_ShopStatus
#------------------------------------------------------------------------------
#  This window displays number of items in possession and the actor's equipment
# on the shop screen.
#==============================================================================

class Window_ShopStatus < Window_Base
  #--------------------------------------------------------------------------
  # Alias listing
  #--------------------------------------------------------------------------
  alias item_cap_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if draw_cap?(@item)
      self.contents.clear
      if @item != nil
        number = $game_party.item_number(@item); cap = @item.item_cap
        text = sprintf(ITEM_CAP::TEXT, number, cap)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 200, WLH, text, 2)
        for actor in $game_party.members
          x = 4
          y = WLH * (2 + actor.index * 2)
          draw_actor_parameter_change(actor, x, y)
        end
      end
    else
      item_cap_refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or
       number == @item.item_cap
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
        max = [max, @item.item_cap - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
end

#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Title: Re: Item Cap
Post by: rgangsta on September 24, 2011, 10:34:50 PM
Sweetness! I'll give this a try right away.

.:EDIT:.
It works! I love you! Thanks a bunch.  ;D
Title: Re: Item Cap
Post by: Dimosthennis on November 06, 2011, 12:47:13 AM
Yo.
I found a wierd error...
Whenever I open a shop scenes I get this error

Script 'Item Cap' line 276: NoMethodError occurred.
undefined method '[]' for nil:NilClass

I am unsure if I did something wrong...

Title: Re: Item Cap
Post by: pacdiggity on November 06, 2011, 12:59:12 AM
Intriguing. It's odd I didn't notice this sooner.
This'll fix it.
Code: [Select]
#===============================================================================
#
# Item Cap - Pacman (6/11/2011)
# Version 2.2
# Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
# Suggestion by Scalinger2
# Use the tag <item cap: x> to set the cap of an item to number x.
# Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
# item and shop scenes.
# Set the default maximum gold in the module below.
# Set the default caps of items (when not set through notebox) in the module.
# Change the TEXT if you want for some reason.
# You can change the maximum amount of gold with the script call:
# $game_system.gold_max = x
# Where x is the maximum amount of gold.
# Set which items can have their item cap drawn in the below module. The
# available options are:
#   :items
#   :weapons
#   :armors
# New in 2.1: no longer crashes upon entering equip scene.
# New in 2.2: no longer crashes upon entering shop scene.
#
#===============================================================================
#
# CONFIGURATION
#
#===============================================================================

module ITEM_CAP
  GOLD_MAX = 40000    # Maximum amount of gold
  DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  TEXT = ": %s / %s"    # Text to display the cap
  SHOW_CAP = [        # Show cap of which items?
    :items,           # Items
    :weapons,         # Weapons
    :armors,          # Armors
  ]
end

#===============================================================================
#
# NO EDITING >:D
#
#===============================================================================

#==============================================================================
# ** RPG::BaseItem
#------------------------------------------------------------------------------
# Superclass of Skill, Item, Weapon, and Armor.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Maximum possession of item
  #--------------------------------------------------------------------------
  def item_cap
    return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
    return @item_cap if @item_cap != nil  # Don't perform if already set
    @item_cap = ITEM_CAP::DEFAULT_LIMIT
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
        @item_cap = $1.to_i
      end
    }
    return @item_cap
  end
  #--------------------------------------------------------------------------
  # * Don't draw the item's cap
  #--------------------------------------------------------------------------
  def exempt_cap?
    return if self.is_a?(RPG::Skill)
    return @exempt if @exempt != nil
    @exempt = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /\\EXEMPT_CAP/i
        @exempt = true
      end
    }
    return @exempt
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :gold_cap
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    item_max_initialize
    @gold_cap = ITEM_CAP::GOLD_MAX
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_gain_gold gain_gold
  alias item_max_gain_item gain_item
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    new_gold = item_max_gain_gold(n)
    @gold = [new_gold, $game_system.gold_cap].min
  end
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item          : Item
  #     n             : Number
  #     include_equip : Include equipped items
  #--------------------------------------------------------------------------
  def gain_item(item, n, include_equip = false)
    unless $scene.is_a?(Scene_Equip)
      number = item_number(item)
      cap = item.item_cap
      case item
      when RPG::Item
        @items[item.id] = [[number + n, 0].max, cap].min
      when RPG::Weapon
        @weapons[item.id] = [[number + n, 0].max, cap].min
      when RPG::Armor
        @armors[item.id] = [[number + n, 0].max, cap].min
      end
      n += number
      if include_equip and n < 0
        for actor in members
          while n < 0 and actor.equips.include?(item)
            actor.discard_equip(item)
            n += 1
          end
        end
      end
    else
      item_max_gain_item(item, n, include_equip)
    end
  end
end

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays a list of inventory items for the item screen, etc.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_cap_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    if draw_cap?(index)
      rect = item_rect(index)
      self.contents.clear_rect(rect)
      item = @data[index]
      if item != nil
        number1 = $game_party.item_number(item); number2 = item.item_cap
        enabled = enable?(item)
        rect.width -= 4
        draw_item_name(item, rect.x, rect.y, enabled)
        self.contents.draw_text(rect, sprintf(ITEM_CAP::TEXT, number1, number2),
         2)
      end
    else
      item_cap_draw_item(index)
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return true if item == nil and $scene.is_a?(Scene_Equip)
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < item.item_cap)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
end

#==============================================================================
# ** Window_ShopStatus
#------------------------------------------------------------------------------
#  This window displays number of items in possession and the actor's equipment
# on the shop screen.
#==============================================================================

class Window_ShopStatus < Window_Base
  #--------------------------------------------------------------------------
  # Alias listing
  #--------------------------------------------------------------------------
  alias item_cap_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if draw_cap?(@item)
      self.contents.clear
      if @item != nil
        number = $game_party.item_number(@item); cap = @item.item_cap
        text = sprintf(ITEM_CAP::TEXT, number, cap)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 200, WLH, text, 2)
        for actor in $game_party.members
          x = 4
          y = WLH * (2 + actor.index * 2)
          draw_actor_parameter_change(actor, x, y)
        end
      end
    else
      item_cap_refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @item
    return true unless item
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or
       number == @item.item_cap
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
        max = [max, @item.item_cap - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
end

#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Title: Re: Item Cap
Post by: Dimosthennis on November 06, 2011, 11:28:36 AM
Thats better.
Thanks for your time.
:)
Title: Re: Item Cap
Post by: Xzygon on December 28, 2011, 08:16:05 AM
If the name of the item happens to be too long, and the max cap is over 99, they overlap each other. Anyway to fix that?
Title: Re: Item Cap
Post by: pacdiggity on December 28, 2011, 08:52:52 AM
Hrrmmm... It's a spacing issue. There are four options.
1. Let it slide. Not recommended.
2. Make that item not display the cap. Not optimal.
3. Change the name / cap size. Not optimal.
4. Change the size of the name. This is probably the best option. It wouldn't be that difficult to fix.

Do you want me to do that?
Title: Re: Item Cap
Post by: Xzygon on December 28, 2011, 04:25:55 PM
It's probably too much of a waste of your time, so probably not. :P
Just went with not displaying the cap. Ah well, it's not needed to know how many bullets the player can have...
Title: Re: Item Cap
Post by: pacdiggity on December 29, 2011, 07:19:31 AM
I fixed it anyway.
Code: [Select]
#===============================================================================
#
# Item Cap - Pacman (29/12/2011)
# Version 2.3
# Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
# Suggestion by Scalinger2
# Use the tag <item cap: x> to set the cap of an item to number x.
# Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
# item and shop scenes.
# Set the default maximum gold in the module below.
# Set the default caps of items (when not set through notebox) in the module.
# Change the TEXT if you want for some reason.
# You can change the maximum amount of gold with the script call:
# $game_system.gold_max = x
# Where x is the maximum amount of gold.
# Set which items can have their item cap drawn in the below module. The
# available options are:
#   :items
#   :weapons
#   :armors
# New in 2.1: no longer crashes upon entering equip scene.
# New in 2.2: no longer crashes upon entering shop scene.
# New in 2.3: draws item name more efficiently.
#
#===============================================================================
#
# CONFIGURATION
#
#===============================================================================

module ITEM_CAP
  GOLD_MAX = 40000    # Maximum amount of gold
  DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  TEXT = ": %s / %s"    # Text to display the cap
  SHOW_CAP = [        # Show cap of which items?
    :items,           # Items
    :weapons,         # Weapons
    :armors,          # Armors
  ]
end

#===============================================================================
#
# NO EDITING >:D
#
#===============================================================================

#==============================================================================
# ** RPG::BaseItem
#------------------------------------------------------------------------------
# Superclass of Skill, Item, Weapon, and Armor.
#==============================================================================

class RPG::BaseItem
  #--------------------------------------------------------------------------
  # * Maximum possession of item
  #--------------------------------------------------------------------------
  def item_cap
    return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
    return @item_cap if @item_cap != nil  # Don't perform if already set
    @item_cap = ITEM_CAP::DEFAULT_LIMIT
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
        @item_cap = $1.to_i
      end
    }
    return @item_cap
  end
  #--------------------------------------------------------------------------
  # * Don't draw the item's cap
  #--------------------------------------------------------------------------
  def exempt_cap?
    return if self.is_a?(RPG::Skill)
    return @exempt if @exempt != nil
    @exempt = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /\\EXEMPT_CAP/i
        @exempt = true
      end
    }
    return @exempt
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :gold_cap
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    item_max_initialize
    @gold_cap = ITEM_CAP::GOLD_MAX
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_max_gain_gold gain_gold
  alias item_max_gain_item gain_item
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------
  def gain_gold(n)
    new_gold = item_max_gain_gold(n)
    @gold = [new_gold, $game_system.gold_cap].min
  end
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item          : Item
  #     n             : Number
  #     include_equip : Include equipped items
  #--------------------------------------------------------------------------
  def gain_item(item, n, include_equip = false)
    unless $scene.is_a?(Scene_Equip)
      number = item_number(item)
      cap = item.item_cap
      case item
      when RPG::Item
        @items[item.id] = [[number + n, 0].max, cap].min
      when RPG::Weapon
        @weapons[item.id] = [[number + n, 0].max, cap].min
      when RPG::Armor
        @armors[item.id] = [[number + n, 0].max, cap].min
      end
      n += number
      if include_equip and n < 0
        for actor in members
          while n < 0 and actor.equips.include?(item)
            actor.discard_equip(item)
            n += 1
          end
        end
      end
    else
      item_max_gain_item(item, n, include_equip)
    end
  end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This is a superclass of all windows in the game.
#==============================================================================

class Window_Base
  #--------------------------------------------------------------------------
  # * Draw Item Name
  #     item    : Item (skill, weapon, armor are also possible)
  #     x       : draw spot x-coordinate
  #     y       : draw spot y-coordinate
  #     enabled : Enabled flag. When false, draw semi-transparently.
  #     ctext   : Text to display the cap.
  #--------------------------------------------------------------------------
  def draw_item_name(item, x, y, enabled = true, ctext = "")
    if item != nil
      w = self.contents.text_size(ctext).width - 48
      draw_icon(item.icon_index, x, y, enabled)
      self.contents.font.color = normal_color
      self.contents.font.color.alpha = enabled ? 255 : 128
      self.contents.draw_text(x + 24, y, 172 - w, WLH, item.name)
    end
  end
end

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays a list of inventory items for the item screen, etc.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # alias listing
  #--------------------------------------------------------------------------
  alias item_cap_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    if draw_cap?(index)
      rect = item_rect(index)
      self.contents.clear_rect(rect)
      item = @data[index]
      if item != nil
        number1 = $game_party.item_number(item); number2 = item.item_cap
        enabled = enable?(item)
        rect.width -= 4
        ctext = sprintf(ITEM_CAP::TEXT, number1, number2)
        draw_item_name(item, rect.x, rect.y, enabled, ctext)
        self.contents.draw_text(rect, ctext, 2)
      end
    else
      item_cap_draw_item(index)
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @data[index]
    return true if item == nil and $scene.is_a?(Scene_Equip)
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < item.item_cap)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
end

#==============================================================================
# ** Window_ShopStatus
#------------------------------------------------------------------------------
#  This window displays number of items in possession and the actor's equipment
# on the shop screen.
#==============================================================================

class Window_ShopStatus < Window_Base
  #--------------------------------------------------------------------------
  # Alias listing
  #--------------------------------------------------------------------------
  alias item_cap_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if draw_cap?(@item)
      self.contents.clear
      if @item != nil
        number = $game_party.item_number(@item); cap = @item.item_cap
        text = sprintf(ITEM_CAP::TEXT, number, cap)
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
        self.contents.font.color = normal_color
        self.contents.draw_text(4, 0, 200, WLH, text, 2)
        for actor in $game_party.members
          x = 4
          y = WLH * (2 + actor.index * 2)
          draw_actor_parameter_change(actor, x, y)
        end
      end
    else
      item_cap_refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Determine whether or not to draw cap
  #     item : item to be checked
  #--------------------------------------------------------------------------
  def draw_cap?(index)
    check = ITEM_CAP::SHOW_CAP
    item = @item
    return true unless item
    return false if item.exempt_cap?
    return true if check.include?(:items) and item.is_a?(RPG::Item)
    return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
    return true if check.include?(:armors) and item.is_a?(RPG::Armor)
    return false
  end
end

#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or
       number == @item.item_cap
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
        max = [max, @item.item_cap - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
end

#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Title: Re: Item Cap
Post by: Xzygon on December 29, 2011, 06:58:16 PM
Why thank ye, good sir. I'll be sure to make good use of this script.
Title: Re: Item Cap
Post by: Wimpy on January 03, 2012, 12:35:47 PM
This script is so cool! I don't think it'll mesh with my current projects, but it's still a very neat idea. ^^ For some reason, I can see this being useful with maybe a Breath of Fire project since those games typically have low-ish caps. Gives me an idea of what I can do with this later on, at least. :P