How do I use item restrictions to force drop an item + its corresponding ammo?

airoll

Member
Hello, I want to implement an inventory where the character can hold a max of two unique weapons. The inventory should respect the following behavior:

  1. If the character already has that weapon in the inventory, it should pick up the ammo but not the weapon.
    Am I supposed to use a Group Item Restriction to solve this problem using Reject Incoming Item as the Overflow Action?
  2. If the character has two weapons, and a new weapon is picked up, then the currently equipped weapon should be removed from the inventory and dropped, alongside its corresponding ammo.
    Do I need to write a custom Item Action to make sure that I drop the corresponding ammo, and then create a ItemActionSet and CategoryItemActionSet, and then assign that to the Forced Remove Item Actions?
 
In my dev project I've been working on improving the overflow action system by incorporating it directly inside the base ItemCollection class. But it is not ready for release yet.

I would highly advise against using the Overflow action of the Group Item Restriction... it was a flawed design where I was rejecting items within the "CanAdd" function, which rejected items when I was just checking whether they should be adedd and not just when they were actually added. There should be a warning saying that GroupItemRestriction overdflow is deprecated if you are using overflow actions.

In the latest updat 1.1.8 I added a new ItemCollection which may help. It is called an ItemTransactionCollection. Used as the Main ItemCollection you can make all pickups go through it one by one and it can send it to other ItemCollection if the item passes the restrictions. If it doesn't then you can listen to the rejected event or use the rejected Item Action, whichever suits you better. The event is called "c_Inventory_OnRejected_ItemInfo" don't forget you can find all events in the EventNames.cs file.

For the restriction you could write a custom one, that will give you the most control. You can make it a Monobehavior or make it a simple class and add it through a ItemRestrctionSetObject

So to answer your questions:

1) If you want the weapon to stay on the floor if it is the same weapon as a one you have, I'm afraid you will need to write a custom pickup. Currently all the pickups content gets added to the character and then the pickup disappears. So another solution would simply be to drop the weapon after picking it up using th rejected action.

2) You can use the techniques I mentioned above to know what Item is being rejected. So inside your custom rejcted action you could remove/drop the previous weapon/ammo and try to add the rejected item again.

Hopefully that makes sense.
I would really like to make the overflow/rejected action system a lot easier to use in the next update. If you have some feedback/requests to take into account do let me know.
 
Hi @Sangemdoko thank you for the helpful answer. I have almost gotten things setup with using the Main collection as a ItemTransactionCollection. Note I am using UCC + UIS + UCC/UIS Integration.

In my PickupItem ability (custom), I move all items from an InventoryPickup to the Main collection. This then sends my weapon to the Weapons ItemCollection, which triggers OnAddItemToInventory(...) (which listens to EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack) in BridgeEquippableProcessing and creates a character item for the weapon.

However, I also want to use EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack in my PickupItem ability so that once an item has been moved to the equippable collection, it equips that item. So I implemented a custom event listener OnInventoryAddItem(...), but what I realized is that I end up having a race condition. BridgeEquippableProcessing.OnAddItemToInventory(...) gets called 2nd, which means that my PickupItem.OnInventoryAddItem(...) fails because there is no character item that is created for the inventory item. If I explicitly call BridgeEquippableProcessing.OnItemAddedToEquippable(...) from my PickupItem.OnInventoryAddItem(...), then the equip works, but now I've created a duplicate character item.

Any ideas on how to address this?
 
I'm trying to set up a similar two weapon system that swaps the active equipped weapon with a weapon pickup.
I have the Main ItemTransactionCollection set up to send weapons to the weapon ItemSlotCollection with two slots.
With new item priority true, the 2nd slot in the weapons ItemSlotCollection is always replaced by the incoming weapon rather than the equipped Slot 0 weapon, and isn't dropped/doesn't spawn a dropPrefab.

Any advice on how to get this working?
 
In the next update I will add a very easy option to drop items when they overflow from the inventory... Although I'm not sure it will work for your use case, I'll look into it in more detail.

That being said for specific use cases like those my advice is to create a custom ItemCollection that inherits the ItemTransactionCollection. This way you can have complete control on how the items are added and what gets removed and how.
 
Top