Theo - Limited Inventory

Tigersong

Furry Fellow
Veteran
Joined
Oct 22, 2012
Messages
451
Reaction score
44
First Language
English
Primarily Uses
I'm a bit confused as to what to actually put in the script editor... but that could be my inexperience talking. Anyhow, it looks like something I may use in the future.
 

SpacemanFive

Meteor Mage
Veteran
Joined
Jun 25, 2013
Messages
207
Reaction score
24
First Language
English
Primarily Uses
Have to say I love this script so far. Very glad I saw the thread up here.

I think it'll really help with the projects I'm working on at the moment, where it's important to manage your inventory wisely. (And somewhat realistically.)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
Bump for update to version 1.3! :D

Now, what is new?

  • I have added ability to change base inventory limit using script call. Some people just asked me how to change inventory limit or something. Not only in this forum. So, I decided to update to this version.
  • Added ability to write your own custom formula. It's similar as damage formula in database (exclude a, b, v). Well, I admit it that was crazy idea which I didn't think of it. Thanks very much ~
Change logs (indonesian) can be found here

Sorry for late update. I was busy with my college life and I was addicted to playing games xD
 

MrDaisy

Villager
Member
Joined
Mar 9, 2014
Messages
20
Reaction score
1
Primarily Uses
well, finally i find one that work perfectly with the other scripts...

thanks for the script.
 

Shian

Pervasively Incandescent
Veteran
Joined
Jan 23, 2014
Messages
33
Reaction score
13
Primarily Uses
Hi, I've edited the script to make it so I can use Tsukihime's map drop script to discard items with one button press. It works fine, except I am capable of selecting things that aren't supposed to be selectable. For items it just gets rid of the item (without putting it on the map), but when I select weapons/armour I get

"Script 'Scene_ItemBase' line 80:NoMethodError Occured.

undefined method for 'for_friend?' for #<RPG::Armor:0x909424c>"

I can't seem to find the part of the script I can edit out to stop all items being selectable. This is the code:

