Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
adhershmnair authored Sep 7, 2024
2 parents 474d5ea + f31e85a commit be84353
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
37 changes: 18 additions & 19 deletions client/drops.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local holdingDrop = false
holdingDrop = false
local bagObject = nil
local heldDrop = nil
CurrentDrop = nil
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
QBCore = exports['qb-core']:GetCoreObject()
PlayerData = nil
local hotbarShown = false

-- Handlers
Expand Down
7 changes: 5 additions & 2 deletions html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 12 additions & 0 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be84353

Please sign in to comment.