Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Item Cap
Pacman
post Jan 30 2012, 07:57 PM
Post #1


Level 3
Group Icon

Group: Member
Posts: 34
Type: Scripter
RM Skill: Advanced




Item Cap

Version: 2.3
Author: Pacman
Release Date: 29/12/2011


Introduction
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
Notebox tag for setting individual item caps on each item
Notebox tag for not drawing the item's cap in windows
Altering limit on gold, also changeable in-game
Displays item cap in item (battle), equip and shop scenes
You can set which types of items (items, weapons and armors) have their cap displayed in the inventory scenes

Script
Updates will be more reliable if you get it from Pastebin. I'll also post it here.
CODE
#===============================================================================
#
# 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
#
#===============================================================================


Customization

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

Compatibility
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.

Screenshot

Screenshot of rgangsta's CyberDrive
.

DEMO
I didn't figure it was necessary. If I must, I'll make one.

Installation
Paste above main, see script header.

FAQ
None yet.

Terms and Conditions
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.

Credits
- Pacman
- Special thanks (credit not required) to rgangsta (for requesting), Scalinger2 (for a suggestion), Mog (I used a similar script in XP of his as a guideline) and Xzygon (bug report).


__________________________
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies (1 - 2)
Kread-EX
post Jan 31 2012, 01:29 AM
Post #2


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




That's pretty neat. Yeah, most item cap scripts tend to give a global cap rather than a specific per-item one.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
Pacman
post Jan 31 2012, 01:41 AM
Post #3


Level 3
Group Icon

Group: Member
Posts: 34
Type: Scripter
RM Skill: Advanced




Yeah, the request was specifically to have individual item caps, and i like it better that way... although I could add an optional global cap, that could make things more realistic. I'll think about that.
Thanks for giving me that suggestion!


__________________________
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th May 2013 - 08:18 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker