JRS CORE문서
API 레퍼런스

inventory

Documentation for jrs inventory system

Warning

This documentation is for developers who are making scripts for JRS Core Framework

Exports#


Note

These exports are client side only!

Getters#

closeInventory#

close inventory

 
lua
exports.jrs_inventory:closeInventory()
Note

These exports are server side only!

Getters#

getUserAmmo#

get all user ammo

sourceintrequired

The player id

callbackfunction

callback function syncronous or asyncronous

returntable

returns a table containing all the ammo

lua
exports.jrs_inventory:getUserAmmo(source, callback)
canCarryWeapons#

check if player can carry weapons

sourceintrequired

The player id

amountintrequired

amount of weapons

callbackfunction

callback function syncronous or asyncronous

weaponNamestring | number

weapon name or hash its needed to check weight since 3.6

returnboolean

returns true if the player can carry the weapons

lua
exports.jrs_inventory:canCarryWeapons(source, amount,callback, weaponName)
getUserWeapon#

get user inventory weapon

sourceintrequired

The player id

callbackfunction

callback function syncronous or asyncronous

weaponIdnumber

weapon 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}

lua
exports.jrs_inventory:getUserWeapon(source, callback,weaponId)
getUserInventoryWeapons#

get user inventory weapons

sourceintrequired

The player id

callbackfunction

callback 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}

lua
exports.jrs_inventory:getUserInventoryWeapons(source, callback)
getWeaponBullets#

get weapon bullets

sourceintrequired

The player id

weaponIDnumberrequired

weapon id

callbackfunction

callback function syncronous or asyncronous

returnnumber

weapon ammo

lua
exports.jrs_inventory:getWeaponBullets(source,weaponID, callback)
getWeaponComponents#

get weapon components

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

callbackfunction

callback function syncronous or asyncronous

returntable

returns a table containing the weapon components

lua
exports.jrs_inventory:getWeaponComponents(source, weaponId, callback)

Setters#

setWeaponCustomDesc#

set weapon custom description

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

descstringrequired

weapon description

cbfunction

callback function syncronous or asyncronous

returnboolean

returns true if the description was successfully set

lua
exports.jrs_inventory:setWeaponCustomDesc(weaponId, desc, cb)
setWeaponCustomLabel#

set weapon custom label

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

labelstringrequired

weapon label

cbfunction

callback function syncronous or asyncronous

returnboolean

returnstrue if the label was successfully set

lua
exports.jrs_inventory:setWeaponCustomLabel(weaponId, label, cb)
setWeaponSerialNumber#

set weapon serial number

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

serialstringrequired

weapon serial number

cbfunction

callback function syncronous or asyncronous

returnboolean

returns true if the serial number was successfully set

lua
exports.jrs_inventory:setWeaponSerialNumber(weaponId, serial, cb)
subWeapon#

remove weapon from user inventory

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the weapon was successfully removed

lua
exports.jrs_inventory:subWeapon(source, weaponId, callback)
giveWeapon#

give weapon to user

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

targetintrequired

target id

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the weapon was successfully given

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

create weapon

sourceintrequired

The player id

weaponNamestringrequired

weapon name

ammostringrequired

amount of ammo

componentstablerequired

weapon components

compstablerequired

weapon components

callbackfunction

callback function syncronous or asyncronous

wepidint

leave this as nil, this is used internally only

serialstring

custom serial number for weapon

labelstring

custom label for weapon

descstring

custom desc for weapons

returnboolean

if async

lua
exports.jrs_inventory:createWeapon(source, weaponName, ammo, components, comps, callback,serial,label,desc)
deleteWeapon#

delete weapon

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

callbackfunction

callback function syncronous or asyncronous

returnboolean

if async

lua
exports.jrs_inventory:deleteWeapon(source, weaponId, callback)
addBullets#

add bullets

sourceintrequired

The player id

bulletTypestringrequired

bullet type

amountnumberrequired

amount of bullets

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the bullets were successfully added

lua
exports.jrs_inventory:addBullets(source, bulletType, amount,callback)
subBullets#

remove bullets from weapon

weaponIdnumberrequired

weapon id

bulletTypestringrequired

bullet type

amountnumberrequired

amount of bullets

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the bullets were successfully removed

