Inventory

Follow this instructions only if you have one of the following inventories: qb-inventory, lj-inventory, ps-inventory

If using qb-inventory, open qb-inventory/fxmanifest.lua if the version is 2.0.0 or higher then jump straight to the end of this page and only add the WipeStash export.

The following steps are for qb-inventory old versions 1.x.x

  • Go to av_laptop/config/_inventory.lua and set

    Config.OldQBInventory = true
  • Go to inventory-folder/server/main.lua

  • Search the function SetItemData and replace it with:

local function SetItemData(source, itemName, key, val, slot)
	if not itemName or not key then return false end

	local Player = QBCore.Functions.GetPlayer(source)

	if not Player then return end
	local item = nil
	if slot then
		item = Player.PlayerData.items[slot]
	else
		item = GetItemByName(source, itemName)
	end
	if not item then return false end

	item[key] = val
	Player.PlayerData.items[item.slot] = item
	Player.Functions.SetPlayerData("items", Player.PlayerData.items)
	return true
end
  • Search the function RemoveFromStash and place the export at the end:

---Remove the item from the stash
---@param stashId string Stash id to remove the item from
---@param slot number Slot to remove the item from
---@param itemName string Name of the item to remove
---@param amount? number The amount to remove
local function RemoveFromStash(stashId, slot, itemName, amount)
	amount = tonumber(amount) or 1
	if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then
		if Stashes[stashId].items[slot].amount > amount then
			Stashes[stashId].items[slot].amount = Stashes[stashId].items[slot].amount - amount
		else
			Stashes[stashId].items[slot] = nil
		end
	else
		Stashes[stashId].items[slot] = nil
		if Stashes[stashId].items == nil then
			Stashes[stashId].items[slot] = nil
		end
	end
end
exports('RemoveFromStash', RemoveFromStash)
  • Search the function AddToStash and place the export at the end like this:

---Add items to a stash
---@param stashId string Stash id to save it to
---@param slot number Slot of the stash to save the item to
---@param otherslot number Slot of the stash to swap it to the item isn't unique
---@param itemName string The name of the item
---@param amount? number The amount of the item
---@param info? table The info of the item
local function AddToStash(stashId, slot, otherslot, itemName, amount, info)
    local slot = slot or 1
    amount = tonumber(amount) or 1
    local ItemData = SharedItems(itemName)
    if not ItemData then
        print("Item "..itemName.." doesn't exist")
        return
    end
    Stashes[stashId] = Stashes[stashId] or Stashes[stashId]
    Stashes[stashId]['items'] = Stashes[stashId]['items'] or {}
    Stashes[stashId].items[slot] = Stashes[stashId].items[slot] or {}
    
    if not ItemData.unique then
        if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then
            Stashes[stashId].items[slot].amount = Stashes[stashId].items[slot].amount + amount
        else
            local itemInfo = SharedItems(itemName:lower())
            Stashes[stashId].items[slot] = {
                name = itemInfo['name'],
                amount = amount,
                info = info or '',
                label = itemInfo['label'],
                description = itemInfo['description'] or '',
                weight = itemInfo['weight'],
                type = itemInfo['type'],
                unique = itemInfo['unique'],
                useable = itemInfo['useable'],
                image = itemInfo['image'],
                slot = slot,
            }
        end
    else
        if Stashes[stashId].items[slot] and Stashes[stashId].items[slot].name == itemName then
            local itemInfo = SharedItems(itemName:lower())
            Stashes[stashId].items[otherslot] = {
                name = itemInfo['name'],
                amount = amount,
                info = info or '',
                label = itemInfo['label'],
                description = itemInfo['description'] or '',
                weight = itemInfo['weight'],
                type = itemInfo['type'],
                unique = itemInfo['unique'],
                useable = itemInfo['useable'],
                image = itemInfo['image'],
                slot = otherslot,
            }
        else
            local itemInfo = SharedItems(itemName:lower())
            Stashes[stashId].items[slot] = {
                name = itemInfo['name'],
                amount = amount,
                info = info or '',
                label = itemInfo['label'],
                description = itemInfo['description'] or '',
                weight = itemInfo['weight'],
                type = itemInfo['type'],
                unique = itemInfo['unique'],
                useable = itemInfo['useable'],
                image = itemInfo['image'],
                slot = slot,
            }
        end
    end
end

exports('addStashItem', AddToStash) -- av-scripts export
  • Search the function addTrunkItems and replace it with:

function addTrunkItems(plate, items) -- av-scripts
	Trunks[plate] = {}
	Trunks[plate].label = "Trunk-"..plate
	Trunks[plate].items = items
end

exports('addTrunkItems', addTrunkItems)
  • Search the function GetStashItems and place the export like this:

