JRS COREDocs

jrs_inventory

Server and client exports, hooks and events of jrs_inventory for items, weapons, storages and trades.

jrs_inventory owns every bag in JRS Core: items, weapons, ammo, storages, ground drops and player trades. Almost all of its API lives on the server, because the server is the only side allowed to change what a player owns. Call the exports with exports.jrs_inventory:<name>(...) from any server script once jrs_inventory has started. A few small client exports exist for UI checks.

Item exports answer with three values, ok, reason, data. Read ok first, and only then pay a reward or take money. The reason strings you will meet most are invalid_item, invalid_count, player_not_found, inventory_not_loaded, full, owned_limit, not_enough and not_found. Hook events are listed right after the export that fires them.

Giving And Taking Items#

Server

addItem

#
exports.jrs_inventory:addItem(source, itemName, count, metadata?, context?)

Puts an item in the player's bag and saves it right away. Items with the same metadata stack into one slot; items with a unique key (for example durability or serial_number) get their own slot each.

lua
local ok, reason, info = exports.jrs_inventory:addItem(source, 'bread', 2)
if not ok then
    print(('could not give bread: %s'):format(reason))
    return
end
print('new stack id', info.itemId)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name from the jrs_items table.
countnumberWhole number above zero.
metadatatableData stored on the item, such as { durability = 100 }.
contexttable|string{ sourceResource = 'name' } or a plain resource name. Used for logs. Defaults to the calling resource.
Returnsboolean, string, tableok, reason, and { item, label, amount, itemId }.
Server

addItemSync

#
exports.jrs_inventory:addItemSync(source, itemName, count, metadata?, sourceResource?)

The function that addItem calls under the hood. Same result, but the last argument is a plain resource name string.

lua
local ok = exports.jrs_inventory:addItemSync(source, 'water', 1, nil, 'jrs_fishing')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
countnumberAmount to add.
metadatatableItem metadata.
sourceResourcestringName written in the logs.
Returnsboolean, string, tableok, reason, data.
Server

jrs_inventory:server:hook:itemAdded

#
AddEventHandler('jrs_inventory:server:hook:itemAdded', function(payload) end)

Fires after an item lands in a bag through the item API. Payload: source, item, amount, itemId, metadata, sourceResource.

lua
AddEventHandler('jrs_inventory:server:hook:itemAdded', function(p)
    if p.item == 'goldbar' then print(('player %s got %s gold bars'):format(p.source, p.amount)) end
end)
Server

subItem

#
exports.jrs_inventory:subItem(source, itemName, count, context?)

Removes an amount of an item, taking from as many stacks as it needs. If the player has too few, nothing is removed.