lua
exports.jrs_inventory:subBullets(weaponId, bulletType, amount,callback)
removeAllUserAmmo#

remove all user ammo

sourceintrequired

The player id

lua
exports.jrs_inventory:removeAllUserAmmo(source)
addWeaponComponent#

add a component to a weapon

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

componentstring | numberrequired

component name or hash

categorystring | numberrequired

slot category

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the component was successfully added

lua
exports.jrs_inventory:addWeaponComponent(source, weaponId, component, category, callback)
subWeaponComponent#

remove a component from a weapon

sourceintrequired

The player id

weaponIdnumberrequired

weapon id

componentstring | numberrequired

component name or hash

categorystring | numberrequired

slot category

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the component was successfully removed

lua
exports.jrs_inventory:subWeaponComponent(source, weaponId, component, category, callback)

Getters#

canCarryItem#

check if player can carry the item before adding it to the inventory

sourceintrequired

The player id

itemstringrequired

The item name

amountintrequired

The amount of items

callbackfunction

The callback function syncronous or asyncronous

returnboolean

returns true if the player can carry the item

lua
exports.jrs_inventory:canCarryItem(source, item, amount, callback)
getUserInventoryItems#

gets all the items in the player inventory

sourceintrequired

The player id

callbackfunction

The callback function syncronous or asyncronous

returntable

returns a table containing all the items in the inventory

lua
exports.jrs_inventory:getUserInventoryItems(source, callback)
getItemCount#

get item amount from player inventory

sourceintrequired

The player id

callbackfunction

callback function for syncronous or asyncronous

itemstringrequired

item name

metadatatable

item metadata

percentageint

allows 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

returnint

returns the amount of items in the inventory

usage
lua
exports.jrs_inventory:getItemCount(source, callback, item, metadata, percentage)
getItemDB#

get DB item

itemstringrequired

item name

callbackfunction

callback function asyncronous or syncronous

returntable

returns a table containing item info

lua
exports.jrs_inventory:getItemDB(item, callback)
getItemById#

get item by main id

sourceintrequired

The player id

idintrequired

item id

callbackfunction

callback 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}

lua
exports.jrs_inventory:getItemById(source, id, callback)
getItem#

get item data

sourceintrequired

The player id

itemstringrequired

item name

callbackfunction

callback function syncronous or asyncronous

metadatatable

item metadata

percentageint

get 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}

lua
exports.jrs_inventory:getItem(source, item,callback, metadata,percentage)

Setters#

addItem#

add item to user

sourceintrequired

The player id

itemstringrequired

item name

amountintrequired

amount of item

metadatatable

item metadata

callbackfunction

callback function syncronous or asyncronous

eventboolean

if true will not trigger the event OnItemCreated

returnboolean

returns true if the item was successfully added

lua
exports.jrs_inventory:addItem(source, item, amount, metadata, callback,event)
subItem#

remove item from user inventory

sourceintrequired

The player id

itemstringrequired

item name

amountintrequired

amount of item

metadatatable

item metadata

callbackfunction

callback function syncronous or asyncronous

eventboolean

event OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event

percentageint

allows 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

returnboolean

returns true if the item was successfully removed

lua
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

sourceintrequired

The player id

itemIdintrequired

item id

callbackfunction

callback function syncronous or asyncronous

eventboolean

event OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event

amountint

amount to remove

returnboolean

returns true if the item was successfully removed

lua
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
sourceintrequired

The player id

itemIdintrequired

item id

metadatatable

reserved keys are:

  • description the description of the item to replace
  • image the image of the item to replace must exist in item folder.
  • label the label of the item to replace
  • weight the weight of the item to replace
  • tolltip add extra text to the tooltip
  • useExpired if true allows to use expired items overriding the useExpired setting in the item db
amountintrequired

amount 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

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the metadata was successfully set

lua
local metadata = { description = 'Custom description', label = 'Custom label' }
exports.jrs_inventory:setItemMetadata(source, itemId, metadata, 1)
lua
  -- SET ITEM METADATA
  exports.jrs_inventory:setItemMetadata(source, itemId, metadata, amount, callback)
registerUsableItem#

register usable item

Note

Items cant be registered twice they must be unique

itemstringrequired

item name

callbackfunctionrequired

