> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-advanced-inventory/developers.md).

# For developers

Developer reference for CAS Advanced Inventory. Every VORP and RSG inventory export, the vorp\_inventoryApi object, custom inventories, old syn windows, item metadata keys and the events to start a tra

**You do not need to change your scripts.** CAS Advanced Inventory answers the same exports, events and database tables as the stock inventory, under the same resource name (`vorp_inventory` or `rsg-inventory`), with the same arguments, callback positions and return values.

## VORP

### Server exports

`exports.vorp_inventory:<name>(...)`, all with VORP's signatures (sync return and optional callback):

| Group              | Exports                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Items              | `addItem`, `subItem`, `subItemById`, `subItemID`, `subAllItems`, `getItemCount`, `getItem`, `getItemById`, `getItemByMainId`, `getItemByName`, `getItemContainingMetadata`, `getItemMatchingMetadata`, `getUserInventoryItems`, `getItemDB`, `canCarryItem`, `canCarryItems`, `setItemMetadata`, `setItemDurability`                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Usable items       | `registerUsableItem`, `unRegisterUsableItem`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Weapons            | `createWeapon`, `canCarryWeapons`, `giveWeapon`, `subWeapon`, `deleteWeapon`, `subAllWeapons`, `getUserInventoryWeapons`, `getUserWeapon`, `getWeaponComponents`, `addWeaponComponent`, `addWeaponComponents`, `subWeaponComponent`, `subWeaponComponents`, `setWeaponCustomLabel`, `setWeaponSerialNumber`, `setWeaponCustomDesc`, and (not in stock VORP) `setWeaponComponents(source, weaponId, components)` to replace a gun's whole part list                                                                                                                                                                                                                                                                                                               |
| Ammo               | `getWeaponBullets`, `getUserAmmo`, `addBullets`, `subBullets`, `removeAllUserAmmo`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Custom inventories | `registerInventory`, `removeInventory`, `isCustomInventoryRegistered`, `getCustomInventoryData`, `updateCustomInventoryData`, `updateCustomInventorySlots`, `getCustomInventorySlots`, `setCustomInventoryItemLimit`, `setCustomInventoryWeaponLimit`, `AddPermissionMoveToCustom`, `AddPermissionTakeFromCustom`, `AddCharIdPermissionMoveToCustom`, `AddCharIdPermissionTakeFromCustom`, `BlackListCustomAny`, `addItemsToCustomInventory`, `addWeaponsToCustomInventory`, `getCustomInventoryItemCount`, `getCustomInventoryWeaponCount`, `removeItemFromCustomInventory`, `removeWeaponFromCustomInventory`, `removeCustomInventoryWeaponById`, `getCustomInventoryItems`, `getCustomInventoryWeapons`, `updateCustomInventoryItem`, `deleteCustomInventory` |
| Opening            | `openInventory`, `closeInventory`, `openPlayerInventory`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Context menu       | `addAllowedContextMenuEvent`, `removeAllowedContextMenuEvent`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

The old API object works too: `exports.vorp_inventory:vorp_inventoryApi()`, and the `vorpCore:*` server events (`vorpCore:addItem`, `vorpCore:subItem`, `vorpCore:getItemCount` and the rest).

### Weapon parts (VORP and RSG)

For a gunsmith bench or a shop. `weaponId` is the VORP loadout id or the RSG serial; `category` is `scope`, `sight`, `barrel`, `grip`, `stock` or `forend`.

| Export                                                   | Returns                | What it does                                                                                                                                                 |
| -------------------------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `attachAccessory(source, weaponId, component, category)` | `true` or `false, err` | Puts the part on (charge the player first). A non factory part it replaces goes to the satchel; `false, 'no_space'` when it does not fit and nothing changes |
| `detachAccessory(source, weaponId, category)`            | `true` or `false, err` | Takes the part off into the satchel and puts the factory part back on                                                                                        |
| `canDetachAccessory(source, weaponId, category)`         | `true` or `false, err` | The same check without changing anything                                                                                                                     |
| `getWeaponParts(weaponName)`                             | table                  | The parts list of a weapon from `config/parts.lua`                                                                                                           |

Errors: `gone`, `no_part`, `wrong_part`, `factory_part`, `no_space`, `too_heavy`.

### Client exports and events

* Exports: `closeInventory`, `setHotbarVisible`, `getWeaponDefaultWeight`, `getWeaponDefaultDesc`, `getWeaponDefaultLabel`, `getWeaponName`, `getWeaponsDefaultData`, `getWeaponAmmoTypes`, `getAmmoLabel`, `getInventoryItem`, `getInventoryItems`, `getServerItem`, `useItem`, `useWeapon`.
* Events it listens to: `vorp_inventory:OpenInv`, `vorp_inventory:CloseInv`, `vorp_inventory:blockInventory`, `vorp_inventory:Client:DisableInventory`, `vorpinventory:ammoUpdateToggle`, `inv:dropstatus`, `inv:givestatus`.
* Events it fires: `vorp_inventory:Client:OnInvStateChange`, `vorp_inventory:onWeaponEquipped`, `syn_weapons:weaponused`, `syn:closeinv`; the `IsInvActive` state bag is set while it is open.
* `config/weapons.lua` and `config/ammo.lua` keep VORP's `SHARED_DATA` shape, so scripts that load them still read weapon names and ammo caps.

### Custom inventories (stashes)

`registerInventory` takes VORP's option table (`id`, `name`, `limit`, `acceptWeapons`, `shared`, `ignoreItemStackLimit`, `whitelistItems`, `UsePermissions`, `UseBlackList`, `whitelistWeapons`, `useWeight`, `weight`, `webhook`). Contents stay in `character_inventories` under the inventory id, so stashes made with the stock inventory keep their items. A stash opens on the right of the satchel; shared stashes are used by one rider at a time and show who has access and the last changes.

