Items go into backpack on pickupSolved

Automatically place items in backpack on pick up and when placing items in backpack automatically place in the page that has the item rather than going into the open one

I will look into this further, but so far, it seems very tricky to implement properly.

First off, I'm not aware of a proper way to determine that something was "picked up". Most likely, we would have to just hook whenever an item is added to the player inventory (both the main or belt containers). It's important to watch the belt container since some items automatically go to the belt when picked up. To optimize performance, I would avoid using any global hooks, and instead use the onItemAddedRemoved delegates directly on the main and belt containers.

Issues I have thought of so far:

  • When moving an item from one inventory container to another (e.g., main -> belt, belt -> main, clothing -> main/belt), the item would be moved to the backpack.
    • To resolve, we could watch for items being removed from inventory containers in order to exempt them from being immediately moved to the backpack. Small performance cost here.
  • When moving an item from your backpack to your inventory, the item would be moved back to the backpack.
    • To resolve, we could watch for items being removed from the backpack in order to exempt them from being immediately moved to the backpack. Small performance cost here.
    • Issue: Split-dragging an item from the backpack to your inventory cannot be easily detected, so the item would be moved into the backpack anyway.
      • We could create an Oxide hook to detect this (e.g., OnItemSplitted to return the item that resulted from the split), but it would not be great for performance given that it would be a global hook.
      • We could try using the CanMoveItem hook to orchestrate the split, but it would bad for performance and significnatly increase likelihood of plugin conflicts.
  • When moving an inner backpack item to your inventory (e.g., an attachment inside a wearpon), the item would be moved to the backpack.
    • To resolve, we could watch for item removals in all items within the backpack. For example, when a weapon is added to the backpack, add a delegate to the weapon item's inventory. When the weapon is removed from the backpack, remove the delegate. This would need to be done recursively for deeply nested items. Unfortunately the logic here is a somewhat complex and it's easy for things to go wrong.
  • When initial items are given to a player after spawn, those items may be moved to the backpack.
    • To resolve, we could possibly ignore item events while the player is asleep or loading, but we might need to use hooks to track that state properly for edge cases. For example, loadout/auto-kit plugins or Restore Upon Death may add the items on a delay after the player has woken up.
  • When fetching an item with the backpack.fetch command, if the item is coming from a virtual page (a page that doesn't have a physical container yet, due to not having been accessed by a player), the above mitigation of tracking the last item wouldn't detect the item.
    • To resolve, we could add logic to virtual ontainers to record the item that was removed/created on-demand.


Merged post

This is now available in the v3.10 beta.

https://umod.org/community/backpacks/46426-backpacks-beta-3100

Locked automatically