# =============================================================================# TheoAllen - Limited Inventory# Version : 1.3# Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com# (English Documentation)# =============================================================================($imported ||= {})[:Theo_LimInventory] = true# =============================================================================# Change logs:# -----------------------------------------------------------------------------# 2014.02.25 - Add limited inventory eval formula to provide flexibility# - Change notetag constant to provide flexibility# 2014.02.16 - Base Inventory slot of an actor can be changed using script call# 2014.02.11 - Bugfix. Unequip item causes lose the item if inventory is full# 2013.10.07 - Bugfix. Item doesn't removed when discarded# - Bugfix. Inventory amount not refreshed when item is discarded# 2013.10.04 - Compatibility fix with chest system# 2013.08.30 - Now unable to discard key item# 2013.08.22 - Bugfix. Item size notetag isn't working# 2013.08.19 - Bugfix when gained item# - Bugfix when disable display item size in shop menu# 2013.08.18 - Finished script# ==============================================================================begin --------------------------------------------------------------------------- Introduction : This script allow you to limit your inventory by overall possesed items instead of individual items --------------------------------------------------------------------------- How to Use : Put this script below material but above main If you're using YEA - Shop Option, put it below that script Edit configurations and the notetags as described below --------------------------------------------------------------------------- Notetags : write down these notetags to the notebox in your database <inv size: n> Use this notetag where the n is a numeric value which is determine the size of item. Use 0 for unlimited item. Only works for item and equipment such as weapon or armor. <inv plus: n> Use this notetag to determine the additional avalaible free inventory slot. This notetag avalaible for Actor, Class, Equip, and States. If it's for actor, avalaible inventory slot will increase when a new actor entered party. If it's for equip, the avalaible slot will be increase if the certain equip is equipped. And so do states. This value can be changed by script call during the game. Just check the script call instruction. <inv minus: n> Inverse of <inv plus>. It will decrease the avalaible inventory slot. Pretty clear I think. <inv formula> script </inv formula> This notetag is used to determine inventory limit based on your own formula For example, inventory limit for an actor is based on its agility or even its level. It can be used inside actor or class notebox. Inventory formula is automatically accumulated with base inventory. I mean, if you're going to add <inv plus: 100> and your formula. Then, the result is ==> 100 + your formula Example : <inv formula> level * 100 </inv formula> By using this formula it means that each actor has leveled up, its base inventory will be increase by 100. If you're using multiple lines, it will be considered as a one line. You can also using these parameters to determine your own formula. - mhp - mmp - atk - def - mat - mdf - agi - luk - $game_variables[id] Note : - A false formula may produce an error. So, make sure you write the correct formula. Alternatively, you can ask ppl out there to help you out. - For scripter, the formula eval is evaled inside Game_Actor --------------------------------------------------------------------------- Script call : If you want to force gain an item even the inventory is full, you can do it by script call. Just write this following line force_gain_item($data_items[id],amount) id is an item id in your database To change base inventory for an actor, use these script call $game_actors[id].base_inv = value << Set $game_actors[id].base_inv += value << Add $game_actors[id].base_inv -= value << Substract If you set dynamic slot as false, you can change inventory limit by using this script call. $game_party.base_inv = value --------------------------------------------------------------------------- Terms of use : Credit me, TheoAllen. You are free to edit this script by your own. As long as you don't claim it yours. For commercial purpose, don't forget to give me a free copy of the game.=end# =============================================================================# Configurations :# =============================================================================module Theo module LimInv # -------------------------------------------------------------------------- # General Settings (just put true / false) # -------------------------------------------------------------------------- DynamicSlot = true # Total avalaible inventory slot depends on actor, states, total party # members, etc ... Display_ItemSize = true # Diplay item size in item menu Include_Equip = false # Total used inventory slot will also include actor equipment. DrawTotal_Size = false # If true, item size window will show total weight of specified item. For # example, you have 10 potions. And each potion has 3 size/weight. The window # will show 30 instead of 3 # -------------------------------------------------------------------------- # Numeric Settings # -------------------------------------------------------------------------- Default_FreeSlot = 0 # Default values which is provided each actor. Of course, you may change # it by notetag. If DynamicSlot is set to false, it will be used as the total # avalaible slot NearMaxed_Percent = 25 # Remain avalaible slot percentage to determine if the inventory is almost # maxed out or not. NearMaxed_Color = 21 # If inventory is almost maxed out, the inventory window will be drawn in # different color. The color code is same as \C[n] in message UseCommand_Size = 200 # The width of use item command window # -------------------------------------------------------------------------- # Vocab Settings (Self-explanatory I think) # -------------------------------------------------------------------------- InvSlotVocab = "Inventory: " # Inventory Vocab InvSizeVocab = "Item Size: " # Item size / weight SlotVocabShort = "Inv:" # Abbreviation for Inventory UseVocab = "Use item" # Use item DiscardVocab = "Discard item" # Discard Item CancelVocab = "Cancel" # Cancel endend# ============================================================================# Do not touch anything pass this line.# =============================================================================begin ----------------------------------------------------------------------------- Compatibility info : ----------------------------------------------------------------------------- This script overwrite these methods : Game_Actor >> trade_item_with_party Game_Party >> max_item_number Game_Party >> item_max? ----------------------------------------------------------------------------- This script aliased these methods : DataManager >> load_database Game_Actor >> setup Game_Party >> initialize Scene_Menu >> start Scene_Item >> start Scene_Item >> use_item Scene_Shop >> on_buy_ok Scene_Shop >> on_sell_ok=end# =============================================================================# Altered built in modules and classes# =============================================================================# =============================================================================# ▼ DataManager# =============================================================================class << DataManager alias theo_limited_item_load_db load_database def load_database theo_limited_item_load_db load_limited_slot end def load_limited_slot database = $data_actors + $data_classes + $data_weapons + $data_armors + $data_states + $data_items database.compact.each do |db| db.load_limited_inv end endend# =============================================================================# ▼ RPG::BaseItem# =============================================================================class RPG::BaseItem attr_accessor :inv_size # Item inventory size attr_accessor :inv_mod # Inventory slot modifier attr_accessor :inv_eval # Inventory eval modifier InvSizeREGX = /<inv[\s_]+size\s*:\s*(\d+)>/i InvPlusREGX = /<inv[\s_]+plus\s*:\s*(\d+)>/i InvMinusREGX = /<inv[\s_]+minus\s*:\s*(\d+)/i InvFormSTART = /<inv[\s_]+formula>/i InvFormEND = /<\/inv[\s_]+formula>/i def load_limited_inv load_eval = false @inv_size = 1 @inv_eval = '0' @inv_mod = self.is_a?(RPG::Actor) ? Theo::LimInv::Default_FreeSlot : 0 self.note.split(/[\r\n]+/).each do |line| case line when InvSizeREGX @inv_size = $1.to_i when InvPlusREGX @inv_mod = $1.to_i when InvMinusREGX @inv_mod = -$1.to_i when InvFormSTART load_eval = true @inv_eval = '' when InvFormEND load_eval = false else @inv_eval += line if load_eval end end end end# =============================================================================# Data structures and workflows goes here# =============================================================================# =============================================================================# ▼ Game_Actor# =============================================================================class Game_Actor < Game_Battler attr_accessor :base_inv alias theo_liminv_setup setup def setup(actor_id) theo_liminv_setup(actor_id) @base_inv = $data_actors[id].inv_mod end def equip_size return 0 unless Theo::LimInv::Include_Equip equips.compact.inject(0) {|total,equip| total + equip.inv_size} end def inv_max result = base_inv result += $data_classes[class_id].inv_mod result += states.inject(0) {|total,db| total + db.inv_mod} result += equips.compact.inject(0) {|total,db| total + db.inv_mod} result += eval(actor.inv_eval) result += eval(self.class.inv_eval) result end # -------------------------------------------------------------------------- # Overwrite : Trade item with party # -------------------------------------------------------------------------- def trade_item_with_party(new_item, old_item) return false if new_item && !$game_party.has_item?(new_item) $game_party.force_gain_item(old_item, 1) $game_party.force_gain_item(new_item, -1) return true end end# =============================================================================# ▼ Game_Party# =============================================================================class Game_Party < Game_Unit attr_accessor :base_inv alias theo_liminv_init initialize def initialize @base_inv = (Theo::LimInv::DynamicSlot ? 0 : Theo::LimInv::Default_FreeSlot) theo_liminv_init end def inv_max return @base_inv unless Theo::LimInv::DynamicSlot return members.inject(0) {|total,member| total + member.inv_max} + @base_inv end def inv_maxed? inv_max <= total_inv_size end def total_inv_size result = all_items.inject(0) {|total,item| total + (item_number(item) * item.inv_size)} result += members.inject(0) {|total,member| total + member.equip_size} result end alias theo_liminv_max_item max_item_number def max_item_number(item) $BTEST ? theo_liminv_max_item(item) : inv_max_item(item) + item_number(item) end def inv_max_item(item) return 9999999 if item.nil? || item.inv_size == 0 free_slot / item.inv_size end def free_slot inv_max - total_inv_size end alias theo_liminv_item_max? item_max? def item_max?(item) $BTEST ? theo_liminv_item_max?(item) : inv_maxed? end def near_maxed? free_slot.to_f / inv_max <= Theo::LimInv::NearMaxed_Percent/100.0 end def item_size(item) return 0 unless item item.inv_size * item_number(item) end def force_gain_item(item, amount) container = item_container(item.class) return unless container last_number = item_number(item) new_number = last_number + amount container[item.id] = [new_number, 0].max container.delete(item.id) if container[item.id] == 0 $game_map.need_refresh = true end end# =============================================================================# ▼ Game_Interpreter# =============================================================================class Game_Interpreter def force_gain_item(item, amount) $game_party.force_gain_item(item, amount) endend# =============================================================================# Window related class goes here# =============================================================================# =============================================================================# ▼ Window_Base# =============================================================================class Window_Base < Window def draw_inv_slot(x,y,width = contents.width,align = 2) txt = sprintf("%d/%d",$game_party.total_inv_size, $game_party.inv_max) color = Theo::LimInv::NearMaxed_Color if $game_party.near_maxed? change_color(text_color(color)) else change_color(normal_color) end draw_text(x,y,width,line_height,txt,align) change_color(normal_color) end def draw_inv_info(x,y,width = contents.width) change_color(system_color) draw_text(x,y,width,line_height,Theo::LimInv::InvSlotVocab) change_color(normal_color) draw_inv_slot(x,y,width) end def draw_item_size(item,x,y,total = true,width = contents.width) rect = Rect.new(x,y,width,line_height) change_color(system_color) draw_text(rect,Theo::LimInv::InvSizeVocab) change_color(normal_color) number = (Theo::LimInv::DrawTotal_Size && total) ? $game_party.item_size(item) : item.nil? ? 0 : item.inv_size draw_text(rect,number,2) endend# =============================================================================# ▼ New Class : Window_MenuLimInv# =============================================================================class Window_MenuLimInv < Window_Base def initialize(width) super(0,0,width,fitting_height(1)) refresh end def refresh contents.clear change_color(system_color) txt = Theo::LimInv::SlotVocabShort draw_text(0,0,contents.width,line_height,txt) draw_inv_slot(0,0) end end# =============================================================================# ▼ New Class : Window_ItemSize# =============================================================================class Window_ItemSize < Window_Base def initialize(x,y,width) super(x,y,width,fitting_height(1)) end def set_item(item) @item = item refresh end def refresh contents.clear draw_item_size(@item,0,0) end end# =============================================================================# ▼ New Class : Window_FreeSlot# =============================================================================class Window_FreeSlot < Window_Base def initialize(x,y,width) super(x,y,width,fitting_height(1)) refresh end def refresh contents.clear draw_inv_info(0,0) endend# =============================================================================# ▼ Window_ItemList# =============================================================================class Window_ItemList < Window_Selectable attr_reader :item_size_window def item_size_window=(window) @item_size_window = window update_help end alias theo_liminv_update_help update_help def update_help theo_liminv_update_help @item_size_window.set_item(item) if @item_size_window end alias theo_liminv_height= height= def height=(height) self.theo_liminv_height = height refresh end def enable?(item) return !item.nil? end end# =============================================================================# ▼ Window_ShopNumber# =============================================================================class Window_ShopNumber < Window_Selectable attr_accessor :mode alias theo_liminv_init initialize def initialize(x, y, height) theo_liminv_init(x, y, height) @mode = :buy end alias theo_liminv_refresh refresh def refresh theo_liminv_refresh draw_itemsize end def draw_itemsize item_size = @number * @item.inv_size total_size = $game_party.total_inv_size + (@mode == :buy ? item_size : -item_size) txt = sprintf("%d/%d",total_size,$game_party.inv_max) ypos = item_y + line_height * ($imported["YEA-ShopOptions"] ? 5 : 4) rect = Rect.new(4,ypos,contents.width-8,line_height) change_color(system_color) draw_text(rect,Theo::LimInv::InvSlotVocab) change_color(normal_color) draw_text(rect,txt,2) end end# =============================================================================# ▼ Window_ShopStatus# =============================================================================class Window_ShopStatus < Window_Base if Theo::LimInv::Display_ItemSize alias theo_liminv_draw_posses draw_possession def draw_possession(x, y) theo_liminv_draw_posses(x,y) y += line_height draw_item_size(@item,x,y,false, contents.width-(x*2)) end if $imported["YEA-ShopOptions"] def draw_actor_equip_info(dx, dy, actor) dy += line_height enabled = actor.equippable?(@item) change_color(normal_color, enabled) draw_text(dx, dy, contents.width, line_height, actor.name) item1 = current_equipped_item(actor, @item.etype_id) draw_actor_param_change(dx, dy, actor, item1) if enabled end end # $imported["YEA-ShopOption"] end # Display item sizeend# =============================================================================# Scene classes goes here# =============================================================================# =============================================================================# ▼ Scene_Menu# =============================================================================class Scene_Menu < Scene_MenuBase alias theo_liminv_start start def start theo_liminv_start create_liminv_window end def create_liminv_window @lim_inv = Window_MenuLimInv.new(160) @lim_inv.x = @command_window.x @lim_inv.y = @command_window.height end end# =============================================================================# ▼ Scene_Item# =============================================================================class Scene_Item < Scene_ItemBase alias theo_liminv_start start def start theo_liminv_start resize_item_window create_freeslot_window create_itemsize_window end def resize_item_window @item_window.height -= @item_window.line_height * 2 end def create_freeslot_window wy = @item_window.y + @item_window.height wh = Theo::LimInv::Display_ItemSize ? Graphics.width/2 : Graphics.width @freeslot = Window_FreeSlot.new(0,wy,wh) @freeslot.viewport = @viewport end def create_itemsize_window return unless Theo::LimInv::Display_ItemSize wx = @freeslot.width wy = @freeslot.y ww = wx @itemsize = Window_ItemSize.new(wx,wy,ww) @itemsize.viewport = @viewport @item_window.item_size_window = @itemsize end end# =============================================================================# ▼ Scene_Shop# =============================================================================class Scene_Shop < Scene_MenuBase alias theo_liminv_buy_ok on_buy_ok def on_buy_ok @number_window.mode = :buy theo_liminv_buy_ok end alias theo_liminv_sell_ok on_sell_ok def on_sell_ok @number_window.mode = :sell theo_liminv_sell_ok endend
Could someone help me out please? Thanks.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
Try to get rid the line 490 - 492

