# Inventory

<figure><img src="/files/Omoh4W8XgBlyNPNT1VbO" alt=""><figcaption><p>Inventory Opened</p></figcaption></figure>

:tada: Removal of ESX.CreateUseableItem and implement item usages inside the inventory using exports.

## Client Export

<pre class="language-lua"><code class="lang-lua"><strong>exports('bandage', function(data, slot)
</strong><strong>    local playerPed = PlayerPedId()
</strong>    local maxHealth = GetEntityMaxHealth(playerPed)
    local health = GetEntityHealth(playerPed)

    -- Does the ped need to heal? We can cancel the item from being used.
    if health &#x3C; maxHealth then
        -- Triggers internal-code to correctly use items.
        -- This adds security, removes the item on use, adds progressbar support, and is necessary for server callbacks.
        exports.ox_inventory:useItem(data, function(data)
            -- The server has verified the item can be used.
            if data then
                SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16)))
                lib.notify({description = 'You feel better already'})
            end
        end)
    else
        -- Don't use the item
        lib.notify({type = 'error', description = 'You don\'t need a bandage right now'})
    end
end)
</code></pre>

## Server Export

```lua
exports('bandage', function(event, item, inventory, slot, data)
    -- Player is attempting to use the item.
    if event == 'usingItem' then
        local playerPed = GetPlayerPed(inventory.id)
        local maxHealth = GetEntityMaxHealth(playerPed)
        local health = GetEntityHealth(playerPed)

        -- Check if the player needs to be healed.
        if health >= maxHealth then
            TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'error', description = 'You don\'t need a bandage right now'})

            -- Returning 'false' will prevent the item from being used
            return false
        end

        return
    end

    -- Player has finished using the item.
    if event == 'usedItem' then
        return TriggerClientEvent('ox_lib:notify', inventory.id, {description = 'You feel better already'})
    end

    -- Player is attempting to purchase the item.
    if event == 'buying' then
        return TriggerClientEvent('ox_lib:notify', inventory.id, {type = 'success', description = 'You bought a bandage'})
    end
end)
```

This utilizes the way ox inventory works within vESX after creating these exports either client or server side you can edit ox\_inventory/data/items.lua for example we are going to use "bandage" as the item to handle our export with

## Creating Items

```lua
['bandage'] = {
	label = 'Bandage',
	weight = 10,
	stack = true,
	close = true,
	allowArmed = false,
	consume = 0.25, -- Allows 4 times per item usage untill it gets removed
	description = 'Bandage for healing',
	client = {
		export = 'vesx_items.bandage',
	},
},
```


---

# Agent Instructions: 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:

```
GET https://high-development.gitbook.io/vesx-framework/use-cases/inventory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
