# Inventory

### server/custom/inventory

{% tabs %}
{% tab title="Default" %}

```lua
Config.Inventory = 'default'              -- default, ox_inventory, axr_inventory, qs-inventory or custom
```

```lua
if Config.Inventory ~= 'default' then
    return
end

local ESX, QBCore
if Config.Framework == 'qb-core' then
    QBCore = exports['qb-core']:GetCoreObject()

    exports['qb-core']:AddItem(Config.Item.Name, {
        name = Config.Item.Name,
        label = Config.Item.Label,
        weight = 10,
        type = 'item',
        image = 'dark_tablet.png',
        unique = false,
        useable = true,
        shouldClose = true,
        combinable = nil,
        description = Config.Item.Description
    })
elseif Config.Framework == 'esx' then
    ESX = exports['es_extended']:getSharedObject()
end

function CreateItem(name, callback)
    if Config.Framework == 'qb-core' then
        QBCore.Functions.CreateUseableItem(name, function(source)
            local identifier = Framework.GetPlayerIdentifier(source)
            callback(identifier)
        end)
    elseif Config.Framework == 'esx' then
        ESX.RegisterUsableItem(name, callback)
    elseif Config.Framework == 'vrp' then
        vRP.defInventoryItem({ name, 'Dark Tablet', 'Dark tablet for illegal activities', function()
            local choices = {}

            choices['Use'] = function(player, choice)
                local user_id = vRP.getUserId({ player })

                if user_id then
                    callback(user_id)
                end
            end

            return choices
        end, 0.01 })
    end
end

function HasItem(identifier, item, amount)
    amount = tonumber(amount) or 1

    if Config.Framework == 'qb-core' then
        local source = QBCore.Functions.GetPlayerByCitizenId(identifier).PlayerData.source
        local items = exports['qb-inventory']:GetItemsByName(source, item)
        return #items >= amount
    elseif Config.Framework == 'esx' then
        local player = ESX.GetPlayerFromIdentifier(identifier)
        local items = player.getInventoryItem(item).count
        return items >= amount
    elseif Config.Framework == 'vrp' then
        local items = vRP.getInventoryItemAmount({ identifier, item })
        return items >= amount
    end
end

function GiveItem(identifier, item, amount)
    if Config.Framework == 'qb-core' then
        local source = QBCore.Functions.GetPlayerByCitizenId(identifier).PlayerData.source
        exports['qb-inventory']:AddItem(source, item, amount)
    elseif Config.Framework == 'esx' then
        local player = ESX.GetPlayerFromIdentifier(identifier)
        player.addInventoryItem(item, amount)
    elseif Config.Framework == 'vrp' then
        vRP.giveInventoryItem({ identifier, item, amount, true })
    end
end
```

{% endtab %}

{% tab title="ox\_inventory" %}

```lua
Config.Framework = 'ox_inventory' -- auto/qb-core/qbox/esx/vrp/standalone
```

```lua
if Config.Inventory ~= 'ox_inventory' then
    return
end

-- Add this in @ox_inventory/data/items.lua
-- ['dark_tablet'] = {
--     label = 'Mobile Data Terminal',
--     weight = 100,
--     stack = false,
--     close = true,
--     allowArmed = false,
--     consume = 0,
--     client = { event = 'gang-activities:openMenu', image = 'dark_tablet.png' },
--     description = 'Dark tablet for illegal activities'
-- }

function CreateItem(name, callback)
    -- This inventory doesn't require this function
end

function HasItem(identifier, item, amount)
    amount = tonumber(amount) or 1
    local source = Framework.GetSourceFromIdentifier(identifier)
    local data = exports['ox_inventory']:GetItem(source, item, nil, true)
    return data.count >= amount
end

function GiveItem(identifier, item, amount)
    local source = Framework.GetSourceFromIdentifier(identifier)
    exports['ox_inventory']:AddItem(source, item, amount)
end
```

{% endtab %}

{% tab title="qs-inventory" %}

```lua
Config.Framework = 'qs-inventory' -- auto/qb-core/qbox/esx/vrp/standalone
```

```lua
if Config.Inventory ~= 'qs-inventory' then
    return
end

function CreateItem(name, callback)
    exports['qs-inventory']:CreateUsableItem(name, function(source, item)
        local identifier = Framework.GetPlayerIdentifier(source)
        callback(identifier)
    end)
end

function HasItem(identifier, item, amount)
    amount = tonumber(amount) or 1

    local source = Framework.GetSourceFromIdentifier(identifier)
    local totalAmount = exports['qs-inventory']:GetItemTotalAmount(source, item)

    return totalAmount >= amount
end

function GiveItem(identifier, item, amount)
    local source = Framework.GetSourceFromIdentifier(identifier)
    exports['qs-inventory']:AddItem(source, item, amount)
end
```

{% endtab %}

{% tab title="axr\_inventory" %}

```lua
Config.Framework = 'axr_inventory' -- auto/qb-core/qbox/esx/vrp/standalone
```

```lua
if Config.Inventory ~= 'axr_inventory' then
    return
end

-- This inventory is a custom script made by our developer
-- https://axero.tebex.io/package/6459587

function CreateItem(name, callback)
    exports['axr_inventory']:createItem(name, 'Dark Tablet', 'Dark tablet for illegal activities', 0.01, 'all', function(identifier)
        callback(identifier)
    end)
end

function HasItem(identifier, item, amount)
    amount = tonumber(amount) or 1
    local items = exports['axr_inventory']:getPlayerItemAmount(identifier, item)
    return items >= amount
end

function GiveItem(identifier, item, amount)
    exports['axr_inventory']:givePlayerItem(identifier, item, amount, true)
end
```

{% endtab %}

{% tab title="custom" %}

```lua
Config.Framework = 'custom' -- auto/qb-core/qbox/esx/vrp/standalone
```

```lua
if Config.Inventory ~= 'custom' then
    return
end

---Creates the item
---@param name string
---@param callback fun(identifier: string)
function CreateItem(name, callback)
    -- register the item as useable
end

---Has the item in inventory?
---@param identifier string|number Citizen id (qb-core, qbox), License (esx), numerical id (vrp)
---@param item string Item name
---@param amount number?
---@return boolean
function HasItem(identifier, item, amount)
    -- implement your logic here
    return true
end

---Gives an item to a player
---@param identifier string|number Citizen id (qb-core, qbox), License (esx), numerical id (vrp)
---@param item string Item name
---@param amount number How many items should be added?
function GiveItem(identifier, item, amount)
    -- add the item to the player
end
```

{% endtab %}
{% endtabs %}
