diff --git a/client/drops.lua b/client/drops.lua index 69a23de0d..298d75e7a 100644 --- a/client/drops.lua +++ b/client/drops.lua @@ -1,4 +1,4 @@ -local holdingDrop = false +holdingDrop = false local bagObject = nil local heldDrop = nil CurrentDrop = nil @@ -7,24 +7,23 @@ CurrentDrop = nil function GetDrops() QBCore.Functions.TriggerCallback('qb-inventory:server:GetCurrentDrops', function(drops) - if drops then - for k, v in pairs(drops) do - local bag = NetworkGetEntityFromNetworkId(v.entityId) - if DoesEntityExist(bag) then - exports['qb-target']:AddTargetEntity(bag, { - options = { - { - icon = 'fas fa-backpack', - label = Lang:t('menu.o_bag'), - action = function() - TriggerServerEvent('qb-inventory:server:openDrop', k) - CurrentDrop = dropId - end, - }, + if not drops then return end + for k, v in pairs(drops) do + local bag = NetworkGetEntityFromNetworkId(v.entityId) + if DoesEntityExist(bag) then + exports['qb-target']:AddTargetEntity(bag, { + options = { + { + icon = 'fas fa-backpack', + label = Lang:t('menu.o_bag'), + action = function() + TriggerServerEvent('qb-inventory:server:openDrop', k) + CurrentDrop = k + end, }, - distance = 2.5, - }) - end + }, + distance = 2.5, + }) end end end) @@ -59,7 +58,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId) label = 'Pick up bag', action = function() if IsPedArmed(PlayerPedId(), 4) then - return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500) + return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500) end if holdingDrop then return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500) diff --git a/client/main.lua b/client/main.lua index 161ecd7b5..5d675ffa7 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,4 +1,5 @@ QBCore = exports['qb-core']:GetCoreObject() +PlayerData = nil local hotbarShown = false -- Handlers diff --git a/html/app.js b/html/app.js index e0d280197..f86977afc 100644 --- a/html/app.js +++ b/html/app.js @@ -482,7 +482,7 @@ const InventoryContainer = Vue.createApp({ targetInventory[targetSlotNumber] = sourceItem; sourceInventory[this.currentlyDraggingSlot].slot = this.currentlyDraggingSlot; targetInventory[targetSlotNumber].slot = targetSlotNumber; - this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, amountToTransfer, targetItem.amount); + this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, sourceItem.amount, targetItem.amount); } } else { sourceItem.amount -= amountToTransfer; @@ -589,6 +589,7 @@ const InventoryContainer = Vue.createApp({ }); if (response.data) { + delete this.playerInventory[playerItemKey]; this.otherInventory[1] = newItem; this.otherInventoryName = response.data; this.otherInventoryLabel = response.data; @@ -698,12 +699,14 @@ const InventoryContainer = Vue.createApp({ } try { - await axios.post("https://qb-inventory/GiveItem", { + const response = await axios.post("https://qb-inventory/GiveItem", { item: selectedItem, amount: amountToGive, slot: selectedItem.slot, info: selectedItem.info, }); + if (!response.data) return; + this.playerInventory[selectedItem.slot].amount -= amountToGive; if (this.playerInventory[selectedItem.slot].amount === 0) { delete this.playerInventory[selectedItem.slot]; diff --git a/server/functions.lua b/server/functions.lua index 7c5b9743b..1b2244f39 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -460,6 +460,18 @@ end exports('OpenInventoryById', OpenInventoryById) +-- Clears a given stash of all items inside +--- @param identifier string +function ClearStash(identifier) + if not identifier then return end + local inventory = Inventories[identifier] + if not inventory then return end + inventory.items = {} + MySQL.prepare('UPDATE inventories SET items = ? WHERE identifier = ?', { json.encode(inventory.items), identifier }) +end + +exports('ClearStash', ClearStash) + --- @param shopData table The data of the shop to create. function CreateShop(shopData) if shopData.name then diff --git a/server/main.lua b/server/main.lua index 6aff6530f..3bfa405f1 100644 --- a/server/main.lua +++ b/server/main.lua @@ -294,11 +294,18 @@ QBCore.Functions.CreateCallback('qb-inventory:server:createDrop', function(sourc local bag = CreateObjectNoOffset(Config.ItemDropObject, playerCoords.x + 0.5, playerCoords.y + 0.5, playerCoords.z, true, true, false) local dropId = NetworkGetNetworkIdFromEntity(bag) local newDropId = 'drop-' .. dropId + local itemsTable = setmetatable({ item }, { + __len = function(t) + local length = 0 + for _ in pairs(t) do length += 1 end + return length + end + }) if not Drops[newDropId] then Drops[newDropId] = { name = newDropId, label = 'Drop', - items = { item }, + items = itemsTable, entityId = dropId, createdTime = os.time(), coords = playerCoords, @@ -488,9 +495,12 @@ RegisterNetEvent('qb-inventory:server:SetInventoryData', function(fromInventory, end else if toItem then - if RemoveItem(fromId, fromItem.name, fromAmount, fromSlot, 'swapped item') and RemoveItem(toId, toItem.name, toAmount, toSlot, 'swapped item') then - AddItem(toId, fromItem.name, fromAmount, toSlot, fromItem.info, 'swapped item') - AddItem(fromId, toItem.name, toAmount, fromSlot, toItem.info, 'swapped item') + 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') end else if RemoveItem(fromId, fromItem.name, toAmount, fromSlot, 'moved item') then