lua
local ok, reason = exports.jrs_inventory:subItem(source, 'wood', 5)
if not ok then
    TriggerClientEvent('jrsCore:notify', source, 'Lumber', 'You need 5 wood', 'bag', 3000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
countnumberAmount to remove.
contexttable|stringCalling resource for logs.
Returnsboolean, string, tableok, reason (not_enough, not_found ...), and { item, label, amount, metadata }.
Server

subItemSync

#
exports.jrs_inventory:subItemSync(source, itemName, count, sourceResource?)

Direct form of subItem with a plain resource name as the last argument.

lua
exports.jrs_inventory:subItemSync(source, 'coal', 1, 'jrs_mining')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
countnumberAmount to remove.
sourceResourcestringName written in the logs.
Returnsboolean, string, tableok, reason, data.
Server

subItemByID

#
exports.jrs_inventory:subItemByID(source, itemId, count, context?)

Removes from one exact stack. Use it when the player picked a specific item, for example a tool with its own durability.

lua
exports.jrs_inventory:subItemByID(source, data.itemId, 1)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberThe stack id (itemId field of an inventory entry).
countnumberAmount to remove from that stack.
contexttable|stringCalling resource for logs.
Returnsboolean, string, tableok, reason, data.
Server

jrs_inventory:server:hook:itemRemoved

#
AddEventHandler('jrs_inventory:server:hook:itemRemoved', function(payload) end)

Fires after subItem takes items. Payload: source, item, amount, metadata, sourceResource.

lua
AddEventHandler('jrs_inventory:server:hook:itemRemoved', function(p)
    print(p.source, 'lost', p.amount, p.item)
end)
Server

InventoryTransaction

#
exports.jrs_inventory:InventoryTransaction(source, operations, context?)

Runs up to 64 add and remove steps as one unit. Every removal is checked first; if any step fails, the steps already done are reversed. Good for crafting and shop swaps.

lua
local ok, reason = exports.jrs_inventory:InventoryTransaction(source, {
    { type = 'remove', item = 'iron', amount = 2 },
    { type = 'remove', item = 'wood', amount = 1 },
    { type = 'add', item = 'hatchet', amount = 1, metadata = { durability = 100 } },
}, { owner = 'jrs_crafting' })
ArgumentTypeMeaning
sourcenumberPlayer server id.
operationstableList of { type = 'add' or 'remove', item = name, amount = n, metadata? }.
contexttable{ owner = 'resource', id = 'custom-id' }.
Returnsboolean, string, tableok, reason, and { id, executed } on success or { index, details, rollbackErrors } on failure.
Server

jrs_inventory:server:hook:transactionCommitted

#
AddEventHandler('jrs_inventory:server:hook:transactionCommitted', function(payload) end)

Fires when an InventoryTransaction finishes. A failed one fires transactionRolledBack with the same payload: source, id, owner, reason, operations, result.

lua
AddEventHandler('jrs_inventory:server:hook:transactionRolledBack', function(p)
    print('tx failed', p.id, p.reason)
end)

Reading The Bag#

Server

getItemCount

#
exports.jrs_inventory:getItemCount(source, itemName)

Total amount of an item across all of the player's stacks. The name match ignores case.

lua
if exports.jrs_inventory:getItemCount(source, 'lockpick') < 1 then return end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
ReturnsnumberThe total, 0 when the player has none.
Server

getUserInventory

#
exports.jrs_inventory:getUserInventory(source)

The player's loaded item list. Each entry has itemId, item, label, count, metaData and slot. getUserInventoryItems is the same function under a second name.

lua
for _, entry in pairs(exports.jrs_inventory:getUserInventoryItems(source) or {}) do
    print(entry.item, entry.count, entry.slot)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable|nilList of item entries, or nil when the bag is not loaded.
Server

jrs_inventory:server:clearInventoryCache

#
TriggerEvent('jrs_inventory:server:clearInventoryCache', source)

Drops the cached bag of a player so it is read again from the database. Only works from another server resource, never from a client.

lua
TriggerEvent('jrs_inventory:server:clearInventoryCache', source)
Server

getItemById

#
exports.jrs_inventory:getItemById(source, itemId)

Finds one stack in the player's bag by its id.

lua
local entry = exports.jrs_inventory:getItemById(source, itemId)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
Returnstable|nilThe entry, or nil if the player does not hold it.
Server

getInventoryTotalWeight

#
exports.jrs_inventory:getInventoryTotalWeight(source)

Current weight of everything in the bag.

lua
local kg = exports.jrs_inventory:getInventoryTotalWeight(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberWeight in kg.
Server

GetMaxWeight

#
exports.jrs_inventory:GetMaxWeight(source)

How much the player may carry. Reads the carryKg perk first, then jrs_core's carry capacity, then Config.Max_Items (50 by default).

lua
local limit = exports.jrs_inventory:GetMaxWeight(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberLimit in kg.
Server

GetFreeWeight

#
exports.jrs_inventory:GetFreeWeight(source)

Space left in the bag.

lua
local free, max, used = exports.jrs_inventory:GetFreeWeight(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsnumber, number, numberfree kg, max kg, current kg.
Server

GetMaxWeapons

#
exports.jrs_inventory:GetMaxWeapons(source)

Number of weapons the player may hold. Uses the weapon-slot perk, and a job limit from Config.WeaponLimitByJob when that one is higher.

lua
local slots = exports.jrs_inventory:GetMaxWeapons(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberWeapon slot count.

Space And Limits#

Server

canCarryItem

#
exports.jrs_inventory:canCarryItem(source, itemName, amount)

Weight-only test against GetMaxWeight. It ignores the MaxOwnedItems cap; use canAcquireItem or getCarryInfo for that.

lua
if not exports.jrs_inventory:canCarryItem(source, 'stone', 10) then
    TriggerClientEvent('jrsCore:notify', source, 'Mining', 'Your bag is full', 'bag', 3000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
amountnumberAmount you plan to add.
Returnsbooleantrue when it fits.
Server

getCarryInfo

#
exports.jrs_inventory:getCarryInfo(source, itemName, amount)

Same check as canCarryItem, plus the numbers behind it and the per-item ownership cap.

lua
local info = exports.jrs_inventory:getCarryInfo(source, 'gold_nugget', 3)
if not info.canCarry then print(info.reason, info.currentWeight, info.maxWeight) end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
amountnumberAmount you plan to add.
Returnstable{ canCarry, reason, currentWeight, addedWeight, maxWeight }. reason is ok, overweight, item_limit_reached, item_not_found or invalid_source.
Server

canAcquireItem

#
exports.jrs_inventory:canAcquireItem(source, itemName, amount)

Checks only the ownership cap from Config.MaxOwnedItems, not weight.

lua
local allowed = exports.jrs_inventory:canAcquireItem(source, 'fishing_rod', 1)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
amountnumberAmount you plan to add.
Returnsbooleantrue when the item has no cap or the player stays under it.
Server

isNoTransferItem

#
exports.jrs_inventory:isNoTransferItem(itemName)

Tells you if an item is on the Config.NoTransferItems list, meaning it can only be sold at its job NPC.

lua
if exports.jrs_inventory:isNoTransferItem(name) then return end
ArgumentTypeMeaning
itemNamestringItem name.
Returnsbooleantrue when the item may not be given or traded.

Outside Switches#

Other JRS resources steer the bag through state-bag keys on the player. jrs_inventory only reads them:

Key Set by Effect in the inventory
jrsPerks.carryKg jrs_core level perks Replaces the weight limit
jrsPerks.weaponSlots jrs_core level perks Replaces the weapon slot count
jrsArena jrs_fightarena Bag cannot open, items cannot be used, weapons cannot be equipped
safezoneBlockWeapons jrs_safezone Weapons cannot be equipped
lua
-- client: is the player inside a fight arena?
local inArena = LocalPlayer.state.jrsArena == true

Usable Items#

Server

RegisterUsableItem

#
exports.jrs_inventory:RegisterUsableItem(itemName, callback)

Links a function to an item so the Use button and the item wheel run it. The item is marked usable even if the database row says otherwise. Your callback does not remove the item; call subItemByID yourself.

lua
exports.jrs_inventory:RegisterUsableItem('canteen', function(data)
    exports.jrs_inventory:subItemByID(data.source, data.itemId, 1)
    TriggerClientEvent('jrs_metabolism:drink', data.source, 40)
end)
ArgumentTypeMeaning
itemNamestringItem name.
callbackfunctionGets one table: { source, item, label, limit, itemId, metaData, args }.
Server

WheelItemInfo

#
exports.jrs_inventory:WheelItemInfo(itemName)

Describes an item for the native item wheel in jrs_core.

lua
local info = exports.jrs_inventory:WheelItemInfo('Bread')
ArgumentTypeMeaning
itemNamestringItem name, any casing.
Returnstable|nil{ item, category, usable, hasCallback }, or nil for an unknown item.
Server

UseItemFromWheel

#
exports.jrs_inventory:UseItemFromWheel(source, itemName)

Uses the first matching stack, with the same checks as the bag (usable flag, broken items).

lua
local used = exports.jrs_inventory:UseItemFromWheel(source, 'bread')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemNamestringItem name.
Returnsbooleantrue only when a registered callback ran.

Metadata And Durability#

Server

getMetadata

#
exports.jrs_inventory:getMetadata(source, itemId)

Full metadata table of one stack.

lua
local meta = exports.jrs_inventory:getMetadata(source, itemId) or {}
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
Returnstable|nilMetadata copy, or nil.
Server

getMetaTypeById

#
exports.jrs_inventory:getMetaTypeById(source, itemId, key)

Reads a single metadata key from one stack.

lua
local owner = exports.jrs_inventory:getMetaTypeById(source, itemId, 'owner')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
keystringMetadata key.
ReturnsanyThe value, or nil.
Server

setMetadata

#
exports.jrs_inventory:setMetadata(source, itemId, metadata, replace?)

Merges new keys into a stack's metadata, or swaps the whole table when replace is true.

lua
exports.jrs_inventory:setMetadata(source, itemId, { engraving = 'J.R.' })
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
metadatatableKeys to write.
replacebooleantrue to overwrite instead of merge.
Returnsboolean, table|stringok, then the new metadata or a reason such as not_found.
Server

setMetadataValue

#
exports.jrs_inventory:setMetadataValue(source, itemId, key, value)

Writes one key. Keys are limited to 64 characters.

lua
exports.jrs_inventory:setMetadataValue(source, itemId, 'charges', 3)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
keystringMetadata key.
valueanyNew value.
Returnsboolean, table|stringok, then the new metadata or a reason.
Server

removeMetadataValue

#
exports.jrs_inventory:removeMetadataValue(source, itemId, key)

Deletes one key from a stack's metadata.

lua
exports.jrs_inventory:removeMetadataValue(source, itemId, 'engraving')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
keystringMetadata key.
Returnsboolean, table|stringok, then the new metadata or a reason.
Server

setDurability

#
exports.jrs_inventory:setDurability(source, itemId, durability)

Sets durability, kept between DurabilityMin and DurabilityMax from the config (0 to 100). An item at 0 cannot be used.

lua
exports.jrs_inventory:setDurability(source, itemId, 100)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
durabilitynumberNew value.
Returnsboolean, table|stringok, then the new metadata or a reason.
Server

damageItem

#
exports.jrs_inventory:damageItem(source, itemId, amount)

Lowers durability by an amount. Call it each time a tool is used.

lua
local ok, left, broken = exports.jrs_inventory:damageItem(source, data.itemId, 5)
if broken then
    TriggerClientEvent('jrsCore:notify', source, 'Mining', 'Your pickaxe broke', 'bag', 3000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
amountnumberPoints to remove, 0 or more.
Returnsboolean, number, booleanok, new durability, and true when the item just broke. On failure: false and a reason.
Server

repairItem

#
exports.jrs_inventory:repairItem(source, itemId, amount?)

Raises durability. Without an amount the item goes back to full.

lua
exports.jrs_inventory:repairItem(source, itemId)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberStack id.
amountnumberPoints to add.
Returnsboolean, numberok and the new durability, or false and a reason.

Item Definitions And Labels#

Server

getItemLabel

#
exports.jrs_inventory:getItemLabel(itemName)

Reads the label column straight from the jrs_items table.

lua
local label = exports.jrs_inventory:getItemLabel('bread')
ArgumentTypeMeaning
itemNamestringItem name.
ReturnsstringThe label, or the item name when no row matches.
Server

GetItemLabel

#
exports.jrs_inventory:GetItemLabel(playerSource, itemName)

Label in the player's chosen language (for example Arabic when the player picked it). Uses the cache, no database call.

lua
local label = exports.jrs_inventory:GetItemLabel(source, 'bread')
ArgumentTypeMeaning
playerSourcenumberPlayer whose language is used.
itemNamestringItem name.
ReturnsstringTranslated label.
Server

GetItemLabelEnglish

#
exports.jrs_inventory:GetItemLabelEnglish(itemName)

The English label whatever the player's language. Handy to tell a stock name from a custom name an owner typed.

lua
local en = exports.jrs_inventory:GetItemLabelEnglish('bread')
ArgumentTypeMeaning
itemNamestringItem name.
ReturnsstringEnglish label.
Server

GetItemDescription

#
exports.jrs_inventory:GetItemDescription(playerSource, itemName)

Item description in the player's language.

lua
local text = exports.jrs_inventory:GetItemDescription(source, 'bread')
ArgumentTypeMeaning
playerSourcenumberPlayer whose language is used.
itemNamestringItem name.
ReturnsstringDescription text.
Server

getItemNames

#
exports.jrs_inventory:getItemNames()

Every row of the jrs_items table. preload_itemtable and check_itemtable run the same query and return the same rows.

lua
for _, row in ipairs(exports.jrs_inventory:getItemNames()) do
    print(row.item, row.label, row.limit)
end
ReturnstableList of item rows.
Server

reloadItemTable

#
exports.jrs_inventory:reloadItemTable()

Reloads item definitions from the database into the caches used for adding items and for the client. Run it after you insert new rows in jrs_items.

lua
MySQL.insert.await('INSERT INTO jrs_items (item, label, `limit`) VALUES (?, ?, ?)', { 'apple_pie', 'Apple Pie', 0.3 })
exports.jrs_inventory:reloadItemTable()
Returnsbooleanfalse when the table came back empty.
Server

reloadItemDefinitions

#
exports.jrs_inventory:reloadItemDefinitions()

Same idea as the /reloaditems admin command: rebuilds the item and weapon lookups from the database.

lua
exports.jrs_inventory:reloadItemDefinitions()
ReturnsbooleanAlways true.

Weapons#

Server

createWeaponOwned

#
exports.jrs_inventory:createWeaponOwned(source, weaponName, ammo?, components?, callback?, context?)

The preferred way to give a weapon. Every new weapon gets a serial number, and the callback always runs, on success or failure.

lua
exports.jrs_inventory:createWeaponOwned(source, 'WEAPON_REVOLVER_CATTLEMAN', 24, {}, function(ok, reason, data)
    if ok then
        print('serial', data.serial_number)
    else
        print('weapon failed', reason) -- busy, invalid_weapon, player_not_found ...
    end
end, { customName = 'Sheriff Revolver' })
ArgumentTypeMeaning
sourcenumberPlayer server id.
weaponNamestringWeapon name like WEAPON_REVOLVER_CATTLEMAN. Casing does not matter.
ammonumber|tableA number fills the matching ammo type (AMMO_REVOLVER, AMMO_RIFLE ...). A table like { AMMO_PISTOL = 12 } is used as is.
componentstableComponent names to attach.
callbackfunctionfunction(ok, reason, data). data holds weapon, slot, ammo, serial_number, stolen.
contexttable|stringResource name, or { sourceResource, noBreak, stolen, forcedComponents, packageName, customName }.
Returnsbooleanfalse when it failed straight away; the callback has the final answer.
Server

createWeapon

#
exports.jrs_inventory:createWeapon(source, weaponName, ammo?, components?, context?)

Older fire-and-forget form. It queues the weapon and returns at once, with no way to learn if it worked.

lua
exports.jrs_inventory:createWeapon(source, 'WEAPON_MELEE_KNIFE')
ArgumentTypeMeaning
sourcenumberPlayer server id.
weaponNamestringWeapon name.
ammonumber|tableAmmo as in createWeaponOwned.
componentstableComponent names.
contexttable|stringCalling resource for logs.
ReturnsbooleanAlways true.
Server

subWeapon

#
exports.jrs_inventory:subWeapon(source, weaponId, callback?, context?)

Takes a weapon away from its owner.

lua
exports.jrs_inventory:subWeapon(source, weaponId, function(ok, reason)
    if not ok then print('could not remove weapon', reason) end
end)
ArgumentTypeMeaning
sourcenumberOwner's server id.
weaponIdnumberRow id in jrs_weaponloadout.
callbackfunctionfunction(ok, reason, data).
contexttable|stringCalling resource for logs.
ReturnsbooleanAlways true; read the callback for the result.
Server

giveWeapon

#
exports.jrs_inventory:giveWeapon(source, weaponId, target)

Moves a weapon from one player to another, with the same checks as a hand-over in the bag (slots, ownership).

lua
exports.jrs_inventory:giveWeapon(source, weaponId, targetId)
ArgumentTypeMeaning
sourcenumberCurrent owner.
weaponIdnumberWeapon row id.
targetnumberPlayer who receives it.
Server

getWeaponsMe

#
exports.jrs_inventory:getWeaponsMe(source)

All weapon rows of the active character from jrs_weaponloadout.

lua
for _, w in ipairs(exports.jrs_inventory:getWeaponsMe(source)) do
    print(w.id, w.name, w.serial_number)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnstableList of rows, empty when no character is loaded.
Server

GetWeaponTable

#
exports.jrs_inventory:GetWeaponTable()

The weapon list from config/weapons.lua, each entry { item, label }. preload_weapontable returns the same list.

lua
local weapons = exports.jrs_inventory:GetWeaponTable()
ReturnstableWeapon definitions.
Server

syncWeaponAmmo

#
exports.jrs_inventory:syncWeaponAmmo(source, weaponId, ammoTable, ammoKey?, exactTotal?, weaponHash?)

Saves a new ammo table for a weapon and pushes it to the player's client. Older save packets from the client are ignored after this call.

lua
exports.jrs_inventory:syncWeaponAmmo(source, weaponId, { AMMO_REVOLVER = 30 }, 'AMMO_REVOLVER')
ArgumentTypeMeaning
sourcenumberPlayer server id.
weaponIdnumberWeapon row id.
ammoTabletableAmmo by type, like { AMMO_REVOLVER = 30 }.
ammoKeystringAmmo type the client should load.
exactTotalnumberExact rounds to put in the weapon.
weaponHashnumberWeapon hash on the client.
Returnsbooleanfalse when the player or weapon is invalid.
Server

setWeaponCondition

#
exports.jrs_inventory:setWeaponCondition(source, weaponId, condition)

Sets how dirty or worn a weapon is, from 0 to 100.

lua
exports.jrs_inventory:setWeaponCondition(source, weaponId, 0)
ArgumentTypeMeaning
sourcenumberOwner's server id.
weaponIdnumberWeapon row id.
conditionnumberNew level, clamped to 0..100.
Returnsboolean, stringok and success, or false with weapon_not_owned, player_not_loaded or invalid_request.
Server

jrs_inventory:server:setWeaponCondition

#
TriggerEvent('jrs_inventory:server:setWeaponCondition', source, weaponId, condition, callback?)

Event form of setWeaponCondition for other server resources. The callback gets (ok, reason).

lua
TriggerEvent('jrs_inventory:server:setWeaponCondition', source, weaponId, 100, function(ok, reason)
    print('clean result', ok, reason)
end)
Client

jrs_inventory:weaponsReady

#
AddEventHandler('jrs_inventory:weaponsReady', function() end)

Fires after the character's weapons are loaded and put back in the bag. A safe moment to check what the player carries.

lua
AddEventHandler('jrs_inventory:weaponsReady', function()
    print('weapons loaded')
end)

Storages#

Storages are rows in the jrs_inventory_storage table. Use any id string you like (up to 190 characters); the id 0 points to the player's own personal stash.

Server

createstorage

#
exports.jrs_inventory:createstorage(source, id, size)

Creates the storage row if it does not exist yet. Calling it again for the same id does nothing.

lua
exports.jrs_inventory:createstorage(source, 'jrs_stash:valentine_bank', 200)
ArgumentTypeMeaning
sourcenumberA player online now; needed to resolve the character.
idstringStorage id.
sizenumberWeight limit.
Server

updatestorage

#
exports.jrs_inventory:updatestorage(source, id, size)

Changes the weight limit of an existing storage.

lua
exports.jrs_inventory:updatestorage(source, 'jrs_stash:valentine_bank', 400)
ArgumentTypeMeaning
sourcenumberA player online now.
idstringStorage id.
sizenumberNew limit.
Server

openstorage

#
exports.jrs_inventory:openstorage(source, id, label?)

Opens a storage window next to the player's bag. Only one player may have a given storage open at a time.

lua
exports.jrs_inventory:openstorage(source, 'jrs_stash:valentine_bank', { title = { en = 'Bank Box', ar = 'صندوق البنك' } })
ArgumentTypeMeaning
sourcenumberPlayer who opens it.
idstringStorage id.
labelstring|tableWindow title, or { title = 'Wagon Locker', name = 'Thunder' }. Each part may also be { en = ..., ar = ... }.
Server

RegisterCustomStorage

#
exports.jrs_inventory:RegisterCustomStorage(id, config)

Free edition only. Keeps a named definition so OpenCustomStorage knows the title to show.

lua
exports.jrs_inventory:RegisterCustomStorage('chest_valentine', { name = 'Town Chest', limit = 150 })
ArgumentTypeMeaning
idstringStorage id.
configtable{ name, limit, shared, acceptWeapons }. limit defaults to 100.
Returnsboolean, stringtrue, or false with invalid_id.
Server

OpenCustomStorage

#
exports.jrs_inventory:OpenCustomStorage(source, id, info?)

Free edition only. Opens a storage with the title from RegisterCustomStorage.

lua
exports.jrs_inventory:createstorage(source, 'chest_valentine', 150)
exports.jrs_inventory:OpenCustomStorage(source, 'chest_valentine')
ArgumentTypeMeaning
sourcenumberPlayer server id.
idstringStorage id.
infostring|tableTitle to use instead of the registered name.
Returnsbooleanfalse for a bad player or id.
Server

GetRegisteredStorages

#
exports.jrs_inventory:GetRegisteredStorages()

Free edition only. Every definition added with RegisterCustomStorage, keyed by id.

lua
local list = exports.jrs_inventory:GetRegisteredStorages()
Returnstable{ [id] = { name, limit, acceptWeapons, shared } }.

RegisterCustomStorage only keeps the definition in memory; it never writes the database row. Run createstorage once with an online player's id before the first open, otherwise no window appears.

Every deposit and withdrawal passes through the two events below, so a resource can guard its own lockers without touching jrs_inventory.

Server

jrs_inventory:server:storagePermission

#
AddEventHandler('jrs_inventory:server:storagePermission', function(source, storageId, direction, data, reply) end)

Asked before every storage move. Call reply(false, reason, message) to refuse it; stay silent to allow. direction is deposit or withdraw, and data holds kind (item or weapon) with the item or weapon details.

lua
AddEventHandler('jrs_inventory:server:storagePermission', function(src, id, direction, data, reply)
    if id:find('^jrs_stash:police') and direction == 'withdraw' and not isLawman(src) then
        reply(false, 'not_lawman', 'Only lawmen may take from this locker')
    end
end)
Server

jrs_inventory:server:storageTransaction

#
AddEventHandler('jrs_inventory:server:storageTransaction', function(source, storageId, direction, data) end)

Fires after a storage move went through. data holds kind, item or weapon, label, amount, and itemId / weaponId.

lua
AddEventHandler('jrs_inventory:server:storageTransaction', function(src, id, direction, data)
    print(src, direction, data.amount, data.label, 'in', id)
end)

Locks And Hooks#

Server

AcquireInventoryLock

#
exports.jrs_inventory:AcquireInventoryLock(source, key?, ttlMs?, owner?)

Reserves a named lock on a player so two of your actions cannot overlap. The lock frees itself after ttlMs (250 to 30000, default 10000).

lua
if not exports.jrs_inventory:AcquireInventoryLock(source, 'butcher_sell', 5000) then return end
-- sell logic
exports.jrs_inventory:ReleaseInventoryLock(source, 'butcher_sell')
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringLock name, default inventory.
ttlMsnumberLifetime in ms.
ownerstringOwner tag, default the calling resource.
Returnsboolean, stringtrue, or false with locked / invalid_source.
Server

ReleaseInventoryLock

#
exports.jrs_inventory:ReleaseInventoryLock(source, key?, owner?, force?)

Frees a lock. Only the owner may free it unless force is true.

lua
exports.jrs_inventory:ReleaseInventoryLock(source, 'butcher_sell')
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringLock name.
ownerstringOwner tag.
forcebooleanFree it even when someone else owns it.
Returnsbooleantrue when the lock is gone.
Server

IsInventoryLocked

#
exports.jrs_inventory:IsInventoryLocked(source, key?)

Checks if a lock is held right now.

lua
local busy = exports.jrs_inventory:IsInventoryLocked(source, 'transaction')
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringLock name.
Returnsbooleantrue while held.
Server

RegisterInventoryHook

#
exports.jrs_inventory:RegisterInventoryHook(eventName, name, callback)

Adds a function that runs when the inventory emits a hook: itemAdded, itemRemoved, transactionCommitted, transactionRolledBack or tradeCompleted.

lua
-- Inside jrs_inventory only; see the paragraph below.
exports.jrs_inventory:RegisterInventoryHook('itemAdded', 'audit', function(p)
    print(p.source, p.item, p.amount)
end)
ArgumentTypeMeaning
eventNamestringHook name.
namestringYour key for it; a second call with the same key replaces the first.
callbackfunctionGets the payload table.
Returnsbooleanfalse when the callback is not a plain function.

A function handed over through an export from another resource arrives in jrs_inventory as a reference table, not a plain function. That is why RegisterInventoryHook and RegisterTradeValidator return false when called from outside. In your own resource, listen to the jrs_inventory:server:hook:<name> events shown next to addItem, subItem, InventoryTransaction and RegisterTradeValidator.

Player Trades#

Server

RegisterTradeValidator

#
exports.jrs_inventory:RegisterTradeValidator(name, callback)

Lets code block a trade. The callback gets (stage, context) and returns false, reason to stop it.

lua
exports.jrs_inventory:RegisterTradeValidator('no_gold', function(stage, ctx)
    for _, it in pairs(ctx.items) do
        if it.item == 'goldbar' then return false, 'gold_blocked' end
    end
    return true
end)
ArgumentTypeMeaning
namestringValidator key, up to 80 characters.
callbackfunctionfunction(stage, context); context has tradeKey, seller, buyer, price, status, items, weapons.
Returnsboolean, stringtrue, or false with invalid_callback / invalid_name.
Server

jrs_inventory:server:tradeCompleted

#
AddEventHandler('jrs_inventory:server:tradeCompleted', function(context) end)

Fires once a trade is paid and delivered. The context has tradeKey, seller, buyer, price, items, weapons and sellerPaid. The same table also goes out as jrs_inventory:server:hook:tradeCompleted.

lua
AddEventHandler('jrs_inventory:server:tradeCompleted', function(ctx)
    print(('trade %s: %s paid $%s'):format(ctx.tradeKey, ctx.buyer, ctx.price))
end)
Server

GetTradeSession

#
exports.jrs_inventory:GetTradeSession(source)

The trade a player is in right now.

lua
local trade = exports.jrs_inventory:GetTradeSession(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable|nilSame shape as the validator context, or nil.
Server

IsTrading

#
exports.jrs_inventory:IsTrading(source)

Quick yes or no for an open trade on the server.

lua
if exports.jrs_inventory:IsTrading(source) then return end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleantrue during a trade.
Client

StartTrade

#
exports.jrs_inventory:StartTrade(targetServerId)

Closes the bag and sends a trade invite to another player.

lua
exports.jrs_inventory:StartTrade(GetPlayerServerId(closestPlayer))
ArgumentTypeMeaning
targetServerIdnumberServer id of the other player.
Returnsbooleanfalse for an invalid target.
Client

CanTradeWith

#
exports.jrs_inventory:CanTradeWith(targetServerId)

Checks that the other player is online, alive in the world and close enough.

lua
local ok, why = exports.jrs_inventory:CanTradeWith(targetId)
ArgumentTypeMeaning
targetServerIdnumberServer id of the other player.
Returnsboolean, number|stringtrue and the distance, or false with invalid_target, offline, invalid_ped or too_far.
Client

IsTradeOpen

#
exports.jrs_inventory:IsTradeOpen()

true while the trade window is on screen.

lua
if exports.jrs_inventory:IsTradeOpen() then return end
ReturnsbooleanWindow state.
Client

IsTrading

#
exports.jrs_inventory:IsTrading()

true when the window is open or a trade is still pending.

lua
local busy = exports.jrs_inventory:IsTrading()
ReturnsbooleanTrade state.
Client

GetTradeSession

#
exports.jrs_inventory:GetTradeSession()

The last trade state the server sent to this client.

lua
local state = exports.jrs_inventory:GetTradeSession()
Returnstable|nilTrade payload, or nil.
Client

CancelTrade

#
exports.jrs_inventory:CancelTrade()

Asks the server to cancel the current trade.

lua
exports.jrs_inventory:CancelTrade()
ReturnsbooleanAlways true.
Client

ReopenTrade

#
exports.jrs_inventory:ReopenTrade()

Asks the server to show the current trade window again.

lua
exports.jrs_inventory:ReopenTrade()
ReturnsbooleanAlways true.

The escrow exports tradeGetSnapshot, tradeCanReceive, tradeReserveOffer, tradeReturnEscrow and tradeDeliverEscrow are used by the trade module itself. They answer unauthorized to any other resource.

Admin And Logs#

Server

CloseInv

#
exports.jrs_inventory:CloseInv(source)

Closes the bag on a player's screen. The same close is reachable as the event jrs_inventory:CloseInv (alias jrs_inventory:closeInventory): TriggerEvent('jrs_inventory:CloseInv', target) from server code, or TriggerEvent('jrs_inventory:CloseInv') on the client before you open your own menu. A target id is only honoured from server code.

lua
exports.jrs_inventory:CloseInv(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Server

OpenPlayerInventoryAdmin

#
exports.jrs_inventory:OpenPlayerInventoryAdmin(adminSource, targetId)

Opens another player's bag for a staff member to look through. If both ids are the same, it just opens the admin's own bag.

lua
exports.jrs_inventory:OpenPlayerInventoryAdmin(source, tonumber(args[1]))
ArgumentTypeMeaning
adminSourcenumberStaff member's server id.
targetIdnumberPlayer to inspect.
Returnsbooleanfalse when the target is offline.
Server

sendInventoryLog

#
exports.jrs_inventory:sendInventoryLog(category, title, playerId, fields, options?)

Sends an entry to the inventory Discord log channel set for that category in config/config_logs.lua.

lua
exports.jrs_inventory:sendInventoryLog('Items', 'Reward Paid', source, { item = 'goldbar', amount = 1 })
ArgumentTypeMeaning
categorystringLog category, for example Items or Storage.
titlestringEntry title.
playerIdnumberPlayer the entry is about.
fieldstableKey and value pairs to show.
optionstableExtra display options.
Returnsbooleanfalse when the category has no webhook.

Client Exports#

Client

IsInventoryOpen

#
exports.jrs_inventory:IsInventoryOpen()

true while the bag or a storage window is really on screen. Live server build only.

lua
if exports.jrs_inventory:IsInventoryOpen() then return end
ReturnsbooleanWindow state.
Client

IsBagWeaponHash

#
exports.jrs_inventory:IsBagWeaponHash(hash)

true when the hash belongs to a weapon row in the player's bag. Tools and scenario props return false.

lua
local _, held = GetCurrentPedWeapon(PlayerPedId(), true, 0, true)
local isGun = exports.jrs_inventory:IsBagWeaponHash(held)
ArgumentTypeMeaning
hashnumberWeapon hash.
ReturnsbooleanWhether it is a real owned weapon.
Client

UnequipAllWeapons

#
exports.jrs_inventory:UnequipAllWeapons(syncServer?)

Puts every equipped weapon back in the bag. The server is told unless you pass false. From the server, send jrs_inventory:client:unequipAllWeapons to the player for the same result, for example on entering a safe area.

lua
exports.jrs_inventory:UnequipAllWeapons()
ArgumentTypeMeaning
syncServerbooleanfalse to skip the server update.