diff --git a/html/app.js b/html/app.js
index 1b885987..3fbd2a9f 100644
--- a/html/app.js
+++ b/html/app.js
@@ -467,6 +467,18 @@ const InventoryContainer = Vue.createApp({
const targetItem = targetInventory[targetSlotNumber];
if (targetItem) {
+ if (this.dragStartInventoryType == "other") {
+ const totalWeightAfterTransfer = (this.otherInventoryWeight-sourceItem.weight * amountToTransfer) + targetItem.weight * targetItem.amount;
+ if (totalWeightAfterTransfer > this.otherInventoryMaxWeight) {
+ throw new Error("Insufficient weight capacity in target inventory");
+ }
+ }
+ else if (this.dragStartInventoryType == "player") {
+ const totalWeightAfterTransfer = (this.playerWeight-sourceItem.weight * amountToTransfer) + targetItem.weight * targetItem.amount;
+ if (totalWeightAfterTransfer > this.maxWeight) {
+ throw new Error("Insufficient weight capacity in player inventory");
+ }
+ }
if (sourceItem.name === targetItem.name && targetItem.unique) {
this.inventoryError(this.currentlyDraggingSlot);
return;
diff --git a/server/functions.lua b/server/functions.lua
index 1eb590e5..90f8aaad 100644
--- a/server/functions.lua
+++ b/server/functions.lua
@@ -371,6 +371,9 @@ function CanAddItem(identifier, item, amount)
elseif Inventories[identifier] then
inventory = Inventories[identifier]
items = Inventories[identifier].items
+ elseif Drops[identifier] then
+ inventory = Drops[identifier]
+ items = Drops[identifier].items
end
if not inventory then
diff --git a/server/main.lua b/server/main.lua
index c6007722..e316c096 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -509,7 +509,7 @@ RegisterNetEvent('qb-inventory:server:SetInventoryData', function(fromInventory,
local toId = getIdentifier(toInventory, src)
if toItem and fromItem.name == toItem.name then
- if RemoveItem(fromId, fromItem.name, toAmount, fromSlot, 'stacked item') then
+ if CanAddItem(toId, toItem.name, toAmount) and RemoveItem(fromId, fromItem.name, toAmount, fromSlot, 'stacked item') then
AddItem(toId, toItem.name, toAmount, toSlot, toItem.info, 'stacked item')
end
elseif not toItem and toAmount < fromAmount then
@@ -521,9 +521,27 @@ RegisterNetEvent('qb-inventory:server:SetInventoryData', function(fromInventory,
local fromItemAmount = fromItem.amount
local toItemAmount = toItem.amount
- if RemoveItem(fromId, fromItem.name, fromItemAmount, fromSlot, 'swapped item') and RemoveItem(toId, toItem.name, toItemAmount, toSlot, 'swapped item') then
- AddItem(toId, fromItem.name, fromItemAmount, toSlot, fromItem.info, 'swapped item')
- AddItem(fromId, toItem.name, toItemAmount, fromSlot, toItem.info, 'swapped item')
+ local didRemoveFromOurInventory = RemoveItem(fromId, fromItem.name, fromItemAmount, fromSlot, 'swapped item')
+ local didRemoveFromTheirInventory = RemoveItem(toId, toItem.name, toItemAmount, toSlot, 'swapped item')
+
+ if didRemoveFromOurInventory and didRemoveFromTheirInventory then
+ local didAddToTheirInventory = AddItem(toId, fromItem.name, fromItemAmount, toSlot, fromItem.info, 'swapped item')
+ local didAddToOurInventory = AddItem(fromId, toItem.name, toItemAmount, fromSlot, toItem.info, 'swapped item')
+
+ local function refundBoth()
+ AddItem(fromId, fromItem.name, fromItemAmount, fromSlot, fromItem.info, 'refund swapped item due to error')
+ AddItem(toId, toItem.name, toItemAmount, toSlot, toItem.info, 'refund swapped item due to error')
+ end
+
+ if (not didAddToTheirInventory) and (not didAddToOurInventory) then
+ refundBoth()
+ elseif (not didAddToTheirInventory) and (didAddToOurInventory) then
+ RemoveItem(fromId, toItem.name, toItemAmount, fromSlot, 'remove item due to being refunded')
+ refundBoth()
+ elseif (not didAddToOurInventory) and (didAddToTheirInventory) then
+ RemoveItem(toId, fromItem.name, fromItemAmount, toSlot, 'remove item due to being refunded')
+ refundBoth()
+ end
end
else
if RemoveItem(fromId, fromItem.name, toAmount, fromSlot, 'moved item') then