# Client Exports

## openInventory

<pre class="language-lua"><code class="lang-lua"><strong>---Lower y upper cases are sensitives
</strong>---@param invType string
---@param id string
---@param data? table
exports.origen_inventory:openInventory(invType, id, data?)
</code></pre>

*invType*: `string`

* `'player'`
* `'shop'`
* `'stash'`
* `'drop'`
* `'glovebox'`
* `'trunk'`

**Examples**

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

```lua
exports.origen_inventory:openInventory('player', 1)
```

{% endtab %}

{% tab title="Shop" %}

```lua
exports.origen_inventory:openInventory('shop', 'test')
```

{% endtab %}

{% tab title="Stash" %}

```lua
exports.origen_inventory:openInventory('stash', 'my-stash', { 
    label = 'My Stash' 
})

--- Or Simply
exports.origen_inventory:openInventory('stash', 'my-stash')
```

{% endtab %}

{% tab title="Trunk/Glove" %}

```lua
exports.origen_inventory:openInventory('trunk', 'my-stash', { 
    label = 'My Trunk' 
})

--- Or Simply
exports.origen_inventory:openInventory('glovebox', 'my-glove')
```

{% endtab %}
{% endtabs %}

## Search <a href="#search" id="search"></a>

{% hint style="info" %}
Please note that this export has been adapted for compatibility when migrating from other inventories.
{% endhint %}

Searches the inventory for an item, or list of items, result varying based on the first argument.

<pre class="language-lua"><code class="lang-lua"><strong>exports.origen_inventory:Search(search, item, metadata)
</strong></code></pre>

* search: `'slots'` or `'count'`
  * `'slots'` returns a table of slots where the item was found at.
  * `'count'` returns the count of the specified item in player's inventory. If searching for multiple items returns key-value pairs of itemName = count.
* item: `table` or `string`
  * Can be a single item name or array of item names.
* metadata?: `table` or `string`
  * If metadata is provided as a string it will search the item's `metadata.type` property.

### Slots <a href="#count" id="count"></a>

{% tabs %}
{% tab title="Single Item" %}

```lua
local water = exports.origen_inventory:Search('slots', 'water')
local count = 0
for _, v in pairs(water) do
    print(v.slot..' contains '..v.count..' water '..json.encode(v.metadata))
    count = count + v.count 
end
print('You have '..count..' water, Nice!')
```

{% endtab %}

{% tab title="Multiple Items" %}

```lua
local items = exports.origen_inventory:Search('slots', {'meat', 'skin'}, 'deer')
 
if items then
    for name, data in pairs(items) do
        local count = 0
 
        for _, v in pairs(data) do
            if v.slot then
                print(v.slot..' contains '..v.count..' '..name..' '..json.encode(v.metadata))
                count = count + v.count
            end
        end
 
        print('You have '..count..' '..name.. " Nice!")
    end
end
```

{% endtab %}
{% endtabs %}

### Count <a href="#slots" id="slots"></a>

{% tabs %}
{% tab title="Single Item" %}

```lua
local inventory = exports.origen_inventory:Search('count', {'meat', 'skin'}, {grade="1"})
 
if inventory then
    for name, count in pairs(inventory) do
        print('You have '..count..' '..name)
    end
end
```

{% endtab %}

{% tab title="Multiple Items" %}

```lua
local items = exports.origen_inventory:Search('slots', {'meat', 'skin'}, 'deer')
 
if items then
    for name, data in pairs(items) do
        local count = 0
 
        for _, v in pairs(data) do
            if v.slot then
                print(v.slot..' contains '..v.count..' '..name..' '..json.encode(v.metadata))
                count = count + v.count
            end
        end
 
        print('You have '..count..' '..name.. " Nice!")
    end
end
```

{% endtab %}
{% endtabs %}

## useSlot

```lua
---Use Inventory Slot
---@param slot number
---@return boolean
exports.origen_inventory:useSlot(slot)

-- Returns false if slot its not a number
-- Returns true if slot is number
```

## displayMetadata

```lua
--- Display item metadata
--- @param metadata table | string
--- @param value any
--- @return boolean
exports.origen_inventory.displayMetadata(metadata, value)
```

## Deprecated Exports

{% hint style="warning" %}

* These exports continue to function as long as they are on this list, please prioritize replacing with new exports.
* Support for these exports is a lower priority, you can request new exports on our support discord.
  {% endhint %}

### OnPlayerLoad

Force the player's boot and inventory systems.

```lua
exports.origen_inventory:OnPlayerLoad()
```

### Lock/Unlock Inventory

```lua
exports.origen_inventory:IsInventoryLocked() -- return boolean
exports.origen_inventory:LockInventory() -- return void
exports.origen_inventory:UnlockInventory() -- return void
exports.origen_inventory:ToggleInventoryAccess(lock --[[true/false]]) -- Lock / unlock inventory
```

### ToggleHotBar

```lua
exports.origen_inventory:ToggleHotBar(visible --[[true/false]])
```

### IsInventoryOpen

```lua
exports.origen_inventory:IsInventoryOpen() -- return boolean
```

### openInventory

Open a giving inventory

```lua
--- Lower y upper cases are sensitives (openInventory not equal to old OpenInventory exports)
exports.origen_inventory:openInventory(invType, id, data?)
```

* invType: `string`
  * `'player'`
  * `'shop'`
  * `'stash'`
  * `'drop'`
  * `'glovebox'`
  * `'trunk'`
* id: `number` or `string`
* data?: `table`

**Examples**

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

