Server

Compatibility

This script works with other popular inventory systems, like es_extended, qb-inventory, and ox_inventory

For ESX and QBCore functions, the setup is done automatically. But, if you want to keep using exports from ox_inventory or qb-inventory for compatibility, you need to turn on this option in the file: jaksam_inventory/integrations/sv_integrations.lua

Server functions

Here there are built-in exports of jaksam's inventory

addItem

Adds items to an inventory with support for metadata and specific slot placement

exports['jaksam_inventory']:addItem(inventoryId, itemName, amount, metadata, slotId)

Parameters

  • inventoryId: string | number

    • The inventory ID to add items to

    • Can be a player server ID or inventory ID

  • itemName: string

    • The name of the item to add

  • amount: number

    • How many items to add

  • metadata: table (optional)

    • Additional data for the item (e.g. weapon serial, item durability)

  • slotId: number (optional)

    • Specific slot to place the item in

Returns

  • success: boolean

    • true if items were added successfully

  • resultCode: string

    • Error message if the operation failed

Example

canCarryItem

Checks if an inventory has space for additional items, considering both weight and slot limits

Parameters

  • inventoryId: string | number

    • The inventory ID to check

    • Can be a player server ID or inventory ID

  • itemName: string

    • The name of the item to check

  • amount: number

    • How many items to check for

Returns

  • boolean

    • true if the inventory can carry the items

    • false if adding would exceed weight or slot limits

Example

canSwapItem

Checks if swapping firstItem (removing firstItemCount) with testItem (adding testItemCount) is possible

Parameters

  • inventoryId: string | number

    • The inventory ID to check

    • Can be a player server ID or inventory ID

  • firstItem: string

    • The name of the item to check

  • firstItemCount: number

    • How many items to remove

  • testItem: string

    • The name of the item to add

  • testItemCount: number

    • How many items to add

Returns

  • boolean

    • true if the inventory can swap the items

    • false if swapping is not possible

Example

clearInventory

Removes all items from an inventory, with optional exclusion of specific items

Parameters

  • inventoryId: string | number

    • The inventory ID to clear

    • Can be a player server ID or inventory ID

  • excludedItems: string | table (optional)

    • Items to exclude from clearing (keep in inventory)

    • Can be a single item name (string) or an array of item names (table)

    • If not provided, all items will be removed

Returns

  • success: boolean

    • true if inventory was cleared successfully

    • false if inventory doesn't exist or database update failed

Example

forceOpenInventory

Forces an inventory to be opened for a specific player without permission checks

Parameters

  • playerId: number

    • The server ID of the player who will see the inventory

  • inventoryId: string | number

    • The inventory ID to open

    • Can be a player server ID (number) or inventory ID (string)

Returns

This function doesn't return any value

Example

getInventory

Gets complete data about an inventory including its items, weight limits, and metadata

Parameters

  • inventoryId: string | number

    • The inventory ID to get data for

    • Can be a player server ID (number) or inventory ID (string)

Returns

  • inventory: table | nil

    • Table containing the inventory data with the following structure:

Example

getItemFromSlot

Gets an item from a specific slot in an inventory

Parameters

  • inventoryId: string | number

    • The inventory ID to get the item from

    • Can be a player server ID (number) or inventory ID (string)

  • slotId: number

    • The slot number to get the item from

Returns

  • item: table | nil

    • The item in the slot, or nil if the slot is empty

    • Item structure:

Example

getItemByName

Gets the first item found in an inventory by its name, with optional metadata filtering

Parameters

  • inventoryId: string | number

    • The inventory ID to search in

    • Can be a player server ID (number) or inventory ID (string)

  • itemName: string

    • The name of the item to search for

  • metadata: table (optional)

    • Metadata to match against when searching

    • If provided, only items with matching metadata will be returned

Returns

  • item: table | nil

    • The first item found matching the criteria, or nil if not found

    • Item structure:

  • slotId: number | nil

    • The raw slot ID where the item was found (1-based index)

    • nil if item not found

Example

getItemLabel

Gets the display label of an item

Parameters

  • itemName: string

    • The name of the item to get the label for

Returns

  • label: string | nil

    • The display label of the item

    • nil if item doesn't exist

Example

getTotalItemAmount

Returns the total amount of a specific item in an inventory, including items in containers

