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#
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.
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)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name from the jrs_items table. |
count | number | Whole number above zero. |
metadata | table | Data stored on the item, such as { durability = 100 }. |
context | table|string | { sourceResource = 'name' } or a plain resource name. Used for logs. Defaults to the calling resource. |
{ item, label, amount, itemId }.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.
local ok = exports.jrs_inventory:addItemSync(source, 'water', 1, nil, 'jrs_fishing')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
count | number | Amount to add. |
metadata | table | Item metadata. |
sourceResource | string | Name written in the logs. |
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.
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)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.
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| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
count | number | Amount to remove. |
context | table|string | Calling resource for logs. |
not_enough, not_found ...), and { item, label, amount, metadata }.exports.jrs_inventory:subItemSync(source, itemName, count, sourceResource?)Direct form of subItem with a plain resource name as the last argument.
exports.jrs_inventory:subItemSync(source, 'coal', 1, 'jrs_mining')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
count | number | Amount to remove. |
sourceResource | string | Name written in the logs. |
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.
exports.jrs_inventory:subItemByID(source, data.itemId, 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | The stack id (itemId field of an inventory entry). |
count | number | Amount to remove from that stack. |
context | table|string | Calling resource for logs. |
AddEventHandler('jrs_inventory:server:hook:itemRemoved', function(payload) end)Fires after subItem takes items. Payload: source, item, amount, metadata, sourceResource.
AddEventHandler('jrs_inventory:server:hook:itemRemoved', function(p)
print(p.source, 'lost', p.amount, p.item)
end)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.
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' })| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
operations | table | List of { type = 'add' or 'remove', item = name, amount = n, metadata? }. |
context | table | { owner = 'resource', id = 'custom-id' }. |
{ id, executed } on success or { index, details, rollbackErrors } on failure.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.
AddEventHandler('jrs_inventory:server:hook:transactionRolledBack', function(p)
print('tx failed', p.id, p.reason)
end)Reading The Bag#
exports.jrs_inventory:getItemCount(source, itemName)Total amount of an item across all of the player's stacks. The name match ignores case.
if exports.jrs_inventory:getItemCount(source, 'lockpick') < 1 then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
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.
for _, entry in pairs(exports.jrs_inventory:getUserInventoryItems(source) or {}) do
print(entry.item, entry.count, entry.slot)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
TriggerEvent('jrs_inventory:server:clearInventoryCache', source)exports.jrs_inventory:getItemById(source, itemId)Finds one stack in the player's bag by its id.
local entry = exports.jrs_inventory:getItemById(source, itemId)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
exports.jrs_inventory:getInventoryTotalWeight(source)Current weight of everything in the bag.
local kg = exports.jrs_inventory:getInventoryTotalWeight(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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).
local limit = exports.jrs_inventory:GetMaxWeight(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_inventory:GetFreeWeight(source)Space left in the bag.
local free, max, used = exports.jrs_inventory:GetFreeWeight(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
local slots = exports.jrs_inventory:GetMaxWeapons(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
Space And Limits#
exports.jrs_inventory:canCarryItem(source, itemName, amount)Weight-only test against GetMaxWeight. It ignores the MaxOwnedItems cap; use canAcquireItem or getCarryInfo for that.
if not exports.jrs_inventory:canCarryItem(source, 'stone', 10) then
TriggerClientEvent('jrsCore:notify', source, 'Mining', 'Your bag is full', 'bag', 3000)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
amount | number | Amount you plan to add. |
exports.jrs_inventory:getCarryInfo(source, itemName, amount)Same check as canCarryItem, plus the numbers behind it and the per-item ownership cap.
local info = exports.jrs_inventory:getCarryInfo(source, 'gold_nugget', 3)
if not info.canCarry then print(info.reason, info.currentWeight, info.maxWeight) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
amount | number | Amount you plan to add. |
{ canCarry, reason, currentWeight, addedWeight, maxWeight }. reason is ok, overweight, item_limit_reached, item_not_found or invalid_source.exports.jrs_inventory:canAcquireItem(source, itemName, amount)Checks only the ownership cap from Config.MaxOwnedItems, not weight.
local allowed = exports.jrs_inventory:canAcquireItem(source, 'fishing_rod', 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
amount | number | Amount you plan to add. |
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.
if exports.jrs_inventory:isNoTransferItem(name) then return end| Argument | Type | Meaning |
|---|---|---|
itemName | string | Item name. |
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 |
-- client: is the player inside a fight arena?
local inArena = LocalPlayer.state.jrsArena == trueUsable Items#
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.
exports.jrs_inventory:RegisterUsableItem('canteen', function(data)
exports.jrs_inventory:subItemByID(data.source, data.itemId, 1)
TriggerClientEvent('jrs_metabolism:drink', data.source, 40)
end)| Argument | Type | Meaning |
|---|---|---|
itemName | string | Item name. |
callback | function | Gets one table: { source, item, label, limit, itemId, metaData, args }. |
exports.jrs_inventory:WheelItemInfo(itemName)Describes an item for the native item wheel in jrs_core.
local info = exports.jrs_inventory:WheelItemInfo('Bread')| Argument | Type | Meaning |
|---|---|---|
itemName | string | Item name, any casing. |
{ item, category, usable, hasCallback }, or nil for an unknown item.exports.jrs_inventory:UseItemFromWheel(source, itemName)Uses the first matching stack, with the same checks as the bag (usable flag, broken items).
local used = exports.jrs_inventory:UseItemFromWheel(source, 'bread')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemName | string | Item name. |
Metadata And Durability#
exports.jrs_inventory:getMetadata(source, itemId)Full metadata table of one stack.
local meta = exports.jrs_inventory:getMetadata(source, itemId) or {}| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
exports.jrs_inventory:getMetaTypeById(source, itemId, key)Reads a single metadata key from one stack.
local owner = exports.jrs_inventory:getMetaTypeById(source, itemId, 'owner')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
key | string | Metadata key. |
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.
exports.jrs_inventory:setMetadata(source, itemId, { engraving = 'J.R.' })| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
metadata | table | Keys to write. |
replace | boolean | true to overwrite instead of merge. |
not_found.exports.jrs_inventory:setMetadataValue(source, itemId, key, value)Writes one key. Keys are limited to 64 characters.
exports.jrs_inventory:setMetadataValue(source, itemId, 'charges', 3)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
key | string | Metadata key. |
value | any | New value. |
exports.jrs_inventory:removeMetadataValue(source, itemId, key)Deletes one key from a stack's metadata.
exports.jrs_inventory:removeMetadataValue(source, itemId, 'engraving')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
key | string | Metadata key. |
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.
exports.jrs_inventory:setDurability(source, itemId, 100)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
durability | number | New value. |
exports.jrs_inventory:damageItem(source, itemId, amount)Lowers durability by an amount. Call it each time a tool is used.
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| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
amount | number | Points to remove, 0 or more. |
exports.jrs_inventory:repairItem(source, itemId, amount?)Raises durability. Without an amount the item goes back to full.
exports.jrs_inventory:repairItem(source, itemId)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Stack id. |
amount | number | Points to add. |
Item Definitions And Labels#
exports.jrs_inventory:getItemLabel(itemName)Reads the label column straight from the jrs_items table.
local label = exports.jrs_inventory:getItemLabel('bread')| Argument | Type | Meaning |
|---|---|---|
itemName | string | Item name. |
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.
local label = exports.jrs_inventory:GetItemLabel(source, 'bread')| Argument | Type | Meaning |
|---|---|---|
playerSource | number | Player whose language is used. |
itemName | string | Item name. |
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.
local en = exports.jrs_inventory:GetItemLabelEnglish('bread')| Argument | Type | Meaning |
|---|---|---|
itemName | string | Item name. |
exports.jrs_inventory:GetItemDescription(playerSource, itemName)Item description in the player's language.
local text = exports.jrs_inventory:GetItemDescription(source, 'bread')| Argument | Type | Meaning |
|---|---|---|
playerSource | number | Player whose language is used. |
itemName | string | Item name. |
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.
for _, row in ipairs(exports.jrs_inventory:getItemNames()) do
print(row.item, row.label, row.limit)
endexports.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.
MySQL.insert.await('INSERT INTO jrs_items (item, label, `limit`) VALUES (?, ?, ?)', { 'apple_pie', 'Apple Pie', 0.3 })
exports.jrs_inventory:reloadItemTable()exports.jrs_inventory:reloadItemDefinitions()Same idea as the /reloaditems admin command: rebuilds the item and weapon lookups from the database.
exports.jrs_inventory:reloadItemDefinitions()Weapons#
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.
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' })| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
weaponName | string | Weapon name like WEAPON_REVOLVER_CATTLEMAN. Casing does not matter. |
ammo | number|table | A number fills the matching ammo type (AMMO_REVOLVER, AMMO_RIFLE ...). A table like { AMMO_PISTOL = 12 } is used as is. |
components | table | Component names to attach. |
callback | function | function(ok, reason, data). data holds weapon, slot, ammo, serial_number, stolen. |
context | table|string | Resource name, or { sourceResource, noBreak, stolen, forcedComponents, packageName, customName }. |
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.
exports.jrs_inventory:createWeapon(source, 'WEAPON_MELEE_KNIFE')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
weaponName | string | Weapon name. |
ammo | number|table | Ammo as in createWeaponOwned. |
components | table | Component names. |
context | table|string | Calling resource for logs. |
exports.jrs_inventory:subWeapon(source, weaponId, callback?, context?)Takes a weapon away from its owner.
exports.jrs_inventory:subWeapon(source, weaponId, function(ok, reason)
if not ok then print('could not remove weapon', reason) end
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Owner's server id. |
weaponId | number | Row id in jrs_weaponloadout. |
callback | function | function(ok, reason, data). |
context | table|string | Calling resource for logs. |
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).
exports.jrs_inventory:giveWeapon(source, weaponId, targetId)| Argument | Type | Meaning |
|---|---|---|
source | number | Current owner. |
weaponId | number | Weapon row id. |
target | number | Player who receives it. |
exports.jrs_inventory:getWeaponsMe(source)All weapon rows of the active character from jrs_weaponloadout.
for _, w in ipairs(exports.jrs_inventory:getWeaponsMe(source)) do
print(w.id, w.name, w.serial_number)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_inventory:GetWeaponTable()The weapon list from config/weapons.lua, each entry { item, label }. preload_weapontable returns the same list.
local weapons = exports.jrs_inventory:GetWeaponTable()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.
exports.jrs_inventory:syncWeaponAmmo(source, weaponId, { AMMO_REVOLVER = 30 }, 'AMMO_REVOLVER')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
weaponId | number | Weapon row id. |
ammoTable | table | Ammo by type, like { AMMO_REVOLVER = 30 }. |
ammoKey | string | Ammo type the client should load. |
exactTotal | number | Exact rounds to put in the weapon. |
weaponHash | number | Weapon hash on the client. |
exports.jrs_inventory:setWeaponCondition(source, weaponId, condition)Sets how dirty or worn a weapon is, from 0 to 100.
exports.jrs_inventory:setWeaponCondition(source, weaponId, 0)| Argument | Type | Meaning |
|---|---|---|
source | number | Owner's server id. |
weaponId | number | Weapon row id. |
condition | number | New level, clamped to 0..100. |
success, or false with weapon_not_owned, player_not_loaded or invalid_request.TriggerEvent('jrs_inventory:server:setWeaponCondition', source, weaponId, condition, callback?)Event form of setWeaponCondition for other server resources. The callback gets (ok, reason).
TriggerEvent('jrs_inventory:server:setWeaponCondition', source, weaponId, 100, function(ok, reason)
print('clean result', ok, reason)
end)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.
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.
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.
exports.jrs_inventory:createstorage(source, 'jrs_stash:valentine_bank', 200)| Argument | Type | Meaning |
|---|---|---|
source | number | A player online now; needed to resolve the character. |
id | string | Storage id. |
size | number | Weight limit. |
exports.jrs_inventory:updatestorage(source, id, size)Changes the weight limit of an existing storage.
exports.jrs_inventory:updatestorage(source, 'jrs_stash:valentine_bank', 400)| Argument | Type | Meaning |
|---|---|---|
source | number | A player online now. |
id | string | Storage id. |
size | number | New limit. |
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.
exports.jrs_inventory:openstorage(source, 'jrs_stash:valentine_bank', { title = { en = 'Bank Box', ar = 'صندوق البنك' } })| Argument | Type | Meaning |
|---|---|---|
source | number | Player who opens it. |
id | string | Storage id. |
label | string|table | Window title, or { title = 'Wagon Locker', name = 'Thunder' }. Each part may also be { en = ..., ar = ... }. |
exports.jrs_inventory:RegisterCustomStorage(id, config)Free edition only. Keeps a named definition so OpenCustomStorage knows the title to show.
exports.jrs_inventory:RegisterCustomStorage('chest_valentine', { name = 'Town Chest', limit = 150 })| Argument | Type | Meaning |
|---|---|---|
id | string | Storage id. |
config | table | { name, limit, shared, acceptWeapons }. limit defaults to 100. |
invalid_id.exports.jrs_inventory:OpenCustomStorage(source, id, info?)Free edition only. Opens a storage with the title from RegisterCustomStorage.
exports.jrs_inventory:createstorage(source, 'chest_valentine', 150)
exports.jrs_inventory:OpenCustomStorage(source, 'chest_valentine')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
id | string | Storage id. |
info | string|table | Title to use instead of the registered name. |
exports.jrs_inventory:GetRegisteredStorages()Free edition only. Every definition added with RegisterCustomStorage, keyed by id.
local list = exports.jrs_inventory:GetRegisteredStorages(){ [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.
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.
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)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.
AddEventHandler('jrs_inventory:server:storageTransaction', function(src, id, direction, data)
print(src, direction, data.amount, data.label, 'in', id)
end)Locks And Hooks#
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).
if not exports.jrs_inventory:AcquireInventoryLock(source, 'butcher_sell', 5000) then return end
-- sell logic
exports.jrs_inventory:ReleaseInventoryLock(source, 'butcher_sell')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Lock name, default inventory. |
ttlMs | number | Lifetime in ms. |
owner | string | Owner tag, default the calling resource. |
locked / invalid_source.exports.jrs_inventory:ReleaseInventoryLock(source, key?, owner?, force?)Frees a lock. Only the owner may free it unless force is true.
exports.jrs_inventory:ReleaseInventoryLock(source, 'butcher_sell')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Lock name. |
owner | string | Owner tag. |
force | boolean | Free it even when someone else owns it. |
exports.jrs_inventory:IsInventoryLocked(source, key?)Checks if a lock is held right now.
local busy = exports.jrs_inventory:IsInventoryLocked(source, 'transaction')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Lock name. |
exports.jrs_inventory:RegisterInventoryHook(eventName, name, callback)Adds a function that runs when the inventory emits a hook: itemAdded, itemRemoved, transactionCommitted, transactionRolledBack or tradeCompleted.
-- Inside jrs_inventory only; see the paragraph below.
exports.jrs_inventory:RegisterInventoryHook('itemAdded', 'audit', function(p)
print(p.source, p.item, p.amount)
end)| Argument | Type | Meaning |
|---|---|---|
eventName | string | Hook name. |
name | string | Your key for it; a second call with the same key replaces the first. |
callback | function | Gets the payload table. |
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#
exports.jrs_inventory:RegisterTradeValidator(name, callback)Lets code block a trade. The callback gets (stage, context) and returns false, reason to stop it.
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)| Argument | Type | Meaning |
|---|---|---|
name | string | Validator key, up to 80 characters. |
callback | function | function(stage, context); context has tradeKey, seller, buyer, price, status, items, weapons. |
invalid_callback / invalid_name.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.
AddEventHandler('jrs_inventory:server:tradeCompleted', function(ctx)
print(('trade %s: %s paid $%s'):format(ctx.tradeKey, ctx.buyer, ctx.price))
end)exports.jrs_inventory:GetTradeSession(source)The trade a player is in right now.
local trade = exports.jrs_inventory:GetTradeSession(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_inventory:IsTrading(source)Quick yes or no for an open trade on the server.
if exports.jrs_inventory:IsTrading(source) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_inventory:StartTrade(targetServerId)Closes the bag and sends a trade invite to another player.
exports.jrs_inventory:StartTrade(GetPlayerServerId(closestPlayer))| Argument | Type | Meaning |
|---|---|---|
targetServerId | number | Server id of the other player. |
exports.jrs_inventory:CanTradeWith(targetServerId)Checks that the other player is online, alive in the world and close enough.
local ok, why = exports.jrs_inventory:CanTradeWith(targetId)| Argument | Type | Meaning |
|---|---|---|
targetServerId | number | Server id of the other player. |
invalid_target, offline, invalid_ped or too_far.exports.jrs_inventory:IsTradeOpen()true while the trade window is on screen.
if exports.jrs_inventory:IsTradeOpen() then return endexports.jrs_inventory:IsTrading()true when the window is open or a trade is still pending.
local busy = exports.jrs_inventory:IsTrading()exports.jrs_inventory:GetTradeSession()The last trade state the server sent to this client.
local state = exports.jrs_inventory:GetTradeSession()exports.jrs_inventory:CancelTrade()Asks the server to cancel the current trade.
exports.jrs_inventory:CancelTrade()exports.jrs_inventory:ReopenTrade()Asks the server to show the current trade window again.
exports.jrs_inventory:ReopenTrade()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#
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.
exports.jrs_inventory:CloseInv(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
exports.jrs_inventory:OpenPlayerInventoryAdmin(source, tonumber(args[1]))| Argument | Type | Meaning |
|---|---|---|
adminSource | number | Staff member's server id. |
targetId | number | Player to inspect. |
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.
exports.jrs_inventory:sendInventoryLog('Items', 'Reward Paid', source, { item = 'goldbar', amount = 1 })| Argument | Type | Meaning |
|---|---|---|
category | string | Log category, for example Items or Storage. |
title | string | Entry title. |
playerId | number | Player the entry is about. |
fields | table | Key and value pairs to show. |
options | table | Extra display options. |
Client Exports#
exports.jrs_inventory:IsInventoryOpen()true while the bag or a storage window is really on screen. Live server build only.
if exports.jrs_inventory:IsInventoryOpen() then return endexports.jrs_inventory:IsBagWeaponHash(hash)true when the hash belongs to a weapon row in the player's bag. Tools and scenario props return false.
local _, held = GetCurrentPedWeapon(PlayerPedId(), true, 0, true)
local isGun = exports.jrs_inventory:IsBagWeaponHash(held)| Argument | Type | Meaning |
|---|---|---|
hash | number | Weapon hash. |
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.
exports.jrs_inventory:UnequipAllWeapons()| Argument | Type | Meaning |
|---|---|---|
syncServer | boolean | false to skip the server update. |