### Old syn windows

The old `vorp_inventory:Open<Type>Inventory` / `vorp_inventory:Reload<Type>Inventory` windows work as they did in VORP's inventory, for **Store, Horse, Cart, steal, House, Hideout, Clan, Container** and **Bank** (syn\_stores, syn\_clan, syn\_Container, syn\_search, syn\_underground and the old vorp\_stables, vorp\_housing and vorp\_bank).

* The list your script sends shows as the right-hand panel.
* Moves go back to your script as its own server events with VORP's JSON (`syn_clan:MoveToClan`, `syn_clan:TakeFromClan`, `vorp_stables:MoveToHorse`, `syn_store:MoveToStore` ...). The item is sent in VORP's item shape.
* One take at a time until your script sends the next list, as before.
* syn\_stores: the owner (`geninfo.isowner`) is asked for a price when stocking the store, buyers see the price.
* `vorp_stables:setClosedInv` and `syn_store:setClosedInv` fire on open and close as before.

## RSG Core

### Server exports

`exports['rsg-inventory']:<name>(...)` as in rsg-inventory 2.x:

`AddItem`, `RemoveItem`, `HasItem`, `GetItemCount`, `CanAddItem`, `CanCarry`, `GetItemBySlot`, `GetItemByName`, `GetItemsByName`, `GetSlotsByItem`, `GetFirstSlotByItem`, `GetTotalWeight`, `GetSlots`, `GetFreeWeight`, `GetItemWeight`, `ClearInventory`, `SetInventory`, `SetItemData`, `SetItemInfo`, `UseItem`, `CreateUsableItem`, `GetUsableItem`, `OpenInventory`, `OpenStash`, `OpenInventoryById`, `OpenPlayerInventory`, `CloseInventory`, `GetInventory`, `CreateInventory`, `RegisterStash`, `DeleteInventory`, `SaveStash`, `ClearStash`, `ForceDropItem`, `CreateDrop`, `LoadInventory`, `SaveInventory`, `CreateShop`, `DoesShopExist`, `OpenShop`, `RestockShop`.

The item methods rsg-core puts on the player (`Player.Functions.AddItem`, `RemoveItem`, `GetItemByName`, `GetItemsByName`, `GetItemBySlot`, `ClearInventory`, `SetInventory` ...) are served by the inventory. `inv_busy`, `rsg-inventory:client:ItemBox`, `rsg-inventory:server:closeInventory` and `rsg-inventory:server:SetInventoryData` behave as before. The `inventory`, `closeinv`, `giveitem` and `clearinv` commands still work.

### Client exports

`HasItem`, `GetItemCount`, `CloseInventory`, `IsOpen`.

## Hooks in the config

Functions in the open config files that you can point at your own scripts:

| Hook                              | File                       | Side   | Returns                                                                              |
| --------------------------------- | -------------------------- | ------ | ------------------------------------------------------------------------------------ |
| `Config.Metabolism()`             | `config/config.lua`        | client | hunger, thirst (0 to 1, or `nil`) for the meters                                     |
| `ServerConfig.Metabolism(source)` | `config/config_server.lua` | server | the same, for a metabolism that keeps its values on the server; the client hook wins |
| `Config.PortraitUrl`              | `config/config.lua`        | server | a picture address with `{id}` (server id) for the rider portraits                    |

## State bags

| State                           | Set by                 | Meaning                                                                                                                                                        |
| ------------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `LocalPlayer.state.IsInvActive` | the inventory          | `true` while the satchel is open (as with stock vorp\_inventory)                                                                                               |
| `LocalPlayer.state.handsUp`     | your hands-up script   | `true` lets `/search` open on this rider ([Stashes and other scripts](/script-documentation/cas-advanced-inventory/compatibility.md#searching-needs-hands-up)) |
| `hunger` / `thirst`             | your metabolism script | read for the meters when no supported metabolism runs                                                                                                          |

## Item metadata keys

| Key                                   | Effect                                                                                                                                                                                       |
| ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `label`                               | Replaces the item name                                                                                                                                                                       |
| `description`                         | Replaces the description                                                                                                                                                                     |
| `image`                               | Picture file name (without `.png`) used instead of the item name                                                                                                                             |
| `weight`                              | Replaces the unit weight                                                                                                                                                                     |
| `rarity`                              | Rarity colour when the item definition has none                                                                                                                                              |
| `context`                             | VORP context menu buttons: `{ text = 'Read', event = { client = 'my:event' } or { server = 'my:event' }, arguments = any }`. Server events must be allowed with `addAllowedContextMenuEvent` |
| `durability` (VORP) / `quality` (RSG) | Shown as a condition bar                                                                                                                                                                     |

## Starting things from other scripts

For radial menus, target scripts or your own UI (client side, `TriggerEvent`):

| Event                         | Arguments     | What it does                                       |
| ----------------------------- | ------------- | -------------------------------------------------- |
| `cas_inventory:client:trade`  | `(serverId?)` | Starts a trade with that rider, or the closest one |
| `cas_inventory:client:search` | `(serverId?)` | Searches that rider, or the closest one            |
| `cas_inventory:client:craft`  | none          | Opens the satchel on hand crafting                 |

The server checks distance and state again, so these are safe to call from anywhere on the client. On VORP `exports.vorp_inventory:openPlayerInventory(...)` opens a searched rider's satchel from your own script (police or robbery scripts), with the checks your script decides.
