qbcore-framework / qb-inventory

Slot Based Inventory System Used With QB-Core :school_satchel:
GNU General Public License v3.0
50 stars 379 forks source link

[BUG] Transfering items with bigger weight then the inventories can hold, makes them get deleted #589

Open RKDimitrov opened 1 week ago

RKDimitrov commented 1 week ago

Summary

Items get deleted when trying to transfer them

Reproduction

When a player tries to transfer items with bigger weight than the inventory can hold, makes the items get deleted and in the console is printed "AddItem: Not enough weight available'" For example, when a player tries to transfer an item weighted 100kg into a inventory with 10kg, the item gets deleted from both inventories.

Expected behavior

Trying to transfer items into a smaller weight inventory, must leave them in the inventory they are already in. For example if you are trying to transfer item with 100kg into a 10kg inventory, the item must stay in the inventory its already in.

Actual behavior

Items get deleted when a player tries to transfer big load of items into another inventory with small weight capacity.

Additional context

No response

Last Updated

Last week

Custom Resources

No

Resource Rename

No

GHOSTLYxKNIGHT commented 5 days ago

im having this issue aswell

Xergxes7 commented 4 days ago

I am running with all the latest community provided patches and get this during item swapping event when a user drags an item from their inventory over a stack of weight larger than inventory capacity in a trunk/stash.

I have implemented a workaround in server/main.lua - This will NOT work if you have not implemented all the community provided workarounds from the issues raised to solve all the preceding bugs. This also only addresses item swapping

At qb-inventory:server:SetInventoryData (added as part of resolution from: https://github.com/qbcore-framework/qb-inventory/issues/580)

Under if RemoveItem(fromId, fromItem.name, fromItemAmount, fromSlot, 'swapped item') and RemoveItem(toId, toItem.name, toItemAmount, toSlot, 'swapped item') then

I added these two exception checks(Inventory is closed to ensure items are set back as this is technically a front end bug in app.js but this was the fastest fix for a live server I could get in): if not CanAddItem(source, fromItem.name, fromItemAmount) then TriggerClientEvent('QBCore:Notify', source, 'Cannot transfer item, please re-open Inventory', 'error') AddItem(toId, toItem.name, toItemAmount, toSlot, toItem.info, 'swapped item') AddItem(fromId, fromItem.name, fromItemAmount, fromSlot, fromItem.info, 'swapped item') CloseInventory(source) return end if not CanAddItem(source, toItem.name, toItemAmount) then TriggerClientEvent('QBCore:Notify', source, 'Cannot transfer item, please re-open Inventory', 'error') AddItem(toId, toItem.name, toItemAmount, toSlot, toItem.info, 'swapped item') AddItem(fromId, fromItem.name, fromItemAmount, fromSlot, fromItem.info, 'swapped item') CloseInventory(source) return end

This is added before lines:

AddItem(toId, fromItem.name, fromItemAmount, toSlot, fromItem.info, 'swapped item') AddItem(fromId, toItem.name, toItemAmount, fromSlot, toItem.info, 'swapped item') end

GHOSTLYxKNIGHT commented 4 days ago

Regrettably this did not fix my issue.

Zack3267 commented 3 days ago

When I tried this fix I could not use admin or wasabi to search a players inventory. And still did not fix the issue sadly to say.