callback {source:int, id:number, label:string, name:string, metadata:table, group:number, type:string, count:number, limit:number,canUse:boolean, mainid: integer, percentage:integer}

resourceNamestring

resource name for debug purposes so users can see in what resource this item is registered at

lua
exports.jrs_inventory:registerUsableItem(item, callback,resourceName)
unRegisterUsableItem#

un register usable item when you stop a script for example

Note

Items cant be registered twice they must be unique

itemstringrequired

item name

lua
exports.jrs_inventory:unRegisterUsableItem(item)

Getters#

getCustomInventoryItemCount#

get custom inventory item count

invidstringrequired

inventory id

itemNamestringrequired

item name

callbackfunction

callback function syncronous or asyncronous

metadatatable

if metadata is provided then it will return the amount of items with the same metadata

returnnumber

returns the amount of items in the inventory

lua
exports.jrs_inventory:getCustomInventoryItemCount(invid,itemName,callback,metadata)
getCustomInventoryItems#

get custom inventory items

invidstringrequired

inventory id

callbackfunction

callback function syncronous or asyncronous

returntable

returns a table containing all the items in the inventory

lua
exports.jrs_inventory:getCustomInventoryItems(invid, callback)

Setters#

removeItemFromCustomInventory#

remove item from custom inventory

invidstringrequired

inventory id

itemNamestringrequired

item name

amountnumberrequired

amount of item

itemCraftedIdnumberrequired

item crafted id

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the item was successfully removed

lua
exports.jrs_inventory:removeItemFromCustomInventory(invid,itemName,callback)
updateCustomInventoryItem#

update item in custom inventory

invIdstringrequired

inventory id

item_idnumberrequired

item id

metadatatablerequired

metadata to update

amountnumber

amount of item

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the item was successfully updated

lua
exports.jrs_inventory:updateCustomInventoryItem(invId, item_id, metadata, amount, callback)
addItemsToCustomInventory#

add items to custom inventory

invidstringrequired

inventory id

itemstablerequired

items to add

charidnumber

charidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the items were successfully added

lua
exports.jrs_inventory:addItemsToCustomInventory(invid, items, charid,callback)
setCustomInventoryItemLimit#
Warning

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

invIdstringrequired

inventory id

itemstringrequired

item name

limitnumberrequired

item limit

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the limit was successfully set

lua
exports.jrs_inventory:setCustomInventoryItemLimit(invId, item, limit, callback)
Warning

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

invidstringrequired

inventory id

callbackfunction

callback function syncronous or asyncronous

returntable

returns a table containing all the weapons in the inventory

lua
exports.jrs_inventory:getCustomInventoryWeapons(invid, callback)
getCustomInventoryWeaponCount#

get custom inventory weapon count

invidstringrequired

inventory id

weaponNamestringrequired

weapon name

callbackfunction

callback function syncronous or asyncronous

returnnumber

returns the amount of weapons in the inventory

lua
exports.jrs_inventory:getCustomInventoryWeaponCount(invid,weaponName,callback)

Setter#

removeCustomInventoryWeaponById#

remove weapon from custom inventory by weapon id

invIdstringrequired

inventory id

weapon_idnumberrequired

weapon id

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the weapon was successfully removed

lua
exports.jrs_inventory:removeCustomInventoryWeaponById(invId, weapon_id, callback)
removeWeaponFromCustomInventory#

remove weapon from custom inventory

invidstringrequired

inventory id

weaponNamestringrequired

weapon name

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the weapon was successfully removed

lua
exports.jrs_inventory:removeWeaponFromCustomInventory(invid,weaponName,callback)
addWeaponsToCustomInventory#

add weapons to custom inventory

invidstringrequired

inventory id

weaponstablerequired

{name: string, serial_number: string?, custom_label: string?, custom_desc: string?, components: table?}

charidnumber

charidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the weapons were successfully added

lua
exports.jrs_inventory:addWeaponsToCustomInventory(invid, weapons, charid,callback)
setCustomInventoryWeaponLimit#
Warning

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

invIdstringrequired

inventory id

weaponstringrequired

weapon name

limitnumberrequired

weapon limit

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the limit was successfully set

lua
exports.jrs_inventory:setCustomInventoryWeaponLimit(invId, weapon, limit, callback)

Getters#

isCustomInventoryRegistered#

check if inventory is registered

