Koja Scripts
KOJA-LIB

Inventory

Server-side inventory functions.

Inventory

Server-side inventory functions. All functions route through the adapter for the detected inventory resource and fall back to the framework's native item API when no adapter is available.


addInventoryItem

Add an item to a player's inventory.

local ok = KOJA.Server.addInventoryItem(source, name, count, metadata, slot)
ParameterTypeDescription
sourcenumberPlayer server ID
namestringItem name
countnumberAmount to add
metadatatable?Item metadata (supported by ox_inventory, qs-inventory, codem-inventory, jaksam_inventory)
slotnumber?Target slot (inventory-specific)

Returns booleantrue on success.


removeInventoryItem

Remove an item from a player's inventory.

local ok = KOJA.Server.removeInventoryItem(source, name, count, metadata, slot)

Same parameters as addInventoryItem.

Returns booleantrue on success.


getInventoryItemCount

Get the total count of an item in a player's inventory.

local count = KOJA.Server.getInventoryItemCount(source, name, metadata)
ParameterTypeDescription
sourcenumberPlayer server ID
namestringItem name
metadatatable?Filter by metadata (ox_inventory only)

Returns number


HasItem

Check if a player owns at least count of an item.

local has = KOJA.Server.HasItem(source, name, count)
ParameterTypeDescription
sourcenumberPlayer server ID
namestringItem name
countnumber?Minimum amount (default: 1)

Returns boolean


GetPlayerInventory

Returns the player's full inventory as a flat map.

local inventory = KOJA.Server.GetPlayerInventory(source)

Returns table{ [itemName] = count }


Examples

-- Give 3 bread to a player
KOJA.Server.addInventoryItem(source, 'bread', 3)

-- Take 1 lockpick
local ok = KOJA.Server.removeInventoryItem(source, 'lockpick', 1)
if not ok then
    print('Failed to remove lockpick')
end

-- Check before doing something
if not KOJA.Server.HasItem(source, 'keycard') then
    KOJA.Server.SendNotify({ source = source, type = 'error', desc = 'You need a keycard.' })
    return
end

-- Print all items
local inv = KOJA.Server.GetPlayerInventory(source)
for item, count in pairs(inv) do
    print(item, count)
end

Metadata & Slot Support

-- ox_inventory: add item with metadata
KOJA.Server.addInventoryItem(source, 'phone', 1, { serial = '12345', color = 'black' })

-- qs-inventory / codem-inventory / jaksam_inventory: add to a specific slot
KOJA.Server.addInventoryItem(source, 'weapon_pistol', 1, nil, 5)
  • Police — Functions for checking how many police officers are online.
  • Callbacks — The callback system allows server scripts to handle requests from clients and vice versa.
  • Licenses — Check whether a player holds a specific driving or skill license.
  • Money — Functions for reading and modifying a player's money on the server.
  • Notifications — Send notifications to a player from the server side.
  • Player — Functions for reading player information on the server.
  • Server API — back to the section overview