```lua
exports.origen_inventory:openInventory('player', 1)
```

{% endtab %}

{% tab title="Shop" %}

```lua
exports.origen_inventory:openInventory('shop', 'test')
```

{% endtab %}

{% tab title="Stash" %}

```lua
exports.origen_inventory:openInventory('stash', 'my-stash', { 
    label = 'My Stash' 
})

--- Or Simply
exports.origen_inventory:openInventory('stash', 'my-stash')
```

{% endtab %}

{% tab title="Trunk" %}

```lua
exports.origen_inventory:openInventory('trunk', 'my-stash', { 
    label = 'My Trunk' 
})

--- Or Simply
exports.origen_inventory:openInventory('trunk', 'my-trunk')
```

{% endtab %}
{% endtabs %}

### GetInventory

Get Player inventory data

```lua
-- return table of items list
-- The following exports do exactly the same thing, for compatibility between various scripts.
exports.origen_inventory:GetInventory()
exports.origen_inventory:getPlayerInventory()
exports.origen_inventory:GetPlayerInventory()
--- Example
local myItems = exports.origen_inventory:GetInventory()
for slot, item in pairs(myItems) do
    if item.name == 'id_card' then
        ...
    end
end 
```

### CloseInventory

Close player inventory

```lua
exports.origen_inventory:CloseInventory()
```

### HasItem

Check if player has item

<pre class="language-lua"><code class="lang-lua"><strong>-- @return boolean
</strong><strong>exports.origen_inventory:HasItem(item_name)
</strong>
-- Example use
local hasWater --[[true/false]] = exports.origen_inventory:HasItem("water")
if hasWater then
    -- Do something
end
</code></pre>

### GetItems

Return the server item list or specific one

```lua
exports.origen_inventory:Items(item?)
exports.origen_inventory:GetInventoryItem(item?)
exports.origen_inventory:GetItemList(item?)
exports.origen_inventory:GetItems(item?)
exports.origen_inventory:getItems(item?)
```

### Unarmed

Set player unarmed

<pre class="language-lua"><code class="lang-lua"><strong>exports.origen_inventory:Unarmed()
</strong></code></pre>

### SetCurrentWeapon

```lua
exports.origen_inventory:SetCurrentWeapon(weapon_data, can_shoot)

-- Example usage
exports.origen_inventory:SetCurrentWeapon({
    name = "WEAPON_PISTOL"
    info = {
        attachments = {
            {
                component = "COMPONENT_PISTOL_CLIP_02" -- Component Hash or Name
            }
        },
        tint = 1
    }
}, true)
```

### SetCurrentWeapon

<pre class="language-lua"><code class="lang-lua"><strong>exports.origen_inventory:AddAmmo(type, amount, item)
</strong></code></pre>

### SetShopEnabled

{% hint style="info" %}
It only works with stores you have in your configuration and not those created at runtime.
{% endhint %}

```lua
exports.origen_inventory:SetShopEnabled(shopId, enabled --[[true/false]])
```

###

### Others

For either one, it will look for the closest player to execute the action.

#### Carry a near player

```lua
exports.origen_inventory:Carry()
```

#### PiggyBack near player

```lua
exports.origen_inventory:PiggyBack()
```

#### ToggleDriftMode

If driftmode is enabled you can toggle it with export

```lua
exports.origen_inventory:ToggleDriftMode(toggle--[[true/false]])
```

### Modules

#### sendModuleMessage

Send data to the module for manipulate later

```lua
--- Send Module message
--- @param id string
--- @param data any
--- @return boolean
exports.origen_inventory:sendModuleMessage(id, data)

--- Example
exports.origen_inventory:sendModuleMessage('test_tab', {
        action = 'open',
        other = 'blah blah'
})
```

#### createModule

Create the module including the correct actions to the script need to transform

```lua
--- Create Module
--- @param id string
--- @param data any
--- @return boolean
exports.origen_inventory:createModule(id, data)

-- Example
exports.origen_inventory:createModule('test_tab', {
        id = 'test_tab',
        icon = 'lucide:at-sign',
        ui = ("https://cfx-nui-%s/ui/index.html"):format(GetCurrentResourceName()),
        useDefaultBackground = true,
        canShow = function()
                return true
        end,
        onOpen = function() end,
        onClose = function() end
})
```

#### removeModule

Remove the module

```lua
exports.origen_inventory:removeModule('test_tab')
```

### Progressbar

**Action:** `exports.origen_inventory:progressBar(...)`

```lua
exports.origen_inventory:progressBar({
    name = 'custom_action_name', -- Unique name for the action
    duration = 5000, -- Time in milliseconds
    label = 'Performing action...', -- Text to display
    useWhileDead = false, -- Allow use while dead
    controlDisables = {
        disableMovement = true, -- Disable player movement
        disableCarMovement = true, -- Disable vehicle movement
        disableMouse = true, -- Disable mouse input
        disableCombat = true, -- Disable combat actions
    },
    canCancel = true, -- Allow the action to be cancelled
    animation = {
        animDict = 'amb@world_human_hammering@male@base', -- Animation dictionary
        anim = 'base', -- Animation name
        flags = 49, -- Animation flags
    },
    prop = {
        model = 'prop_tool_hammer', -- Prop model
        bone = 28422, -- Bone index to attach the prop
        coords = { x = 0.0, y = 0.0, z = 0.0 }, -- Position offsets
        rotation = { x = 0.0, y = 0.0, z = 0.0 }, -- Rotation offsets
    }
})
```
