Instance Inventory Issue

I've been tinkering away at a project that borrows a lot of elements from the classic Resident Evil games - specifically a limited inventory. I've been using TheoAllen's script to handle this. Alongside the limited inventory I've also utilised Hime's Instance Items Script and Selchar's Weapon Durability script to imitate something similar to having limited weapon uses/ammo; to add some tension and decision making for the player.
Unfortunately, I've hit a snag trying to get the Limited Inventory script to play nicely with the Instance Items: dropping a weapon (as handled by the Limited Inventory script) does not work - the weapon remains in the player's inventory (sort of? you can't drop it again, but you can still find it in your inventory and equip it).
I also have Storage Boxes by IMP1 which highlight a similar issue, with Instanced weapons being duplicated when placed in storage - though I was able to edit this script to handle instanced items and the duplication glitch only occurred after I placed the Limited Inventory script into the project. :c
The issue seems to be that whenever Theo's Limited Inventory script tries to remove an item from the inventory it's directed to the template item rather than the instance - but I can't quite figure out where exactly this happens and how to remedy it. Any edits I've made have been unsuccessful.
I've tried placing each script in different positions in the list; and if Theo's script is located anywhere underneath Hime's suddenly weapons don't even show up in the inventory at all. Is this a clue?

Any help/direction on how to fix this would be appreciated. Ultimately the limited inventory is more important and if I have to drop the weapon durability I'm sure I can think of some other gameplay quirk, but I had a lot of fun ideas related to the durability that I'm not ready to throw away just yet ;~;

I've attached a demo which should hopefully demonstrate the issue more clearly than my word-soup.

Thanks for reading!
I have moved this thread to RGSSx Script Support.
Hey,

You could try using this:
Spoiler
Code:
# ============================================================================
#  Compatibility Patch for TheoAllens Limited Inventory / Himes Instance Items
# ----------------------------------------------------------------------------
# The scripts should be in the following order:
# - TheoAllens Limited Inventory
# - Himes Instance Items
# - This Script
# (Otherwise calling Game_Party#gain_item might cause an infinite recursion)
# ============================================================================

class Game_Party
 
  # This iteration of Game_Party#gain_item supports instance items, but does
  # not yet include a maximum amount for them:
  alias_method(:gain_item_ILC_beforeInstanceItemLimit, :gain_item)
 
  def gain_item(item, amount, include_equip = false)
    if !Theo::LimInv::ForceGain && instance_enabled?(item)
      amount = [amount, [inv_max_item(item), 0].max].min
    end
    gain_item_ILC_beforeInstanceItemLimit(item, amount, include_equip)
  end
 
  alias_method(:force_gain_item_ILC_beforeInstanceItems, :force_gain_item)
  def force_gain_item(item, amount, include_equip = false)
    if instance_enabled?(item)
      # Ignore the above added inventory capacity check (forced):
      gain_item_ILC_beforeInstanceItemLimit(item, amount, include_equip)
    else
      force_gain_item_ILC_beforeInstanceItems(item, amount, include_equip)
    end
  end
end
At least the problem seems to be that both scripts clash over how items are gained/lost by the party. The Limited Inventory script introduces its own "force_gain_item" method to bypass the normal inventory limit check, but this also bypasses some of the changes made by the Instance Items script.
Hey,

You could try using this:
Spoiler
Code:
# ============================================================================
#  Compatibility Patch for TheoAllens Limited Inventory / Himes Instance Items
# ----------------------------------------------------------------------------
# The scripts should be in the following order:
# - TheoAllens Limited Inventory
# - Himes Instance Items
# - This Script
# (Otherwise calling Game_Party#gain_item might cause an infinite recursion)
# ============================================================================

class Game_Party
 
  alias_method(:force_gain_item_ILC_TLIHIImerge, :force_gain_item)
  def force_gain_item(item, amount, include_equip = false)
    if instance_enabled?(item)
      gain_item(item, amount, include_equip)
    else
      force_gain_item_ILC_TLIHIImerge(item, amount, include_equip)
    end
  end
end
At least the problem seems to be that both scripts clash over how items are gained/lost by the party. The Limited Inventory script introduces its own "force_gain_item" method to bypass the normal inventory limit check, but this also bypasses some of the changes made by the Instance Items script.
That works a treat - thank you so much! I appreciate the explanation of where the problem was stemming from; that and the code snippet have given me a better understanding of Ruby in general. Thanks again!
One thing I forgot yesterday is that currently adding instanced items is not restricted by inventory capacity (the Instanced Items script assumes any unique item fits at least once in the inventory).

This should not be consequencial if you have the "ForceGain" option in the Limited Inventory script enabled anyways (which you currently seem to have), but I amended the script above just to be sure.

Glad to see it helped.
One thing I forgot yesterday is that currently adding instanced items is not restricted by inventory capacity (the Instanced Items script assumes any unique item fits at least once in the inventory).

This should not be consequencial if you have the "ForceGain" option in the Limited Inventory script enabled anyways (which you currently seem to have), but I amended the script above just to be sure.

Glad to see it helped.
Thanks again! I've copied over the amended script to be safe, though I believe I've mostly avoided unwanted item adding through conditional branches checking against $game_party.total_inv_size

Still, this has prompted me to do some more testing to make sure everything works - and I've found (and fixed... I hope) some other oddities that all of these scripts have sprung. So thanks for that too! I appreciate all of the help!

Original thread: https://forums.rpgmakerweb.com/threads/instance-inventory-issue.159451/