RX Scripts Logo
Inventory

Functions

Server-side inventory functions supporting 10+ inventory systems.

The Inventory adapter provides unified inventory operations on the server side across multiple inventory systems.

Item Management Functions

registerUsableItem

Registers an item as usable.

FM.inventory.registerUsableItem(itemName, cb)
Note: This is an alias for FM.framework.registerUsableItem. Both work identically.

getItemLabel

Returns the display label for an item.

FM.inventory.getItemLabel(item)
item
string required

The item name

Returns: string|nil - Item label or nil if not found

Note: May not work for weapons in ESX & OX inventory.

addItem

Adds an item to a player's inventory.

FM.inventory.addItem(src, item, amount, metadata)
src
number required

Player source ID

item
string required

Item name to add

amount
number required

Amount to add

metadata
table

Optional item metadata

Returns: boolean - True if item was added successfully

Example:

RegisterNetEvent('giveItem', function()
    local src = source
    if FM.inventory.addItem(src, "water", 5) then
        print("Added 5 water bottles")
    end

    -- Add with metadata
    FM.inventory.addItem(src, "id_card", 1, {
        firstname = "John",
        lastname = "Doe",
        dob = "01/01/1990"
    })
end)

removeItem

Removes an item from a player's inventory.

FM.inventory.removeItem(src, item, amount, slotId, metadata)
src
number required

Player source ID

item
string required

Item name to remove

amount
number required

Amount to remove

slotId
number

Specific slot to remove from (optional)

metadata
table

Specific metadata to match (optional)

Returns: boolean - True if item was removed successfully


canCarryItem

Checks if a player can carry an item (weight/space check).

FM.inventory.canCarryItem(src, item, amount)
src
number required

Player source ID

item
string required

Item name to check

amount
number required

Amount to check

Returns: boolean - True if player can carry the item


getItem

Gets information about a specific item in a player's inventory.

FM.inventory.getItem(src, item)
src
number required

Player source ID

item
string required

Item name to get

Returns: Item|nil - Item data or nil if not found

Item Structure:

{
    name = "water",
    label = "Water",
    amount = 5
}

getInventory

Gets all items in a player's inventory.

FM.inventory.getInventory(src)
src
number required

Player source ID

Returns: table<number, Item> - Table of items indexed by slot

Weapon Functions

addWeapon

Adds a weapon to a player's inventory.

FM.inventory.addWeapon(src, weapon, ammo)
src
number required

Player source ID

weapon
string required

Weapon name to add

ammo
number

Ammo count (optional, default 0)

Returns: boolean - True if weapon was added successfully

Example:

RegisterNetEvent('giveWeapon', function()
    local src = source
    FM.inventory.addWeapon(src, "weapon_pistol", 50)
end)

removeWeapon

Removes a weapon from a player's inventory.

FM.inventory.removeWeapon(src, weapon)
src
number required

Player source ID

weapon
string required

Weapon name to remove

Returns: boolean - True if weapon was removed successfully


getWeapon

Gets information about a weapon in a player's inventory.

FM.inventory.getWeapon(src, weapon)
src
number required

Player source ID

weapon
string required

Weapon name to get

Returns: Weapon|nil - Weapon data or nil if not found

Weapon Structure:

{
    name = "weapon_pistol",
    ammo = 50,
    count = 1
}

Metadata Functions

getMetaDataBySlot

Gets metadata from a specific inventory slot.

FM.inventory.getMetaDataBySlot(inv, slot)
inv
string|number required

Inventory identifier (player source or inventory name)

slot
number required

The slot number

Returns: table|nil - Item metadata or nil if not found


setMetaDataBySlot

Sets metadata for a specific inventory slot.

FM.inventory.setMetaDataBySlot(inv, slot, metadata)
inv
string|number required

Inventory identifier (player source or inventory name)

slot
number required

The slot number

metadata
table required

The new metadata to set

Returns: boolean|nil - Success status


getSlotIDByItem

Gets the first slot containing a specific item.

FM.inventory.getSlotIDByItem(inv, itemName)
inv
string|number required

Inventory identifier

itemName
string required

The item name to find

Returns: number|nil - Slot number or nil if not found

Stash Functions

registerStash

Registers a stash for use (mainly for ox_inventory).

FM.inventory.registerStash(stash)
stash
StashConfig required

Stash configuration object

StashConfig Structure:

{
    id = "police_evidence",     -- Unique stash ID
    label = "Evidence Locker",  -- Display label
    slots = 50,                 -- Number of slots
    weight = 100000,            -- Weight limit
    owner = false,              -- Owner identifier or false for shared
    groups = { police = 0 },    -- Job/gang access (optional)
    coords = vector3(x, y, z)   -- Location (optional)
}

Example:

-- Register a shared stash
FM.inventory.registerStash({
    id = "gang_stash_ballas",
    label = "Ballas Stash",
    slots = 100,
    weight = 200000,
    owner = false,
    groups = { ballas = 0 }
})

-- Register a player-owned stash
FM.inventory.registerStash({
    id = "player_safe_" .. identifier,
    label = "Personal Safe",
    slots = 50,
    weight = 100000,
    owner = identifier
})

upgradeStash

Upgrades a stash's weight and/or slots.

FM.inventory.upgradeStash(stashId, newWeight, newSlots)
stashId
string|number required

The stash identifier to upgrade

newWeight
number

New weight limit (optional)

newSlots
number

New slot count (optional)

Example:

-- Upgrade stash capacity
FM.inventory.upgradeStash("player_safe_123", 150000, 75)

Exports

All inventory functions are available as exports:

exports['fmLib']:inventory_registerUsableItem(itemName, cb)
exports['fmLib']:inventory_getItemLabel(item)
exports['fmLib']:inventory_addItem(src, item, amount, metadata)
exports['fmLib']:inventory_removeItem(src, item, amount, slotId, metadata)
exports['fmLib']:inventory_canCarryItem(src, item, amount)
exports['fmLib']:inventory_getItem(src, item)
exports['fmLib']:inventory_getInventory(src)
exports['fmLib']:inventory_addWeapon(src, weapon, ammo)
exports['fmLib']:inventory_removeWeapon(src, weapon)
exports['fmLib']:inventory_getWeapon(src, weapon)
exports['fmLib']:inventory_getMetaDataBySlot(inv, slot)
exports['fmLib']:inventory_setMetaDataBySlot(inv, slot, metadata)
exports['fmLib']:inventory_getSlotIDByItem(inv, itemName)
exports['fmLib']:inventory_registerStash(stash)
exports['fmLib']:inventory_upgradeStash(stashId, newWeight, newSlots)