Parameters

  • inventoryId: string | number

    • The inventory ID to check

  • itemName: string

    • The name of the item to count

  • metadata: table (optional)

    • Metadata to match against when counting (if provided, only items with the same metadata AND name will be counted)

  • skipContainers: boolean (optional)

    • If true, items in containers will not be counted

Returns

  • totalAmount: number

    • Total amount of the item in the inventory, including containers (only if skipContainers is false)

  • totalAmountContainersExcluded: number | nil

    • Total amount excluding containers (only if skipContainers is false)

Example

hasItem

Checks if an inventory has a specific item

Parameters

  • inventoryId: string | number

    • The inventory ID to check

  • itemName: string

    • The name of the item to check

  • quantity: number (optional)

    • How many items to check for

    • Default is 1

Returns

  • boolean

    • true if the inventory has the item

    • false if the inventory does not have the item

Example

registerUsableItem

Registers a callback function that will be called when an item is used Framework specific registering item will work anyway, as ESX.RegisterUsableItem and QBCore one

Parameters

  • itemName: string

    • The name of the item to register

  • callback: function

    • Function to call when item is used

    • Parameters of callback on ESX: playerId, itemName, inventoryItem (name, metadata, amount)

    • Parameters of callback on QBCore: playerId, inventoryItem (name, metadata, amount, etc.)

Returns

  • success: boolean

    • true if registration was successful

Example

registerStash

Dynamically registers a new stash and creates its server inventory during runtime

Parameters

  • options: table

    • Configuration table for the stash with the following fields:

    • id (string, optional): Unique ID for the stash. If not provided, one will be autogenerated

    • label (string, required): Display name for the stash

    • coords (vector3 | table, optional): Location where the stash can be accessed via interaction point

    • maxWeight (number, optional): Maximum weight capacity. Default: 100

    • maxSlots (number, optional): Maximum number of slots. Default: 100

    • radius (number, optional): Distance from which players can access the stash. Default: 3.0

    • isPrivate (boolean, optional): If true, creates a separate inventory for each player. Default: false

    • allowedJobs (table, optional): Table of job names that can access the stash. If nil, stash is public. Example: {police = true, sheriff = true}

    • temporary (boolean, optional): If true, stash won't be saved to database and lost on script restart. Default: false

    • startingItems (table, optional): Items to add when the stash is first created. Format: {{itemName, amount, metadata}, {itemName2, amount2, metadata2}, ...}

    • runtimeOnly (boolean, optional): If true (default), stash can only be opened programmatically. If false and coords are provided, creates client-side interaction points (jaksam_inventory will handle also stash opening point itself) Default: true

Returns

  • stashId: string | nil

    • The ID of the created stash

    • nil if creation failed

Example

removeItem

Removes items from an inventory

Parameters

  • inventoryId: string | number

    • The inventory ID to remove items from

    • Can be a player server ID or inventory ID

  • itemName: string

    • The name of the item to remove

  • amount: number

    • How many items to remove

  • metadata: table (optional)

    • Metadata to match when removing items (if provided, only items with the same metadata AND name will be removed)

  • slotId: number (optional)

    • Specific slot to remove items from

Returns

  • success: boolean

    • true if items were removed successfully

  • resultCode: string

    • Error message if the operation failed

Example

saveDirtyInventories

Saves all modified inventories to the database

Parameters

None

Returns

  • success: boolean

    • true if all inventories were saved successfully

Example

saveDirtyInventory

Saves a specific inventory to the database if it has been modified

Parameters

  • inventoryId: string | number

    • The ID of the inventory to save

Returns

  • success: boolean

    • true if inventory was saved successfully

Example

setInventoryMaxWeight

Sets the maximum weight capacity for an inventory

Parameters

  • inventoryId: string | number

    • The inventory ID to modify

  • maxWeight: number

    • The new maximum weight capacity

Returns

  • success: boolean

    • true if weight was set successfully

Example

setItemMetadataInSlot

Updates the metadata of an item in a specific inventory slot

Parameters

  • inventoryId: string | number

    • The inventory ID containing the item

  • slotId: number

    • The slot containing the item to update

  • metadata: table

    • The new metadata to set

Returns

  • success: boolean

    • true if metadata was updated successfully

  • resultCode: string

    • Error message if the operation failed

Example

Last updated

Was this helpful?