---Get items in a stash
----@param stashId string The id of the stash to get
----@return table items
local function GetStashItems(stashId)
	local items = {}
	local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashId })
	if not result then return items end
	
	local stashItems = json.decode(result)
	if not stashItems then return items end
	
	for _, item in pairs(stashItems) do
		local itemInfo = QBCore.Shared.Items[item.name:lower()]
		if itemInfo then
			items[item.slot] = {
				name = itemInfo['name'],
				amount = tonumber(item.amount),
				info = item.info or '',
				label = itemInfo['label'],
				description = itemInfo['description'] or '',
				weight = itemInfo['weight'],
				type = itemInfo['type'],
				unique = itemInfo['unique'],
				useable = itemInfo['useable'],
				image = itemInfo['image'],
				slot = item.slot,
			}
		end
	end
	return items
end

exports("GetStashItems", GetStashItems) -- av-scripts export
  • Search for SaveStashItems function and add an export like this:

---Save the items in a stash
---@param stashId string The stash id to save the items from
---@param items table items to save
local function SaveStashItems(stashId, items)
	if Stashes[stashId].label == 'Stash-None' or not items then return end

	for _, item in pairs(items) do
		item.description = nil
	end

	MySQL.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
		['stash'] = stashId,
		['items'] = json.encode(items)
	})

	Stashes[stashId].isOpen = false
end

exports("SaveStashItems",SaveStashItems) -- av-scripts export
  • Search for the event inventory:server:SaveInventory and replace it with:

RegisterNetEvent('inventory:server:SaveInventory', function(type, id) -- av-scripts
	local src = source
	if type == 'trunk' then
		if IsVehicleOwned(id) then
			SaveOwnedVehicleItems(id, Trunks[id].items)
		else
			Trunks[id].isOpen = false
		end
	elseif type == 'glovebox' then
		if (IsVehicleOwned(id)) then
			SaveOwnedGloveboxItems(id, Gloveboxes[id].items)
		else
			Gloveboxes[id].isOpen = false
		end
	elseif type == 'stash' then
		SaveStashItems(id, Stashes[id].items)
	elseif type == 'drop' then
		if Drops[id] then
			Drops[id].isOpen = false
			if Drops[id].items == nil or next(Drops[id].items) == nil then
				Drops[id] = nil
				TriggerClientEvent('inventory:client:RemoveDropItem', -1, id)
			end
		end
	end
	TriggerEvent("av_scripts:inventorySaved",src,type,id)
end)
  • Search for the event inventory:server:OpenInventory and add the field newLabel like this:

-- Add the var newLabel inside function(name, id, other)
-- Replace secondInv.label = 'Stash-' .. id
-- with:
-- secondInv.label = newLabel or 'Stash-' .. id
RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other, newLabel) -- ADD IT HERE
	local src = source
	local ply = Player(src)
	local Player = QBCore.Functions.GetPlayer(src)
	if ply.state.inv_busy then
		return QBCore.Functions.Notify(src, Lang:t('notify.noaccess'), 'error')
	end
	if name and id then
		local secondInv = {}
		if name == 'stash' then
			if Stashes[id] then
				if Stashes[id].isOpen then
					local Target = QBCore.Functions.GetPlayer(Stashes[id].isOpen)
					if Target then
						TriggerClientEvent('inventory:client:CheckOpenState', Stashes[id].isOpen, name, id, Stashes[id].label)
					else
						Stashes[id].isOpen = false
					end
				end
			end
			local maxweight = 1000000
			local slots = 50
			if other then
				maxweight = other.maxweight or 1000000
				slots = other.slots or 50
			end
			secondInv.name = 'stash-' .. id
			secondInv.label = newLabel or 'Stash-' .. id -- REPLACE HERE
			
-- There's more code than this in your inventory
-- So please DON'T copy/paste any of this code to your inventory, just add the needed lines
  • Copy/paste this code at the end of the file:

-- av-scripts export:
function WipeStash(id) -- for old qb-inventory
	Stashes[id] = {}
	Stashes[id].items = {}
	SaveStashItems(id, Stashes[id].items)
end

exports("WipeStash", WipeStash)

This is for qb-inventory 2.0 or higher.

  • Go to qb-inventory/server/main.lua and replace function SetItemData with the following:

local function SetItemData(source, itemName, key, val, slot)
	if not itemName or not key then return false end
	local Player = QBCore.Functions.GetPlayer(source)
	if not Player then return end
	local item = nil
	if slot then
		item = Player.PlayerData.items[slot]
	else
		item = GetItemByName(source, itemName)
	end
	if not item then return false end
	item[key] = val
	Player.PlayerData.items[item.slot] = item
	Player.Functions.SetPlayerData("items", Player.PlayerData.items)
	return true
end
  • Add this export in qb-inventory/server/main.lua at the end of the file:

function WipeStash(identifier)
    if Inventories and Inventories[identifier] then
        Inventories[identifier]['items'] = {}
    end
    local exists = MySQL.single.await('SELECT `items` FROM `inventories` WHERE `identifier` = ?', {
        identifier
    })
    if exists and exists['items'] then
        local empty = {}
        MySQL.update.await('UPDATE `inventories` SET `items` = ? WHERE `identifier` = ?', {
            json.encode(empty), identifier
        })
    end
end

exports('WipeStash', WipeStash)

Last updated