idstringrequired

inventory id

callbackfunction

callback function syncronous or asyncronous

returnboolean

returns true if the inventory is registered

lua
exports.jrs_inventory:isCustomInventoryRegistered(id, callback)
AddCharIdPermissionTakeFromCustom#
Warning

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

idstringrequired

inventory id

charidnumberrequired

charid

stateboolean

state

lua
exports.jrs_inventory:AddCharIdPermissionTakeFromCustom(id,charid,state)
AddCharIdPermissionMoveToCustom#
Warning

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

idstringrequired

inventory id

charidnumberrequired

charid

stateboolean

state

lua
exports.jrs_inventory:AddCharIdPermissionMoveToCustom(id,charid,state)
getCustomInventorySlots#

get cached inventory slots

invIdstringrequired

inventory id

callbackfunction

callback function syncronous or asyncronous

lua
exports.jrs_inventory:getCustomInventorySlots(invId,callback)

Setters#

deleteCustomInventory#

delete custom inventory from data base and cache

invIdstringrequired

inventory id

lua
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 }

lua
exports.jrs_inventory:registerInventory(data)
AddPermissionMoveToCustom#
Warning

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

invIdstringrequired

inventory id

jobNamestringrequired

job name

jobgradenumberrequired

job grade

lua
exports.jrs_inventory:AddPermissionMoveToCustom(invId, jobName, jobgrade)
AddPermissionTakeFromCustom#
Warning

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

invIdstringrequired

inventory id

jobNamestringrequired

job name

jobgradenumberrequired

job grade

lua
exports.jrs_inventory:AddPermissionTakeFromCustom(invId, jobName, jobgrade)
BlackListCustomAny#
Warning

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

invIdstringrequired

inventory id

itemstringrequired

item name | weapon name

lua
exports.jrs_inventory:BlackListCustomAny(invId, item)
removeInventory#

remove inventory from session

invIdstringrequired

inventory id

lua
exports.jrs_inventory:removeInventory(invId)
updateCustomInventorySlots#

update inventory slots

invIdstringrequired

inventory id

slotsnumberrequired

inventory slots

lua
exports.jrs_inventory:updateCustomInventorySlots(invId, slots)
openInventory#

open inventory main or secondary

sourceintrequired

The player id

invIdstring

inventory id

lua
exports.jrs_inventory:openInventory(source, invId)
closeInventory#

close inventory main or secondary

sourceintrequired

The player id

invIdstring

inventory id

lua
exports.jrs_inventory:closeInventory(source, invId)
openPlayerInventory#

open player inventory

datatablerequired

{ source:int, target:int, title:string, blacklist:table, itemsLimit:table, timeout:number }

lua
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#

Note

Server Side only

Listen to when an item is used

lua
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

OnItemCreated
lua
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

OnItemRemoved
lua
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

OnItemTakenFromCustomInventory
lua
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

OnItemMovedToCustomInventory
lua
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

OnInvStateChange
lua
AddEventHandler("jrs_inventory:Client:OnInvStateChange",function(boolean)
    print(boolean)
end)

Block player inventory from server or client side

OnInvBlock
lua
TriggerClientEvent("jrs_inventory:blockInventory", player_id, true or false)
OnInvBlock
lua
  TriggerEvent("jrs_inventory:blockInventory", true or false)
Note

Client Side only

Listen to when a weapon is equipped

onWeaponEquipped
lua
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

componentAdded
lua
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

componentRemoved
lua
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.

Note

client side

GetEquippedWeaponData
lua
local key = string.format("GetEquippedWeaponData_%d",weaponHash)
local data = LocalPlayer.state[key]
local serial = data.serialNumber
local id = data.weaponId
Note

server side

GetEquippedWeaponData
lua
local key = string.format("GetEquippedWeaponData_%d",weaponHash)
local data = Player(source).state[key]
local serial = data.serialNumber
local id = data.weaponId

check if inventory is active (open or closed) including custom inventories

Note

client side

IsInvActive
lua
LocalPlayer.state.IsInvActive
Note

server side

IsInvActive
lua
Player(source).state.IsInvActive

Global Statebags#

returns timestamp from server to be used in client

lua
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
JRS Core · 무료 오픈소스 RedM 프레임워크 · JRS TEAM 제작