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

addItemToTrunk

Adds items to a vehicle trunk using only the vehicle plate, automatically resolving the full inventory ID

Parameters

  • plate: string

    • The vehicle license plate

  • itemName: string

    • The name of the item to add

  • amount: number

    • How many items to add

  • metadata: table (optional)

    • Additional data for the item

  • 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 (e.g., "vehicle_not_found")

  • notificationType: string

    • Type of notification to show to the user

Example

Notes

  • Works with owned vehicles (even if not spawned/in garage)

  • Works with NPC vehicles (if currently spawned)

  • Automatically creates trunk inventory if it doesn't exist

  • For owned vehicles, inventory is persistent (saved to database)

addItemToGlovebox

Adds items to a vehicle glovebox using only the vehicle plate, automatically resolving the full inventory ID

Parameters

  • plate: string

    • The vehicle license plate

  • itemName: string

    • The name of the item to add

  • amount: number

    • How many items to add

  • metadata: table (optional)

    • Additional data for the item

  • 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 (e.g., "vehicle_not_found")

  • notificationType: string

    • Type of notification to show to the user

Example

Notes

  • Works with owned vehicles (even if not spawned/in garage)

  • Works with NPC vehicles (if currently spawned)

  • Automatically creates glovebox inventory if it doesn't exist

  • For owned vehicles, inventory is persistent (saved to database)

removeItemFromTrunk

Removes items from a vehicle trunk using only the vehicle plate, automatically resolving the full inventory ID

Parameters

  • plate: string

    • The vehicle license plate

  • itemName: string

    • The name of the item to remove

  • amount: number

    • How many items to remove

  • metadata: table (optional)

    • Metadata to match for removal (optional filtering)

  • slotId: number (optional)

    • Specific slot to remove from

Returns

  • success: boolean

    • true if items were removed successfully

  • resultCode: string

    • Error message if the operation failed

  • notificationType: string

    • Type of notification to show to the user

Example

Notes

  • Vehicle must exist (owned vehicle in database or NPC vehicle currently spawned)

  • Returns false with "vehicle_not_found" if vehicle doesn't exist

removeItemFromGlovebox

Removes items from a vehicle glovebox using only the vehicle plate, automatically resolving the full inventory ID

Parameters

  • plate: string

    • The vehicle license plate

  • itemName: string

    • The name of the item to remove

  • amount: number

    • How many items to remove

  • metadata: table (optional)

    • Metadata to match for removal (optional filtering)

  • slotId: number (optional)

    • Specific slot to remove from

Returns

  • success: boolean

    • true if items were removed successfully

  • resultCode: string

    • Error message if the operation failed

  • notificationType: string

    • Type of notification to show to the user

Example

Notes

  • Vehicle must exist (owned vehicle in database or NPC vehicle currently spawned)

  • Returns false with "vehicle_not_found" if vehicle doesn't exist

getInventoryIdFromPlate

Resolves the full inventory ID for a vehicle compartment using only the vehicle plate

Parameters

  • plate: string

    • The vehicle license plate

  • compartment: string

    • Either "trunk" or "glovebox"

Returns

  • inventoryId: string | nil

    • The full inventory ID (format: "vehicle:plate:model:compartment")

    • nil if vehicle not found

Example

Notes

  • Searches in this order:

    1. Owned vehicles database (ESX: owned_vehicles, QBCore: player_vehicles)

    2. Existing inventories in jaksam_inventory table

    3. Currently spawned vehicles (GetAllVehicles - NPC vehicles)

  • For owned vehicles, automatically creates inventory if it doesn't exist

  • Created inventories are persistent for owned vehicles, temporary for NPC vehicles

  • Works even if vehicle is not currently spawned (garage)

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

createInventory

Creates a new inventory in both database and memory (depending on options). If an inventory with the same ID already exists, returns the existing one without modifying it

