> For the complete documentation index, see [llms.txt](https://devix.gitbook.io/devix/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devix.gitbook.io/devix/devix-inventory/installation/qbox_core/qbox-item-sync.md).

# QBox Item Sync

## What it does

* Reads the item list from **devix-inventory** (`GetItemList()`).
* Fills **qbShared.Items** (or your shared item table) in the format QBox/QB scripts expect.
* When devix-inventory restarts, the list is reloaded automatically.

So any script that uses `qbShared.Items` sees the same items as in your inventory.

***

## When to use it

* You use **QBox** (or QB Core) and **devix-inventory**.
* Your scripts read from **qbShared.Items** (or `QBCore.Shared.Items`) and you want that list to come from devix-inventory.
* You prefer a **single copy-paste** solution without editing other files.

***

## How to use

{% stepper %}
{% step %}
Put the code below in the right place in your QBox/shared setup (e.g. in the file that defines `qbShared` or your bridge `shared` module).
{% endstep %}

{% step %}
Ensure **devix-inventory** starts before this code runs (e.g. in `server.cfg`: `ensure devix-inventory` before the resource that loads this).
{% endstep %}

{% step %}
Restart the resource (or server). You should see in the server console:\
`[bridge/qb] Loaded X items into qbShared.Items from devix-inventory.`
{% endstep %}
{% endstepper %}

***

## Code (copy-paste)

qbx\_core/bridge/qb/shared/main.lua

```lua
local qbShared = require 'shared.main'

qbShared.Items = {}
local function fillItemsFromDevix()
    if GetResourceState('devix-inventory') ~= 'started' then return end
    local ok, list = pcall(function() return exports['devix-inventory']:GetItemList() end)
    if not ok or type(list) ~= 'table' then return end
    for name, data in pairs(list) do
        if name and data and type(data) == 'table' then
            local n = (data.name or name):lower()
            qbShared.Items[n] = {
                name = data.name or name,
                label = data.label or name,
                weight = data.weight or 0,
                type = data.type or 'item',
                image = data.image or (data.name or name) .. '.png',
                unique = data.unique or false,
                useable = data.useable ~= false,
                shouldClose = true,
                combinable = nil,
                description = data.description or nil
            }
        end
    end
end
CreateThread(function()
    while GetResourceState('devix-inventory') ~= 'started' do Wait(500) end
    fillItemsFromDevix()
end)
AddEventHandler('onResourceStart', function(resourceName)
    if resourceName == 'devix-inventory' then
        Wait(500)
        fillItemsFromDevix()
    end
end)

local starterItems = require 'config.shared'.starterItems
---@deprecated use starterItems in config/shared.lua
qbShared.StarterItems = {}

if type(starterItems) == 'table' then
    for i = 1, #starterItems do
        local item = starterItems[i]

        ---@diagnostic disable-next-line: deprecated
        qbShared.StarterItems[item.name] = {
            amount = item.amount,
            item = item.name,
        }
    end
end

---@deprecated use lib.math.groupdigits from ox_lib
qbShared.CommaValue = lib.math.groupdigits

---@deprecated use lib.string.random from ox_lib
qbShared.RandomStr = function(length)
    if length <= 0 then return '' end
    local pattern = math.random(2) == 1 and 'a' or 'A'

    ---@diagnostic disable-next-line: deprecated
    return qbShared.RandomStr(length - 1) .. lib.string.random(pattern)
end

---@deprecated use lib.string.random from ox_lib
qbShared.RandomInt = function(length)
    if length <= 0 then return '' end

    ---@diagnostic disable-next-line: deprecated
    return qbShared.RandomInt(length - 1) .. lib.string.random('1')
end

---@deprecated use string.strsplit with CfxLua 5.4
qbShared.SplitStr = function(str, delimiter)
    local result = table.pack(string.strsplit(delimiter, str))
    result.n = nil
    return result
end

---@deprecated use qbx.string.trim from modules/lib.lua
qbShared.Trim = function(str)
    if not str then return nil end
    return qbx.string.trim(str)
end

---@deprecated use qbx.string.capitalize from modules/lib.lua
qbShared.FirstToUpper = function(str)
    if not str then return nil end
    return qbx.string.capitalize(str)
end

---@deprecated use qbx.math.round from modules/lib.lua
qbShared.Round = qbx.math.round

---@deprecated use qbx.setVehicleExtra from modules/lib.lua
qbShared.ChangeVehicleExtra = qbx.setVehicleExtras

---@deprecated use qbx.setVehicleExtra from modules/lib.lua
qbShared.SetDefaultVehicleExtras = qbx.setVehicleExtras

---@deprecated use qbx.armsWithoutGloves.male from modules/lib.lua
qbShared.MaleNoGloves = qbx.armsWithoutGloves.male

---@deprecated use qbx.armsWithoutGloves.female from modules/lib.lua
qbShared.FemaleNoGloves = qbx.armsWithoutGloves.female

return qbShared
```

***

## Summary

| What        | Detail                                          |
| ----------- | ----------------------------------------------- |
| **Purpose** | Sync devix-inventory item list → qbShared.Items |
| **For**     | QBox / QB Core + devix-inventory                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://devix.gitbook.io/devix/devix-inventory/installation/qbox_core/qbox-item-sync.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
