Server

Server-side exports for ak47_inventory.

Core Item Operations

AddItem

Adds an item to an inventory with automatic stacking and weight checks.

local success, reason = exports['ak47_inventory']:AddItem(inv, item, amount, slot, info, weight, expiretime)
Parameter Type Required Description
inv string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
amount number Yes Quantity to add
slot number No Specific target slot index
info table No Custom item metadata table
weight number No Override weight per unit
expiretime number No Override expiration timestamp
  • Returns: boolean, string | number (Success flag and slot index or failure reason)

RemoveItem

Removes an item quantity from an inventory.

local success, reason = exports['ak47_inventory']:RemoveItem(inv, item, amount, slot)
Parameter Type Required Description
inv string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
amount number Yes Quantity to remove
slot number No Specific slot index to remove from
  • Returns: boolean, string (True on success, false and reason on failure)

HasItems

Verifies if an inventory contains required item quantities.

local hasAll, missingItems = exports['ak47_inventory']:HasItems(inv, items)
Parameter Type Required Description
inv string / number Yes Player source ID or inventory identifier
items table Yes Key-value table of required items and amounts
  • Returns: boolean, table (Status boolean and table of missing item counts)

GetItem

Retrieves consolidated item data from an inventory across all slots.

local itemData = exports['ak47_inventory']:GetItem(inv, item, info, strict)
Parameter Type Required Description
inv string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: table or nil (Consolidated item data table)

GetAmount

Returns total numeric count of an item in an inventory.

local total = exports['ak47_inventory']:GetAmount(identifier, item, info, strict)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: number (Total item quantity)

CanAddItem

Checks whether an inventory has sufficient slots and weight capacity for an item.

local canAdd = exports['ak47_inventory']:CanAddItem(identifier, item, amount, skipWeight)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
amount number Yes Quantity to check
skipWeight boolean No If true, bypasses weight limit checks
  • Returns: boolean (true if item can fit, false otherwise)

CanRemoveItem

Checks whether an inventory contains sufficient quantity of an item.

local canRemove = exports['ak47_inventory']:CanRemoveItem(identifier, item, amount)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
item string Yes Item identifier name
amount number Yes Quantity to check
  • Returns: boolean (true if quantity exists, false otherwise)

CanCarryAmount

Calculates maximum amount of an item that fits within remaining weight capacity.

local maxAmount = exports['ak47_inventory']:CanCarryAmount(identifier, item)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
item string / table Yes Item identifier name or item data table
  • Returns: number (Quantity that fits into inventory)

CanSwapItem

Determines whether swapping items between inventories or slots violates weight limits.

local canSwap = exports['ak47_inventory']:CanSwapItem(inv, firstItem, firstItemCount, testItem, testItemCount)
Parameter Type Required Description
inv string / number Yes Inventory identifier
firstItem table Yes First item data table
firstItemCount number Yes First item quantity
testItem table Yes Target item data table
testItemCount number Yes Target item quantity
  • Returns: boolean (true if swap is valid, false otherwise)

Inventory Management

OpenInventory

Opens an inventory interface on the client for a specific player source.

exports['ak47_inventory']:OpenInventory(source, identifier)
Parameter Type Required Description
source number Yes Target player server ID
identifier string Yes Inventory identifier to open

CloseInventory

Forces the inventory UI closed for a specific player source.

exports['ak47_inventory']:CloseInventory(source)
Parameter Type Required Description
source number Yes Target player server ID

CreateInventory

Initializes a new inventory in active memory.

exports['ak47_inventory']:CreateInventory(identifier, data)
Parameter Type Required Description
identifier string Yes Unique inventory identifier string
data table Yes Table containing label, maxWeight, slots, and type

LoadInventory

Loads an inventory from the database or creates it if missing.

local success = exports['ak47_inventory']:LoadInventory(identifier, data)
Parameter Type Required Description
identifier string Yes Unique inventory identifier string
data table No Default schema data if missing in database
  • Returns: boolean (true if loaded successfully)

SaveInventory

Forces an immediate save of a specific inventory to the database.

exports['ak47_inventory']:SaveInventory(identifier)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier

SaveAllInventory

Forces an immediate database save of all loaded inventories with pending changes.

exports['ak47_inventory']:SaveAllInventory()

ClearInventory