Parameters

  • id: string | nil

    • Unique identifier for the inventory. If nil, a random ID is generated

  • label: string | nil

    • Display name for the inventory. If nil, a translation based on inventory type will be used

  • options: table (optional)

    • Configuration options for the inventory:

    • maxWeight (number, optional): Maximum weight capacity

    • maxSlots (number, optional): Maximum number of slots

    • columns (number, optional): Number of columns for grid display in the UI (for example you can make an inventory that's total slots is 10, but only has 2 columns, so it will be a 2x5 grid)

    • temporary (boolean, optional): If true, the inventory is not saved to the database and will be lost on script restart

    • prefillItems (table, optional): Random loot configuration. Items are picked via weighted selection without replacement. Structure:

      • minTypes (number, optional): Minimum number of different item types to add. Default: 1

      • maxTypes (number, optional): Maximum number of different item types to add. Default: pool size

      • items (table, required): Array of possible items, each entry: {name = string, chance = number, min = number, max = number, metadata = table?}

        • name (string, required): Item name

        • chance (number, optional): Relative weight for selection (higher = more likely). Default: 1

        • min (number, optional): Minimum amount when picked. Default: 1

        • max (number, optional): Maximum amount when picked. Default: 1

        • metadata (table, optional): Metadata to attach to the item

    • revealItems (table, optional): Progressive item reveal animation when the inventory is opened. Items appear one by one. Structure:

      • delayPerItem (number, optional): Milliseconds between each item reveal. Default: 1000

      • randomOrder (boolean, optional): If true, items are revealed in random order instead of slot order. Default: false

    • slots (table, optional): Per-slot configuration. Key is the slot number, value is a SlotConfig table:

      • label (string, optional): Display label for the slot placeholder

      • image (string, optional): Placeholder image name shown when slot is empty

      • opacity (number, optional): Placeholder image opacity (0.0 - 1.0)

      • whitelist (table, optional): Slot-level whitelist. Format: {itemName = true, ...}. Takes priority over inventory-level whitelist

      • blacklist (table, optional): Slot-level blacklist. Format: {itemName = true, ...}. Applied before inventory whitelist

    • whitelist (table, optional): Inventory-level item whitelist (used as fallback if a slot has no filter). Format: {itemName = true, ...}

    • blacklist (table, optional): Inventory-level item blacklist. Format: {itemName = true, ...}

    • allowedJobs (table, optional): Jobs allowed to access this inventory. Format: {police = true, sheriff = true}

    • allowedIdentifiers (table, optional): Character identifiers allowed to access this inventory. Format: {charIdentifier = true, ...}

    • disableIncoming (boolean, optional): If true, items cannot be transferred into this inventory by the player

    • disableOutgoing (boolean, optional): If true, items cannot be transferred out of this inventory by the player

    • dropDisabled (boolean, optional): If true, items cannot be dropped from this inventory

    • noLimitDrag (boolean, optional): If true, dragging ignores the amount selection dialog and moves the full stack. Used internally for shops

  • items: table (optional)

    • Static items to add when the inventory is first created. Array format: {{itemName, amount, metadata}, ...}

    • Ignored if the inventory already exists in the database

  • inventoryType: string (optional)

    • Type of inventory. Default: "stash". Other values: "player", "trunk", "glovebox"

  • metadata: table (optional)

    • Additional metadata for the inventory

Returns

  • inventory: Inventory | nil

    • The created (or existing) inventory table, or nil if creation failed

    • Structure: {id, label, options, items, type, totalWeight, metadata}

Example

Notes

  • If id already exists, the existing inventory is returned as is, static items and prefillItems are NOT re-applied

  • prefillItems uses weighted random selection without replacement (each item type can only be picked once)

  • prefillItems is processed via options, while static items is a separate parameter. they serve different purposes

  • Use temporary = true for ephemeral inventories (lootboxes, event rewards) to avoid database bloat

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

getItemsByName

Gets all items from an inventory by 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 items to search for

  • metadata: table (optional)

    • Metadata to match against when searching

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

  • strict: boolean (optional)

    • Whether to match the metadata strictly (default: nil)

    • If true, all metadata fields must match exactly

Returns

  • items: table

    • Array of all items found matching the criteria

    • Empty table {} if no items found

    • Each item in the array has the following structure:

Example

Notes

  • Each item includes the slot field indicating where it was found

  • Use this when you need to process multiple stacks of the same item

  • For single item lookups, prefer getItemByName for better performance

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

setDurability

Sets the durability value of an item in a specific inventory slot

Parameters

  • inventoryId: string | number

    • The inventory ID containing the item

    • Can be a player server ID or inventory ID

  • slotId: number

    • The slot containing the item to update

  • durability: number

    • The durability value to set (will be clamped between 0 and 100)

Returns

  • success: boolean

    • true if durability was updated successfully

  • resultCode: string

    • Error message if the operation failed

Example

Last updated