inventory
Documentation for jrs inventory system
This documentation is for developers who are making scripts for JRS Core Framework
Exports#
These exports are client side only!
These exports are server side only!
Getters#
getUserAmmo#
get all user ammo
sourceintrequiredThe player id
callbackfunctioncallback function syncronous or asyncronous
returntablereturns a table containing all the ammo
exports.jrs_inventory:getUserAmmo(source, callback)canCarryWeapons#
check if player can carry weapons
sourceintrequiredThe player id
amountintrequiredamount of weapons
callbackfunctioncallback function syncronous or asyncronous
weaponNamestring | numberweapon name or hash its needed to check weight since 3.6
returnbooleanreturns true if the player can carry the weapons
exports.jrs_inventory:canCarryWeapons(source, amount,callback, weaponName)getUserWeapon#
get user inventory weapon
sourceintrequiredThe player id
callbackfunctioncallback function syncronous or asyncronous
weaponIdnumberweapon id
returntable{id:number,name:string,propietary:string,used:boolean,desc:string,group:number,source:number,label:string,serial_number:string,custom_label:string,custom_desc:string}
exports.jrs_inventory:getUserWeapon(source, callback,weaponId)getUserInventoryWeapons#
get user inventory weapons
sourceintrequiredThe player id
callbackfunctioncallback function syncronous or asyncronous
returntable{id:number,name:string,propietary:string,used:boolean,desc:string,group:number,source:number,label:string,serial_number:string,custom_label:string,custom_desc:string}
exports.jrs_inventory:getUserInventoryWeapons(source, callback)getWeaponBullets#
get weapon bullets
sourceintrequiredThe player id
weaponIDnumberrequiredweapon id
callbackfunctioncallback function syncronous or asyncronous
returnnumberweapon ammo
exports.jrs_inventory:getWeaponBullets(source,weaponID, callback)getWeaponComponents#
get weapon components
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
callbackfunctioncallback function syncronous or asyncronous
returntablereturns a table containing the weapon components
exports.jrs_inventory:getWeaponComponents(source, weaponId, callback)Setters#
setWeaponCustomDesc#
set weapon custom description
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
descstringrequiredweapon description
cbfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the description was successfully set
exports.jrs_inventory:setWeaponCustomDesc(weaponId, desc, cb)setWeaponCustomLabel#
set weapon custom label
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
labelstringrequiredweapon label
cbfunctioncallback function syncronous or asyncronous
returnbooleanreturnstrue if the label was successfully set
exports.jrs_inventory:setWeaponCustomLabel(weaponId, label, cb)setWeaponSerialNumber#
set weapon serial number
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
serialstringrequiredweapon serial number
cbfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the serial number was successfully set
exports.jrs_inventory:setWeaponSerialNumber(weaponId, serial, cb)subWeapon#
remove weapon from user inventory
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the weapon was successfully removed
exports.jrs_inventory:subWeapon(source, weaponId, callback)giveWeapon#
give weapon to user
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
targetintrequiredtarget id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the weapon was successfully given
exports.jrs_inventory:giveWeapon(source, weaponId, target,callback)createWeapon#
create weapon
sourceintrequiredThe player id
weaponNamestringrequiredweapon name
ammostringrequiredamount of ammo
componentstablerequiredweapon components
compstablerequiredweapon components
callbackfunctioncallback function syncronous or asyncronous
wepidintleave this as nil, this is used internally only
serialstringcustom serial number for weapon
labelstringcustom label for weapon
descstringcustom desc for weapons
returnbooleanif async
exports.jrs_inventory:createWeapon(source, weaponName, ammo, components, comps, callback,serial,label,desc)deleteWeapon#
delete weapon
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanif async
exports.jrs_inventory:deleteWeapon(source, weaponId, callback)addBullets#
add bullets
sourceintrequiredThe player id
bulletTypestringrequiredbullet type
amountnumberrequiredamount of bullets
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the bullets were successfully added
exports.jrs_inventory:addBullets(source, bulletType, amount,callback)subBullets#
remove bullets from weapon
weaponIdnumberrequiredweapon id
bulletTypestringrequiredbullet type
amountnumberrequiredamount of bullets
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the bullets were successfully removed
exports.jrs_inventory:subBullets(weaponId, bulletType, amount,callback)removeAllUserAmmo#
remove all user ammo
sourceintrequiredThe player id
exports.jrs_inventory:removeAllUserAmmo(source)addWeaponComponent#
add a component to a weapon
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
componentstring | numberrequiredcomponent name or hash
categorystring | numberrequiredslot category
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the component was successfully added
exports.jrs_inventory:addWeaponComponent(source, weaponId, component, category, callback)subWeaponComponent#
remove a component from a weapon
sourceintrequiredThe player id
weaponIdnumberrequiredweapon id
componentstring | numberrequiredcomponent name or hash
categorystring | numberrequiredslot category
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the component was successfully removed
exports.jrs_inventory:subWeaponComponent(source, weaponId, component, category, callback)Getters#
canCarryItem#
check if player can carry the item before adding it to the inventory
sourceintrequiredThe player id
itemstringrequiredThe item name
amountintrequiredThe amount of items
callbackfunctionThe callback function syncronous or asyncronous
returnbooleanreturns true if the player can carry the item
exports.jrs_inventory:canCarryItem(source, item, amount, callback)getUserInventoryItems#
gets all the items in the player inventory
sourceintrequiredThe player id
callbackfunctionThe callback function syncronous or asyncronous
returntablereturns a table containing all the items in the inventory
exports.jrs_inventory:getUserInventoryItems(source, callback)getItemCount#
get item amount from player inventory
sourceintrequiredThe player id
callbackfunctioncallback function for syncronous or asyncronous
itemstringrequireditem name
metadatatableitem metadata
percentageintallows to control what items to get, if 0 gets all items with no metadata if meta was not passed if 0 gets items expired, anything above 0 or equal will return those item count
returnintreturns the amount of items in the inventory
exports.jrs_inventory:getItemCount(source, callback, item, metadata, percentage)getItemDB#
get DB item
itemstringrequireditem name
callbackfunctioncallback function asyncronous or syncronous
returntablereturns a table containing item info
exports.jrs_inventory:getItemDB(item, callback)getItemById#
get item by main id
sourceintrequiredThe player id
idintrequireditem id
callbackfunctioncallback function syncronous or asyncronous
returntable{id:number, label:string, name:string, metadata:table, group:number, type:string, count:number, limit:number,canUse:boolean,percenage:integer,description:string,weight:number}
exports.jrs_inventory:getItemById(source, id, callback)getItem#
get item data
sourceintrequiredThe player id
itemstringrequireditem name
callbackfunctioncallback function syncronous or asyncronous
metadatatableitem metadata
percentageintget an item only at a certain percentage, if 0 it gets tems expired if nil gets any item if more than 0 gets any item that equals or is above
returntable{id:number, label:string, name:string, metadata:table, group:number, type:string, count:number, limit:number,canUse:boolean,weight:number,desc:string,percentage:integer}
exports.jrs_inventory:getItem(source, item,callback, metadata,percentage)Setters#
addItem#
add item to user
sourceintrequiredThe player id
itemstringrequireditem name
amountintrequiredamount of item
metadatatableitem metadata
callbackfunctioncallback function syncronous or asyncronous
eventbooleanif true will not trigger the event OnItemCreated
returnbooleanreturns true if the item was successfully added
exports.jrs_inventory:addItem(source, item, amount, metadata, callback,event)subItem#
remove item from user inventory
sourceintrequiredThe player id
itemstringrequireditem name
amountintrequiredamount of item
metadatatableitem metadata
callbackfunctioncallback function syncronous or asyncronous
eventbooleanevent OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event
percentageintallows to control percentage of items to remove, if nil removes any, if 0 removes expired items only, if more than 0 it removes anything above or equal
returnbooleanreturns true if the item was successfully removed
exports.jrs_inventory:subItem(source, item, amount, metadata, callback,event,percentage)subItemById#
remove item from user inventory by its id exort available on verion 3.9 and up lower versions uses subItemID
sourceintrequiredThe player id
itemIdintrequireditem id
callbackfunctioncallback function syncronous or asyncronous
eventbooleanevent OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event
amountintamount to remove
returnbooleanreturns true if the item was successfully removed
exports.jrs_inventory:subItemById(source, itemId,callback,event,amount)setItemMetadata#
- Split a stack and modify only some items (amount must be less than the current stack)
- Merge with an existing stack that has matching metadata (amount must be more or equal than the current stack)
- Modify the entire stack's metadata (amount must be more or equal than the current stack) this only applies if metadata is the same as current stack
sourceintrequiredThe player id
itemIdintrequireditem id
metadatatablereserved keys are:
descriptionthe description of the item to replaceimagethe image of the item to replace must exist in item folder.labelthe label of the item to replaceweightthe weight of the item to replacetolltipadd extra text to the tooltipuseExpiredif true allows to use expired items overriding the useExpired setting in the item db
amountintrequiredamount of item to remove from current stack if less, if more it will remove from here and add to another stack if metadata matches, if not then it updates the entire stack with new meta
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the metadata was successfully set
local metadata = { description = 'Custom description', label = 'Custom label' }
exports.jrs_inventory:setItemMetadata(source, itemId, metadata, 1) -- SET ITEM METADATA
exports.jrs_inventory:setItemMetadata(source, itemId, metadata, amount, callback)registerUsableItem#
register usable item
Items cant be registered twice they must be unique
itemstringrequireditem name
callbackfunctionrequiredcallback {source:int, id:number, label:string, name:string, metadata:table, group:number, type:string, count:number, limit:number,canUse:boolean, mainid: integer, percentage:integer}
resourceNamestringresource name for debug purposes so users can see in what resource this item is registered at
exports.jrs_inventory:registerUsableItem(item, callback,resourceName)unRegisterUsableItem#
un register usable item when you stop a script for example
Items cant be registered twice they must be unique
itemstringrequireditem name
exports.jrs_inventory:unRegisterUsableItem(item)Getters#
getCustomInventoryItemCount#
get custom inventory item count
invidstringrequiredinventory id
itemNamestringrequireditem name
callbackfunctioncallback function syncronous or asyncronous
metadatatableif metadata is provided then it will return the amount of items with the same metadata
returnnumberreturns the amount of items in the inventory
exports.jrs_inventory:getCustomInventoryItemCount(invid,itemName,callback,metadata)getCustomInventoryItems#
get custom inventory items
invidstringrequiredinventory id
callbackfunctioncallback function syncronous or asyncronous
returntablereturns a table containing all the items in the inventory
exports.jrs_inventory:getCustomInventoryItems(invid, callback)Setters#
removeItemFromCustomInventory#
remove item from custom inventory
invidstringrequiredinventory id
itemNamestringrequireditem name
amountnumberrequiredamount of item
itemCraftedIdnumberrequireditem crafted id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the item was successfully removed
exports.jrs_inventory:removeItemFromCustomInventory(invid,itemName,callback)updateCustomInventoryItem#
update item in custom inventory
invIdstringrequiredinventory id
item_idnumberrequireditem id
metadatatablerequiredmetadata to update
amountnumberamount of item
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the item was successfully updated
exports.jrs_inventory:updateCustomInventoryItem(invId, item_id, metadata, amount, callback)addItemsToCustomInventory#
add items to custom inventory
invidstringrequiredinventory id
itemstablerequireditems to add
charidnumbercharidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the items were successfully added
exports.jrs_inventory:addItemsToCustomInventory(invid, items, charid,callback)setCustomInventoryItemLimit#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
if in registerCustomInventory you set whitelistItems true then use this export to set which items are whitelisted and their amount
invIdstringrequiredinventory id
itemstringrequireditem name
limitnumberrequireditem limit
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the limit was successfully set
exports.jrs_inventory:setCustomInventoryItemLimit(invId, item, limit, callback)JRS Core custom inventories store items only. These functions exist for compatibility: reads return empty / 0, writes return false.
Getters#
getCustomInventoryWeapons#
get custom inventory weapons
invidstringrequiredinventory id
callbackfunctioncallback function syncronous or asyncronous
returntablereturns a table containing all the weapons in the inventory
exports.jrs_inventory:getCustomInventoryWeapons(invid, callback)getCustomInventoryWeaponCount#
get custom inventory weapon count
invidstringrequiredinventory id
weaponNamestringrequiredweapon name
callbackfunctioncallback function syncronous or asyncronous
returnnumberreturns the amount of weapons in the inventory
exports.jrs_inventory:getCustomInventoryWeaponCount(invid,weaponName,callback)Setter#
removeCustomInventoryWeaponById#
remove weapon from custom inventory by weapon id
invIdstringrequiredinventory id
weapon_idnumberrequiredweapon id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the weapon was successfully removed
exports.jrs_inventory:removeCustomInventoryWeaponById(invId, weapon_id, callback)removeWeaponFromCustomInventory#
remove weapon from custom inventory
invidstringrequiredinventory id
weaponNamestringrequiredweapon name
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the weapon was successfully removed
exports.jrs_inventory:removeWeaponFromCustomInventory(invid,weaponName,callback)addWeaponsToCustomInventory#
add weapons to custom inventory
invidstringrequiredinventory id
weaponstablerequired{name: string, serial_number: string?, custom_label: string?, custom_desc: string?, components: table?}
charidnumbercharidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the weapons were successfully added
exports.jrs_inventory:addWeaponsToCustomInventory(invid, weapons, charid,callback)setCustomInventoryWeaponLimit#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
set custom inventory whitelisted weapons, if in registerCustomInventory you set whitelistWeapons true then use this export to set which weapons are whitelisted and their amount
invIdstringrequiredinventory id
weaponstringrequiredweapon name
limitnumberrequiredweapon limit
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the limit was successfully set
exports.jrs_inventory:setCustomInventoryWeaponLimit(invId, weapon, limit, callback)Getters#
isCustomInventoryRegistered#
check if inventory is registered
idstringrequiredinventory id
callbackfunctioncallback function syncronous or asyncronous
returnbooleanreturns true if the inventory is registered
exports.jrs_inventory:isCustomInventoryRegistered(id, callback)AddCharIdPermissionTakeFromCustom#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
add permissions using charids
idstringrequiredinventory id
charidnumberrequiredcharid
statebooleanstate
exports.jrs_inventory:AddCharIdPermissionTakeFromCustom(id,charid,state)AddCharIdPermissionMoveToCustom#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
add permissions using charids
idstringrequiredinventory id
charidnumberrequiredcharid
statebooleanstate
exports.jrs_inventory:AddCharIdPermissionMoveToCustom(id,charid,state)getCustomInventorySlots#
get cached inventory slots
invIdstringrequiredinventory id
callbackfunctioncallback function syncronous or asyncronous
exports.jrs_inventory:getCustomInventorySlots(invId,callback)Setters#
deleteCustomInventory#
delete custom inventory from data base and cache
invIdstringrequiredinventory id
exports.jrs_inventory:deleteCustomInventory(invId)registerInventory#
register custom inventory
datatablerequired{ id:string, name:string, limit:number, acceptWeapons:boolean, shared:boolean, ignoreItemStackLimit:boolean, whitelistItems:boolean, UsePermissions:boolean, UseBlackList:boolean, whitelistWeapons:boolean,webhook:string }
exports.jrs_inventory:registerInventory(data)AddPermissionMoveToCustom#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
add permissions to move item to inventory by job and grade
invIdstringrequiredinventory id
jobNamestringrequiredjob name
jobgradenumberrequiredjob grade
exports.jrs_inventory:AddPermissionMoveToCustom(invId, jobName, jobgrade)AddPermissionTakeFromCustom#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
add permissions to take item from inventory by job and grade
invIdstringrequiredinventory id
jobNamestringrequiredjob name
jobgradenumberrequiredjob grade
exports.jrs_inventory:AddPermissionTakeFromCustom(invId, jobName, jobgrade)BlackListCustomAny#
Accepted so existing scripts do not break, but it has no effect in JRS Core: a custom inventory is only opened by the script that owns it.
black list items or weapons
invIdstringrequiredinventory id
itemstringrequireditem name | weapon name
exports.jrs_inventory:BlackListCustomAny(invId, item)removeInventory#
remove inventory from session
invIdstringrequiredinventory id
exports.jrs_inventory:removeInventory(invId)updateCustomInventorySlots#
update inventory slots
invIdstringrequiredinventory id
slotsnumberrequiredinventory slots
exports.jrs_inventory:updateCustomInventorySlots(invId, slots)openInventory#
open inventory main or secondary
sourceintrequiredThe player id
invIdstringinventory id
exports.jrs_inventory:openInventory(source, invId)closeInventory#
close inventory main or secondary
sourceintrequiredThe player id
invIdstringinventory id
exports.jrs_inventory:closeInventory(source, invId)openPlayerInventory#
open player inventory
datatablerequired{ source:int, target:int, title:string, blacklist:table, itemsLimit:table, timeout:number }
local data = {
source = source,
target = target,
title = "Search inventory",
blacklist = { -- OPTIONAL
water = true, -- item name or weapon name
},
itemsLimit = { -- OPTIONAL
weapons = { itemType = "item_weapon", limit = 1 }, -- how many weapons user is allowed to take
items = { itemType = "item_standard", limit = 2 }, -- how many items user is allowed to take
},
timeout = 60, -- OPTIONAL in seconds , if enabled when user reaches limits then a timeout is applied so player cant steal for that amount of time if removed then once limit reached only after restart they can steal again
}
exports.jrs_inventory:openPlayerInventory(data)Events#
Server Side only
Listen to when an item is used
AddEventHandler("jrs_inventory:Server:OnItemUse",function(data)
local source = data.source
local itemName = data.item.name
local itemMetadata = data.item.metadata
end)Listen to when an item is created in player inventory
AddEventHandler("jrs_inventory:Server:OnItemCreated",function(data,source)
-- data.count, data.name, data.metadata
end)Listen to when an item is removed from player inventory
AddEventHandler("jrs_inventory:Server:OnItemRemoved",function(data,source)
-- data.count , data.name , data.metadata
end)Listen to when an item is taken from custom inventory
AddEventHandler("jrs_inventory:Server:OnItemTakenFromCustomInventory", function(item, invId, source)
-- item.amount , item.name, item.id, item.metadata
end)Listen to when an item is moved to custom inventory
AddEventHandler("jrs_inventory:Server:OnItemMovedToCustomInventory", function(item, invId, source)
-- item.amount , item.name, item.id, item.metadata
end)Listen for inventory state change (opens or closes) including custom inventories
AddEventHandler("jrs_inventory:Client:OnInvStateChange",function(boolean)
print(boolean)
end)Block player inventory from server or client side
TriggerClientEvent("jrs_inventory:blockInventory", player_id, true or false) TriggerEvent("jrs_inventory:blockInventory", true or false)Client Side only
Listen to when a weapon is equipped
AddEventHandler("jrs_inventory:onWeaponEquipped", function(components, weaponId, name, isDual, defaultAttachments)
-- components: table of the equipped components, weaponId: weapon id, name: weapon name, isDual: boolean, defaultAttachments: table
end)Listen to when a component is added to a weapon
AddEventHandler("jrs_inventory:componentAdded", function(weaponId, component, category)
-- weaponId: weapon id, component: component name, category: slot category
end)Listen to when a component is removed from a weapon
AddEventHandler("jrs_inventory:componentRemoved", function(weaponId, component, category)
-- weaponId: weapon id, component: component name, category: slot category
end)Statebags#
contains data from the current weapon used in the inventory or last weapon used.
client side
local key = string.format("GetEquippedWeaponData_%d",weaponHash)
local data = LocalPlayer.state[key]
local serial = data.serialNumber
local id = data.weaponIdserver side
local key = string.format("GetEquippedWeaponData_%d",weaponHash)
local data = Player(source).state[key]
local serial = data.serialNumber
local id = data.weaponIdcheck if inventory is active (open or closed) including custom inventories
client side
LocalPlayer.state.IsInvActiveserver side
Player(source).state.IsInvActiveGlobal Statebags#
returns timestamp from server to be used in client
local timestamp = GlobalState.TimeNow
-- Get hours, minutes and seconds from timestamp
local seconds = GlobalState.TimeNow % 60
local minutes = math.floor(GlobalState.TimeNow / 60) % 60
local hours = math.floor(GlobalState.TimeNow / 3600) % 24