Code:
  def enable?(item)    return !item.nil?  end
 

Zoecyta

Claire will be back!
Member
Joined
Apr 17, 2014
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Nice man, is there a way so each stack of items has 1 size instead of the number of items?  (stack of 20 pots = 1 size)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
Well, sorry... no

I haven't impement float number as item size (e.g the item size is 0.05 for each item)

Moreover, I'm not in a position to edit script. You can ask other scripters to edit my script :)
 

frederik850

Villager
Member
Joined
May 17, 2014
Messages
91
Reaction score
1
First Language
dutch
Primarily Uses
I got this error when I try to buy a weapon: Line 337: Type error occured. Nil can't be coerced into fixnum. What should I do?
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
Sorry for late reply

Did u use other scripts such as custom database?
 

frederik850

Villager
Member
Joined
May 17, 2014
Messages
91
Reaction score
1
First Language
dutch
Primarily Uses
I use many other scripts, I don't think I have custom database, though.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
It works fine here... it may be a conflict but who knows

If the line 337 was

free_slot / item.inv_sizeThen, try to change it

free_slot / (item.inv_size rescue 1)Not sure if it works though
 

Fallun

Villager
Member
Joined
May 24, 2014
Messages
26
Reaction score
1
First Language
Danish
Primarily Uses
Awesooome! i love this script, thanks a bunch for sharing the script!
 

