> For the complete documentation index, see [llms.txt](https://tgiann.gitbook.io/tgiann/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tgiann.gitbook.io/tgiann/scripts/tgiann-inventory/exports/shared-client-and-server.md).

# Shared (client & server)

These exports are registered in shared files, so they can be called from both the client and the server.

{% hint style="info" %}
Every export is also registered with a lowercase first letter, so `Items` and `items` call the same function.
{% endhint %}

{% hint style="info" %}
Per item settings (size, prop, block, carry, roleplay, decay, editable, max stack, use count, rarity...) are read in this order: the in game admin panel (`/invadmin`, `data/items.json`), then a preset the panel assigned, then the field in `items/items.lua`. The exports below always return that final value.
{% endhint %}

## Items

Returns the item list, or the data of a single item when a name is given. Labels and descriptions with multi-language support are resolved to a single string. Aliases: `GetItemList`, `ItemList` (Ox Inventory name).

```lua
local allItems = exports["tgiann-inventory"]:Items()
local bandage = exports["tgiann-inventory"]:Items("bandage")
local bandageForPlayer = exports["tgiann-inventory"]:Items("bandage", src) -- server side
```

### Parameters

* **item?**: `string` item name, the whole item list is returned when omitted
* **src?**: `number` player source, used to resolve multi-language labels to that player's language (server side only). The default language is used when omitted

### Returns

* `table` the item list, or the data of a single item

***

## ItemsRaw

Same as `Items`, but multi-language labels and descriptions are returned as tables instead of being resolved to a single string.

```lua
local bandage = exports["tgiann-inventory"]:ItemsRaw("bandage")
```

### Parameters

* **itemName?**: `string` item name, the whole item list is returned when omitted

### Returns

* `table` the item list, or the data of a single item

***

## GetItemLabel

Returns the label of an item.

```lua
local label = exports["tgiann-inventory"]:GetItemLabel("bandage")
```

### Parameters

* **item**: `string` item name
* **src?**: `number` player source, used to resolve a multi-language label to that player's language (server side only)

### Returns

* `string` item label

***

## GetItemSize

Returns how many cells an item takes in the grid inventory. The size comes from the admin panel or the `size` field in `items.lua`, items without one are 1x1. The width is never wider than `config.grid.columns` and the height never taller than `config.grid.maxItemHeight`. An item taller than the grid is wide can not be turned.

```lua
local width, height, rotatable = exports["tgiann-inventory"]:GetItemSize("weapon_carbinerifle")
-- 4, 2, true
```

### Parameters

* **name**: `string` item name

### Returns

* `integer` width in cells
* `integer` height in cells
* `boolean` whether players can turn the item (R by default)

***

## GetItemProp

Returns the world prop of an item, used when it is dropped, thrown, placed or carried. Missing fields and items without a prop come from the default object of the feature. Old name: `GetItemThrowObject`.

```lua
local prop = exports["tgiann-inventory"]:GetItemProp("bandage")
local throwProp = exports["tgiann-inventory"]:GetItemProp("bandage", config.throwableAnyItem.defaultObject)
```

### Parameters

* **name**: `string` item name
* **defaultObject?**: `table` default object of the feature (`config.objectDrop`, `config.throwableAnyItem` or `config.placeableAnyItem` `.defaultObject`), the drop default is used when omitted

### Returns

* `table` `{ hash: number, groundRotation?: number[], handRotation: number[][], handRotationOrder?: number, zOffset: number }`. Without `groundRotation` the prop is placed on the ground automatically

***

## ItemHasProp

Returns whether the item has its own prop model (admin panel or `propModel` / `prop` in `items.lua`), so the default object is not used. Old name: `IsItemConfiguredForThrowObject`.

```lua
local hasOwnProp = exports["tgiann-inventory"]:ItemHasProp("bandage")
```

### Parameters

* **name**: `string` item name

### Returns

* `boolean` whether the item has its own prop

***

## GetDurabilityPercent

Calculates the remaining durability of a decayable item in percent. The value can go below `0` for expired items.

```lua
local decayTime = exports["tgiann-inventory"]:GetItemDecayTime("bandage")
local percent = exports["tgiann-inventory"]:GetDurabilityPercent(itemData.info.durability, decayTime)
```

### Parameters

* **itemDurability**: `number` the `durability` timestamp stored in the item metadata
* **durabilityTime**: `number` total decay time of the item in seconds
* **nowTime?**: `number` timestamp used as "now", the current cloud time is used when omitted

### Returns

* `number` remaining durability in percent

***

## GetItemDecayTime

Returns how many seconds an item lasts before it decays (admin panel or `decayTime` in `items.lua`).

```lua
local seconds = exports["tgiann-inventory"]:GetItemDecayTime("bandage")
```

### Parameters

* **name**: `string` item name

### Returns

* `number?` seconds until the item decays, `nil` when it does not decay

***

## GetClotheDirtPercent

Returns how dirty a clothing item is. It returns `0` when `config.clotheDirt.active` is disabled. Time based dirt only accrues while the item is worn (`dirtTime`), dirt of unworn items is kept in `extraDirt`.

```lua
local percent = exports["tgiann-inventory"]:GetClotheDirtPercent(itemData.info)
```

### Parameters

* **info**: `table` metadata of the clothing item
* **nowTime?**: `number` timestamp used as "now". On the client the server clock from `GlobalState.tgiInvServerTime` is used when omitted

### Returns

* `number` dirt percent between `0` and `100`

***

## GetBlockItemData

Returns the block settings of an item, set in the admin panel (`/invadmin > Items`) or with the `block` field in `items.lua`. Blocked items cannot be moved into the given inventory types, and the grid shows the drop area red for them.

```lua
local blockData = exports["tgiann-inventory"]:GetBlockItemData("bandage")
```

### Parameters

* **name**: `string` item name

### Returns

* `table?` `{ drop?, glovebox?, trunk?, stash?, give?, player?, throw?, place?: boolean }`, `nil` when the item is not blocked

***

## GetEditableItemData

Returns whether players can rename the item or give it their own picture (right click > Edit).

```lua
local editable = exports["tgiann-inventory"]:GetEditableItemData("phone")
```

### Parameters

* **name**: `string` item name

### Returns

* `table?` `{ label: boolean, img: boolean }`, `nil` when the item can not be edited

***

## GetItemMaxStack

Returns how high an item stacks: its own setting, then the weapon default (`/invadmin > General settings`), then the global default. Money items under `config.moneyAsItem` always return `0`.

```lua
local maxStack = exports["tgiann-inventory"]:GetItemMaxStack("bandage")
```

### Parameters

* **name**: `string` item name

### Returns

* `number` max stack, `0` means no limit

***

## GetItemMaxUse

Returns the use count of an item. The item is deleted when the count reaches `0`.

```lua
local maxUse = exports["tgiann-inventory"]:GetItemMaxUse("lockpick")
```

### Parameters

* **name**: `string` item name

### Returns

* `table?` `{ amount: number, autoDecreases: boolean }`, `nil` when the item has no use count

***

## GetItemSwimBreak

Returns the item the player gets in place of this one when they swim (`brokenInWater` in `items.lua`).

```lua
local brokenItem = exports["tgiann-inventory"]:GetItemSwimBreak("phone")
-- "broken_phone"
```

### Parameters

* **name**: `string` item name

### Returns

* `string?` item name, `nil` when water does not break the item

***

## GetItemRarity

Returns the rarity key of an item (`/invadmin > Rarities`, or `rareName` in `items.lua`).

```lua
local rarity = exports["tgiann-inventory"]:GetItemRarity("weapon_carbinerifle")
```

### Parameters

* **name**: `string` item name

### Returns

* `string?` rarity key, `nil` when the item has none

***

## GetItemCarryConfig

Returns the carry settings of an item, set with the `carry` field in `items.lua` or in the admin panel. Carry items are held in the player's hands as a prop while they are in the inventory.

```lua
local carryData = exports["tgiann-inventory"]:GetItemCarryConfig("gold_bar")
```

### Parameters

* **name**: `string` item name

### Returns

* `table?` carry settings, `nil` when the item is not a carry item. `model` falls back to the item's prop

***

## GetItemRoleplayConfig

Returns the roleplay action of an item (animation, progress bar, emote, hand prop), set in the admin panel (`/invadmin > Items > Use > Roleplay`) or with the `roleplay` field in `items.lua`. The admin panel wins when both exist.

```lua
local roleplay = exports["tgiann-inventory"]:GetItemRoleplayConfig("bouquet")
```

### Parameters

* **name**: `string` item name

### Returns

* `table?` roleplay settings, `nil` when the item has none

***

## RegisterCraft

Registers a crafting category at runtime. Call it on both the client and the server, because the crafting list is stored in the shared config on each side.

```lua
local items = {
    {
        giveAmount = 1,
        name = "testburger",
        costs = {
            ["testitem"] = 5,
            ["testitemuniq"] = 3,
        },
        duration = 5000,
        multiplyDurationByAmount = true,
        percent = 50,
        info = { label = "My Test Label for Burger" }
    },
}
exports["tgiann-inventory"]:RegisterCraft("policecraft", "Police Crafting", items)
```

### Parameters

* **category**: `string` unique crafting category name, used by `OpenCraft` and `configCraft.lua` craft locations
* **label**: `string` crafting menu label
* **items**: `table` recipe list. Recipe fields: `name`, `giveAmount`, `costs`, `duration?`, `multiplyDurationByAmount?`, `percent?`, `info?`

***

## RegisterJobCraft

Registers a crafting menu for a job. It throws when a menu is already registered for that job.

```lua
exports["tgiann-inventory"]:RegisterJobCraft("police", "Police Crafting", items)
```

### Parameters

* **jobName**: `string` job name
* **label**: `string` crafting menu label
* **items**: `table` recipe list, same structure as in `RegisterCraft`

***

## RegisterGangCraft

Registers a crafting menu for a gang. It throws when a menu is already registered for that gang.

```lua
exports["tgiann-inventory"]:RegisterGangCraft("ballas", "Ballas Crafting", items)
```

### Parameters

* **gangName**: `string` gang name
* **label**: `string` crafting menu label
* **items**: `table` recipe list, same structure as in `RegisterCraft`

***

## CraftCategory

Returns the crafting categories with their labels. The list is built while `configCraft.lua` is loaded, so categories registered later with `RegisterCraft` are not included.

```lua
local categories = exports["tgiann-inventory"]:CraftCategory()
-- categories = { { craft = 1, label = "Main Craft" } }
```

### Returns

* `table` list of `{ craft: number, label: string }`
