Party Item Limit
Authors: game_guy
Version: 1.2
Type: Item Carry Limit
Key Term: Player / Party / Troop Add-on
IntroductionWhat this script does is set the party's item limit.
For instance say the party item limit is 10. You can only hold 10 items/weapons/armors.
For example you have 6 potions and 4 high potions. You won't be able to carry anything else.
Features
- Limits how many items the party can carry
- Limit is changable throughout the game
ScreenshotsN/A
DemoDemo is 1.1
Demo (http://www.sendspace.com/file/m4clp7)
Script
#===============================================================================
# Party Item Limit
# Author: game_guy
# Date: June 6th, 2009
#-------------------------------------------------------------------------------
# Intro
# What this script does is set the party's item limit. For instance say the
# party item limit is 10. You can only hold 10 different items/weapons/armors.
# For example you have 6 potions and 4 high potions. You won't be able to
# Carry anything else.
#
# Features
# * Limits how many items the party can carry
#
# Instructions
# Go down to the BEGIN CONFIG and you'll see this line
# @max_items = 20
# Change that 20 to whatever you like.
# You can also change that number in game using this in a script call
# $game_system.max_items = x
# x = number
#
# Credits
# game_guy ~ for making it
# Xuroth ~ inspiring me with the idea of a post
# link to post
# http://forum.chaos-project.com/index.php?topic=3444.msg74388#msg74388
#===============================================================================
#===============================================================================
# Game_System
#-------------------------------------------------------------------------------
# *Changed one method
#===============================================================================
class Game_System
attr_accessor :max_items
alias add_max_items initialize
def initialize
#===========================================================================
# BEGIN CONFIG
@max_items = 20 # Change this to the max items you want the party to carry
# END CONFIG
#===========================================================================
add_max_items
end
end
#===============================================================================
# Game_Party
#-------------------------------------------------------------------------------
# *Added one method
# *changed three methods
#===============================================================================
class Game_Party
#=============================================================================
# Get Item Total
#=============================================================================
def get_item_total
amount = 0
for i in 1...$data_items.size
if item_number(i) > 0
amount += item_number(i)
end
end
for i in 1...$data_weapons.size
if weapon_number(i) > 0
amount += weapon_number(i)
end
end
for i in 1...$data_armors.size
if armor_number(i) > 0
amount += armor_number(i)
end
end
return amount
end
#=============================================================================
# Gain Item
#=============================================================================
def gain_item(item_id, n)
if item_id > 0
itemamount = get_item_total
unless itemamount == $game_system.max_items
number = $game_system.max_items - itemamount
if n > number
n = number
end
@items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
end
end
end
#=============================================================================
# Gain Weapon
#=============================================================================
def gain_weapon(weapon_id, n)
if weapon_id > 0
itemamount = get_item_total
unless itemamount == $game_system.max_items
number = $game_system.max_items - itemamount
if n > number
n = number
end
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
end
end
end
#=============================================================================
# Gain Armor
#=============================================================================
def gain_armor(armor_id, n)
if armor_id > 0
itemamount = get_item_total
unless itemamount == $game_system.max_items
number = $game_system.max_items - itemamount
if n > number
n = number
end
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
end
end
end
end
Here's a different version that allows you to set the maximum of items, armors, and weapons instead of all of them together
#===============================================================================
# Party Item Limit
# Author: game_guy
# Date: June 6th, 2009
#-------------------------------------------------------------------------------
# Intro
# What this script does is set the party's item limit. For instance say the
# party item limit is 10. You can only hold 10 different items/weapons/armors.
# For example you have 6 potions and 4 high potions. You won't be able to
# Carry anything else.
#
# Features
# * Limits how many items the party can carry
#
# Instructions
# Go down to the BEGIN CONFIG and you'll see this line
# @max_items = 20
# @max_weapons = 20
# @max_armors = 20
# Change that 20 to whatever you like.
# You can also change that number in game using this in a script call
# $game_system.max_items = x
# $game_system.max_weapons = x
# $game_system.max_armor = x
# x = number
#
# Credits
# game_guy ~ for making it
# Xuroth ~ inspiring me with the idea of a post
# link to post
# http://forum.chaos-project.com/index.php?topic=3444.msg74388#msg74388
#===============================================================================
#===============================================================================
# Game_System
#-------------------------------------------------------------------------------
# *Changed one method
#===============================================================================
class Game_System
attr_accessor :max_items
attr_accessor :max_weapons
attr_accessor :max_armor
alias add_max_items initialize
def initialize
#===========================================================================
# BEGIN CONFIG
@max_items = 20 # Change this to the max items you want the party to carry
@max_weapons = 20 # Change this to the max weapons you want the party to carry
@max_armor = 20 # Change this to the max armor you want the party to carry
# END CONFIG
#===========================================================================
add_max_items
end
end
#===============================================================================
# Game_Party
#-------------------------------------------------------------------------------
# *Added one method
# *changed three methods
#===============================================================================
class Game_Party
#=============================================================================
# Get Item Total
#=============================================================================
def get_item_total
amount = 0
for i in 1...$data_items.size
if item_number(i) > 0
amount += item_number(i)
end
end
return amount
end
#=============================================================================
# Get Armor Total
#=============================================================================
def get_armor_total
amount = 0
for i in 1...$data_armors.size
if armor_number(i) > 0
amount += armor_number(i)
end
end
return amount
end
#=============================================================================
# Get Weapon Total
#=============================================================================
def get_weapon_total
amount = 0
for i in 1...$data_weapons.size
if weapon_number(i) > 0
amount += weapon_number(i)
end
end
return amount
end
#=============================================================================
# Gain Item
#=============================================================================
def gain_item(item_id, n)
if item_id > 0
itemamount = get_item_total
unless itemamount >= $game_system.max_items
number = $game_system.max_items - itemamount
if n > number
n = number
end
@items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
end
end
end
#=============================================================================
# Gain Weapon
#=============================================================================
def gain_weapon(weapon_id, n)
if weapon_id > 0
itemamount = get_weapon_total
unless itemamount >= $game_system.max_weapons
number = $game_system.max_weapons - itemamount
if n > number
n = number
end
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
end
end
end
#=============================================================================
# Gain Armor
#=============================================================================
def gain_armor(armor_id, n)
if armor_id > 0
itemamount = get_armor_total
unless itemamount >= $game_system.max_armor
number = $game_system.max_armor - itemamount
if n > number
n = number
end
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
end
end
end
end
InstructionsInstructions
Go down to the BEGIN CONFIG and you'll see this line
@max_items = 20
Change that 20 to whatever you like.
You can also change that number in game using this in a script call
$game_system.max_items = x
x = number
CompatibilityNot tested with SDK. Should be compatible with pretty much anything.
Credits and Thanks
- game_guy ~ for making it
- Xuroth ~ inspiring me with the idea of a post
Quote from: Xuroth on June 09, 2009, 07:00:26 pm
I was just thinking that the 99 of any item would seem kinda ridiculus. Arshes: I can carry 99 of any item, but not 100, yet i can carry 99 of another item at the same time!
Hilda: I can carry 250 pounds of items
you already have an awesome feature, but I think you could do even better. of course if you dont like the idea, thats fine. I know how it would work, and how to assign (through many ways ) weight to items using multiplexed dummy elements or by using a comment in the items description (simpler) any way thanks for the awesome script
Author's NotesN/A
this system is flawed it only checks to see if you have the max items already if you have one less than the max then gain 100 items all at the same time then you will still gain the 100 items. same if you have 0 and gain more than the max all at the same time, also you only give them one potion in the demo not 20
use an n.times loop and increase the number of items they have by 1 each loop unless they have the max items. like so
def gain_item(item_id, n)
if item_id > 0
itemamount = get_item_total
n.times {|i|
unless itemamount == $game_system.max_items
@items[item_id] = [[item_number(item_id) 1 n, 0].max, 99].min
end
}
end
end
Just to be nitpicky...
QuoteYou can only hold 10 different items/weapons/armors.
For example you have 6 potions and 4 high potions.
In this example, that'd only be 2 different items, so you'd be able to carry 8 more different items.
@ryex I do need to fix that.
@aqua no you couldnt have 8 more. I meant 10 items total its hard for me to explain. Pretty much you can only hold a total of 10 items at a time
i edited my post with a easy way to fix that problem g_g
I had already fixed it :P XD
Anyways updated.
my method is faster and uses less code
YOU FAIL G_G... :V:
well I updated it before you edited post and oh well if I fail. I fail at a lot of things xD
Anyways any thoughts on teh script itself?
I editted your introduction to fix some minor stuff.
Added a different version that allows you to setup the max items, weapons, and armors
Well, here are some lines of code that some people might find usefull (to be used with the first version):
To print the current number of items and the max number of items on a window (maybe replacing the steps/playtime window on the menu) :
self.contents.draw_text(4, 20, 120, 32, $game_party.get_item_total.to_s + "/" + $game_system.max_items.to_s)
If you decide to upgrade the "bag" on a constant basis (20 items each time, for example), you can use this to show the next size of your bag:
self.contents.draw_text(4, 60, 120, 32, ($game_system.max_items + 20).to_s)
You can replace the 20 for any other number, so if you have a item cap of 20, it'll show 40.
Also, I guess people know this alredy, but you can use this to sum certain number of items instead of giving a real number (usefull if you want to make some kind of upgrade bag shop, I guess) :
$game_system.max_items =
$game_system.max_items + n
Where n is the number of allowed items you want to give to the player.
I know it's very basic stuff, but I wanted to thanks for the script, so I thought I'd might as well share the little stuff I found out, in case another noob like me comes and wants to do any of that. So... thanks for the script :^_^':
wouldn't you just do this
#===============================================================================
# Game_System
#-------------------------------------------------------------------------------
# *Changed one method
#===============================================================================
class Game_System
attr_accessor :max_items
alias add_max_items initialize
def initialize
#===========================================================================
# BEGIN CONFIG
@max_items = 20 # Change this to the max items you want the party to carry
# END CONFIG
#===========================================================================
add_max_items
end
end
#===============================================================================
# Game_Party
#-------------------------------------------------------------------------------
# *Added one method
# *changed three methods
#===============================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Gain Items (or lose)
# item_id : item ID
# n : quantity
#--------------------------------------------------------------------------
def gain_item(item_id, n)
# Update quantity data in the hash.
if item_id > 0
@items[item_id] = [[item_number(item_id) + n, 0].max, $game_systems.max_items].min
end
end
#--------------------------------------------------------------------------
# * Gain Weapons (or lose)
# weapon_id : weapon ID
# n : quantity
#--------------------------------------------------------------------------
def gain_weapon(weapon_id, n)
# Update quantity data in the hash.
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, $game_systems.max_items].min
end
end
#--------------------------------------------------------------------------
# * Gain Armor (or lose)
# armor_id : armor ID
# n : quantity
#--------------------------------------------------------------------------
def gain_armor(armor_id, n)
# Update quantity data in the hash.
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, $game_systems.max_items].min
end
end
end
I noticed a flaw in this script where it won't check if you can carry your entire purchase when at a shop. If you can't it just gives you what you can carry but you still pay for everything else.
Quote from: Sacred Nym on June 26, 2010, 04:23:55 pm
I noticed a flaw in this script where it won't check if you can carry your entire purchase when at a shop. If you can't it just gives you what you can carry but you still pay for everything else.
True. Here's a little edit in order to avoid that:
Edited: The last fix had a bug where you couldn't sell items if you had more the max number of items. Anyways, here's another fix, hopefully this one will have no bugs:
Change your Shop_Scene (I'm using the default one) for this one:
#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
# This class performs shop screen processing.
#==============================================================================
class Scene_Shop
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window
@help_window = Window_Help.new
# Make command window
@command_window = Window_ShopCommand.new
# Make gold window
@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 64
# Make dummy window
@dummy_window = Window_Base.new(0, 128, 640, 352)
# Make buy window
@buy_window = Window_ShopBuy.new($game_temp.shop_goods)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
# Make sell window
@sell_window = Window_ShopSell.new
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
# Make quantity input window
@number_window = Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
# Make status window
@status_window = Window_ShopStatus.new
@status_window.visible = false
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@sell_window.dispose
@number_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@sell_window.update
@number_window.update
@status_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If buy window is active: call update_buy
if @buy_window.active
update_buy
return
end
# If sell window is active: call update_sell
if @sell_window.active
update_sell
return
end
# If quantity input window is active: call update_number
if @number_window.active
update_number
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # buy
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Change windows to buy mode
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
@status_window.visible = true
when 1 # sell
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Change windows to sell mode
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
when 2 # quit
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to map screen
$scene = Scene_Map.new
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when buy window is active)
#--------------------------------------------------------------------------
def update_buy
# Set status window item
@status_window.item = @buy_window.item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Change windows to initial mode
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
# Erase help text
@help_window.set_text("")
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get item
@item = @buy_window.item
# If item is invalid, or price is higher than money possessed
if @item == nil or @item.price > $game_party.gold
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Get items in possession count
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
# If 99 items are already in possession
if number == 99
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Calculate maximum amount possible to buy
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number].min
# Change windows to quantity input mode
@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
#--------------------------------------------------------------------------
# * Frame Update (when sell window is active)
#--------------------------------------------------------------------------
def update_sell
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Change windows to initial mode
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
# Erase help text
@help_window.set_text("")
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get item
@item = @sell_window.item
# Set status window item
@status_window.item = @item
# If item is invalid, or item price is 0 (unable to sell)
if @item == nil or @item.price == 0
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Get items in possession count
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
# Maximum quanitity to sell = number of items in possession
max = number
# Change windows to quantity input mode
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
#--------------------------------------------------------------------------
# * Frame Update (when quantity input window is active)
#--------------------------------------------------------------------------
def update_number
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Set quantity input window to inactive / invisible
@number_window.active = false
@number_window.visible = false
# Branch by command window cursor position
case @command_window.index
when 0 # buy
# Change windows to buy mode
@buy_window.active = true
@buy_window.visible = true
when 1 # sell
# Change windows to sell mode
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Set quantity input window to inactive / invisible
@number_window.active = false
@number_window.visible = false
# Branch by command window cursor position
case @command_window.index
when 0 # buy
# Buy process
case @item
when RPG::Item
if $game_party.get_item_total + @number_window.number <= $game_system.max_items
$game_party.gain_item(@item.id, @number_window.number)
$game_party.lose_gold(@number_window.number * @item.price)
$game_system.se_play($data_system.shop_se)
else
$game_system.se_play($data_system.cancel_se)
end
when RPG::Weapon
if $game_party.get_item_total + @number_window.number <= $game_system.max_items
$game_party.gain_weapon(@item.id, @number_window.number)
$game_party.lose_gold(@number_window.number * @item.price)
$game_system.se_play($data_system.shop_se)
else
$game_system.se_play($data_system.cancel_se)
end
when RPG::Armor
if $game_party.get_item_total + @number_window.number <= $game_system.max_items
$game_party.gain_armor(@item.id, @number_window.number)
$game_party.lose_gold(@number_window.number * @item.price)
$game_system.se_play($data_system.shop_se)
else
$game_system.se_play($data_system.cancel_se)
end
end
# Refresh each window
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
# Change windows to buy mode
@buy_window.active = true
@buy_window.visible = true
when 1 # sell
# Sell process
case @item
when RPG::Item
$game_party.lose_item(@item.id, @number_window.number)
$game_system.se_play($data_system.shop_se)
$game_party.gain_gold(@number_window.number * (@item.price / 2))
when RPG::Weapon
$game_party.lose_weapon(@item.id, @number_window.number)
$game_system.se_play($data_system.shop_se)
$game_party.gain_gold(@number_window.number * (@item.price / 2))
when RPG::Armor
$game_party.lose_armor(@item.id, @number_window.number)
$game_system.se_play($data_system.shop_se)
$game_party.gain_gold(@number_window.number * (@item.price / 2))
end
# Refresh each window
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
# Change windows to sell mode
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
end
end
Hopefully that will solve it for good. If you find any bugs... well, I guess I'll try to fix them lol. Or if you can fix them, that's fine with me :^_^':