shadow2k

Villager
Member
Joined
Oct 12, 2013
Messages
21
Reaction score
2
First Language
English
Primarily Uses
I'm wondering if there is a way to combine this script's functionality with the chest system in order to limit the amount of size/weight a chest can carry?  I think this would be useful in creating a variety of storage containers for use in an advanced crafting system I'm working on.

Basically, I'm just looking to apply the limited inventory mechanics to the chest system, but I'm not sure how to actually do it.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
None at the moment. Since I have no interest on modifying my chest system either. 

But anyone are free to modify and adapt my works if interested
 

AtliJorund

Warper
Member
Joined
Aug 29, 2014
Messages
1
Reaction score
0
First Language
English
Primarily Uses
It's been a minute since anyone has posted but lemme say I love it, it does the job. One thing I did notice is that is doesn't update your total weight until you back out of the items screen. I'll toy around with it later (I have to sleep sometime) and see what I can do.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,498
First Language
Indonesian
Primarily Uses
RMVXA
When it doesn't update the total item? After you discarded an item? or after use?
 

Ralpf

Veteran
Veteran
Joined
Jun 5, 2014
Messages
590
Reaction score
152
First Language
English
Very good idea...didn't think about using something like this till I saw it...but I think it would work well with what I am working on.
 

Kuronokun

Villager
Member
Joined
Aug 10, 2014
Messages
21
Reaction score
2
First Language
French
Primarily Uses
Hello !

First, thank you for this script, it's very usefull and easy to understand it.

I noticed two problems. I explain : My inventory limit is 20. I created an armor who add 10 slot. So, when i'm wearing this armor, my inventory limit is 30.

My inventory is full ( so 30/30 ). If i take off the armor, my inventory is now 30/20.

And i need to put another item in my inventory to update the limit.

Second problem : when it updates the limit, some items disappear randomly or have a negative value.

Thank you for your reply ^^
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

This video really speaks to me...

Stream will be live shortly with a session of the interactive text adenture! Feel free to drop by!
I worked a lot more today and I am thinking about Youtube videos to make to my channel, but I am still looking for some content :D

But I am happy to be back at work :D
Update... no scam calls all day. I think they learned their lesson. And I'm working on a fake anti-piracy video, featuring a fan game I'm making in MV. If I had the permission to make the game a licensed game that I could sell (rather than having it totally free like fan games are required to be), I'd use a really cool anti-piracy screen...

Forum statistics

Threads
104,362
Messages
1,005,840
Members
135,878
Latest member
hjbkwjhef
Top