Wipes all item records from an inventory.

exports['ak47_inventory']:ClearInventory(identifier)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier

UnloadInventory

Unloads an inventory from memory without deleting its database record.

exports['ak47_inventory']:UnloadInventory(identifier)
Parameter Type Required Description
identifier string / number Yes Inventory identifier string

DeleteInventory

Permanently removes an inventory from active memory and the database.

exports['ak47_inventory']:DeleteInventory(identifier)
Parameter Type Required Description
identifier string / number Yes Inventory identifier string

Data Retrieval & Getters

GetInventory

Retrieves the complete data table of an inventory.

local invData = exports['ak47_inventory']:GetInventory(identifier)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
  • Returns: table or nil (Inventory table or nil if not found)

GetInventoryItems

Retrieves an array of all items inside an inventory.

local items = exports['ak47_inventory']:GetInventoryItems(identifier)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
  • Returns: table (Array of item data tables)

Searches an inventory for total item counts or slot occurrences.

local result = exports['ak47_inventory']:Search(identifier, searchType, item, info)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
searchType string Yes Search mode ('slots' or 'amount')
item string / table Yes Single item name or array of item names
info table / string No Metadata filter table or string match
  • Returns: number or table (Item count or slot data tables)

Items

Retrieves the shared item table or a specific item's definition.

local itemDefs = exports['ak47_inventory']:Items(itemName)
Parameter Type Required Description
itemName string No Specific item name or nil for all items
  • Returns: table (Shared item definitions or single item table)

GetItemLabel

Retrieves the localized display label for an item.

local label = exports['ak47_inventory']:GetItemLabel(name)
Parameter Type Required Description
name string Yes Item identifier name
  • Returns: string (Display label)

GetCurrentWeapon

Retrieves the weapon data table currently equipped by a player.

local weaponData = exports['ak47_inventory']:GetCurrentWeapon(source)
Parameter Type Required Description
source number Yes Player server ID
  • Returns: table or nil (Weapon item data or nil if unarmed)

CanCarryWeight

Checks whether an inventory has sufficient remaining capacity to carry added weight.

local canCarry = exports['ak47_inventory']:CanCarryWeight(identifier, weight)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
weight number Yes Weight to add in grams
  • Returns: boolean (true if weight fits, false otherwise)

GetEmptySlot

Finds the first available empty slot index in an inventory.

local slotIndex = exports['ak47_inventory']:GetEmptySlot(identifier)
Parameter Type Required Description
identifier string / number Yes Player source ID or inventory identifier
  • Returns: number or nil (Slot index number or nil if full)

GetContainerFromSlot

Retrieves the sub-inventory identifier associated with a container slot (e.g. backpack).

local containerId = exports['ak47_inventory']:GetContainerFromSlot(identifier, slot)
Parameter Type Required Description
identifier string / number Yes Parent inventory identifier
slot number Yes Slot index occupied by container item
  • Returns: string or nil (Container inventory identifier string)

Slot Operations

GetSlot

Retrieves item data stored at a specific slot index.

local itemData = exports['ak47_inventory']:GetSlot(identifier, slot)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
slot number Yes Slot index number
  • Returns: table or nil (Item data table or nil if empty)

GetSlotForItem

Finds the first slot containing an item or the first empty slot.

local slotIndex = exports['ak47_inventory']:GetSlotForItem(identifier, item)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
  • Returns: number or nil (Slot index number)

GetSlotWithItem

Retrieves data of the first slot containing a specific item.

local slotData = exports['ak47_inventory']:GetSlotWithItem(identifier, item, info, strict)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: table or nil (Slot data table)

GetSlotIdWithItem

Retrieves the index number of the first slot containing a specific item.

local slotId = exports['ak47_inventory']:GetSlotIdWithItem(identifier, item, info, strict)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: number or nil (Slot index number)

GetSlotsWithItem

Retrieves an array of all slot data tables containing a specific item.

local slots = exports['ak47_inventory']:GetSlotsWithItem(identifier, item, info, strict)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: table or nil (Array of slot data tables)

GetSlotIdsWithItem

Retrieves an array of all slot indices containing a specific item.

local slotIds = exports['ak47_inventory']:GetSlotIdsWithItem(identifier, item, info, strict)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
info table No Metadata filter table
strict boolean No Strict metadata match flag
  • Returns: table or nil (Array of slot index numbers)

