qb-inventory
These modifications can only be made if you use the qb-inventory
Add the following to the end of the qb-inventory/server/main.lua
file
exports("GetStash", function(stashId)
return Stashes[stashId] or {
items = GetStashItems(stashId)
}
end)
exports('GetStashItems', GetStashItems)
RegisterServerEvent('qb-inventory:server:SaveStashItems', function(stashId, items)
MySQL.insert('INSERT INTO stashitems (stash, items) VALUES (@stash, @items) ON DUPLICATE KEY UPDATE items = @items', {
['@stash'] = stashId,
['@items'] = json.encode(items)
})
if Stashes[stashId] then
Stashes[stashId].items = items
end
end)
In the qb-inventory/server/functions.lua
file we will modify and add the following:
• The function InitializeInventory(inventoryId, data)
will be left as follows
local function InitializeInventory(inventoryId, data)
if Inventories[inventoryId] and Inventories[inventoryId].maxweight then return Inventories[inventoryId] end
Inventories[inventoryId] = {
items = {},
isOpen = false,
label = data and data.label or inventoryId,
maxweight = data and data.maxweight or Config.StashSize.maxweight,
slots = data and data.slots or Config.StashSize.slots
}
return Inventories[inventoryId]
end
• Below the function we export it by adding the following code
exports('InitializeInventory', InitializeInventory) -- exports['qb-inventory']:InitializeInventory(inventoryId, data)
• And finally we add this function and export it.
local function getItemCountByName(identifier, item)
if not Inventories[identifier] then return 0 end
local count = 0
for _, v in pairs(Inventories[identifier].items) do
if v and v.name == item then
count = count + v.amount
end
end
return count
end
exports('getItemCountByName', getItemCountByName) -- exports['qb-inventory']:getItemCountByName(identifier, item)
Last updated