GetItemSlots

Retrieves a map of slot indices and item quantities for a specific item.

local itemSlots = exports['ak47_inventory']:GetItemSlots(identifier, item)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
  • Returns: table (Key-value map of [slot] = amount)

GetFirstItem

Retrieves the first found item table for an item name.

local itemData = exports['ak47_inventory']:GetFirstItem(identifier, item)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
item string Yes Item identifier name
  • Returns: table or nil (First found item table)

Updates & Modification

SetItemInfo

Updates custom metadata table for an item at a specific slot.

local success = exports['ak47_inventory']:SetItemInfo(identifier, slot, info)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
slot number Yes Slot index number
info table Yes Updated metadata table
  • Returns: boolean (true if updated successfully)

SetQuality

Sets durability quality percentage for an item at a specific slot.

local success = exports['ak47_inventory']:SetQuality(identifier, slot, quality)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
slot number Yes Slot index number
quality number Yes New quality percentage (0-100)
  • Returns: boolean (true if updated successfully)

RemoveQuality

Reduces durability quality percentage for an item at a specific slot.

local success = exports['ak47_inventory']:RemoveQuality(identifier, slot, amount)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
slot number Yes Slot index number
amount number Yes Quality percentage to subtract
  • Returns: boolean (true if updated successfully)

SetMaxWeight

Sets maximum weight capacity for an inventory.

local success = exports['ak47_inventory']:SetMaxWeight(identifier, maxWeight)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
maxWeight number Yes New maximum weight in grams
  • Returns: boolean (true if updated successfully)

SetSlotCount

Sets total available slot count for an inventory.

local success = exports['ak47_inventory']:SetSlotCount(identifier, slots)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
slots number Yes New maximum slot count
  • Returns: boolean (true if updated successfully)

UpdatePlayerInv

Synchronizes server player inventory state to the client.

exports['ak47_inventory']:UpdatePlayerInv(source)
Parameter Type Required Description
source number Yes Player server ID

SetInvItems

Replaces the full item table of an inventory.

exports['ak47_inventory']:SetInvItems(identifier, items)
Parameter Type Required Description
identifier string / number Yes Inventory identifier
items table Yes Array of item slot tables

ClearClothing

Clears equipped physical clothing items from a player.

exports['ak47_inventory']:ClearClothing(source)
Parameter Type Required Description
source number Yes Player server ID

Administrative & Special

ConfiscateInventory

Confiscates player inventory items and stores them into a temporary stash.

local stashId = exports['ak47_inventory']:ConfiscateInventory(source)
Parameter Type Required Description
source number Yes Player server ID
  • Returns: string (Identifier of confiscated storage stash)

ReturnInventory

Restores previously confiscated items back into a player's inventory.

local success = exports['ak47_inventory']:ReturnInventory(source, identifier)
Parameter Type Required Description
source number Yes Player server ID
identifier string Yes Confiscated storage identifier string
  • Returns: boolean (true if inventory was restored)

CreateShop

Registers a dynamic shop inventory on the server.

exports['ak47_inventory']:CreateShop(shopId, label, items, account)
Parameter Type Required Description
shopId string Yes Unique shop identifier string
label string Yes Display title for the shop UI
items table Yes Array of shop item tables
account string Yes Currency account ('cash', 'bank', 'black_money')

SetWhitelistedItemsForContainer

Configures allowed items whitelist for a specific container inventory.

exports['ak47_inventory']:SetWhitelistedItemsForContainer(identifier, items)
Parameter Type Required Description
identifier string / number Yes Container inventory identifier
items table Yes Array of allowed item names

SetBlacklistedItemsForContainer

Configures blocked items blacklist for a specific container inventory.

exports['ak47_inventory']:SetBlacklistedItemsForContainer(identifier, items)
Parameter Type Required Description
identifier string / number Yes Container inventory identifier
items table Yes Array of blocked item names

OnChangeVehiclePlate

Updates database and memory inventory identifiers when a vehicle plate changes.

exports['ak47_inventory']:OnChangeVehiclePlate(oldPlate, newPlate)
Parameter Type Required Description
oldPlate string Yes Original vehicle license plate string
newPlate string Yes New vehicle license plate string