Inventory
Documentation for vorp inventory system
This documentation is for developers who are making scripts for VORP Core Framework
Exports
Getters
get all user inventory items
returns
a table containing all the items in the inventory
local result = exports.vorp_inventory:getInventoryItems()
Getters
get all user inventory items
returns
a table containing all the items in the inventory
local result = exports.vorp_inventory:getInventoryItems()
close inventory
exports.vorp_inventory:closeInventory()
Getters
check if player can carry weapons
The player id
amount of weapons
callback function syncronous or asyncronous
weapon name or hash its needed to check weight since 3.6
returns
true if the player can carry the weapons
exports.vorp_inventory:canCarryWeapons(source, amount,callback, weaponName)
get user inventory weapon
The player id
callback function syncronous or asyncronous
weapon id
{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.vorp_inventory:getUserWeapon(source, callback,weaponId)
get user inventory weapons
The player id
callback function syncronous or asyncronous
{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.vorp_inventory:getUserInventoryWeapons(source, callback)
Setters
give weapon to user
The player id
weapon id
target id
callback function syncronous or asyncronous
returns
true if the weapon was successfully given
exports.vorp_inventory:giveWeapon(source, weaponId, target,callback)
create weapon
The player id
weapon name
amount of ammo
weapon components
weapon components
callback function syncronous or asyncronous
leave this as nil, this is used internally only
custom serial number for weapon
custom label for weapon
custom desc for weapons
if async
exports.vorp_inventory:createWeapon(source, weaponName, ammo, components, comps, callback,serial,label,desc)
add bullets
The player id
bullet type
amount of bullets
callback function syncronous or asyncronous
returns
true if the bullets were successfully added
exports.vorp_inventory:addBullets(source, bulletType, amount,callback)
remove bullets from weapon
weapon id
bullet type
amount of bullets
callback function syncronous or asyncronous
returns
true if the bullets were successfully removed
exports.vorp_inventory:subBullets(weaponId, bulletType, amount,callback)
Getters
check if player can carry weapons
The player id
amount of weapons
callback function syncronous or asyncronous
weapon name or hash its needed to check weight since 3.6
returns
true if the player can carry the weapons
exports.vorp_inventory:canCarryWeapons(source, amount,callback, weaponName)
get user inventory weapon
The player id
callback function syncronous or asyncronous
weapon id
{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.vorp_inventory:getUserWeapon(source, callback,weaponId)
get user inventory weapons
The player id
callback function syncronous or asyncronous
{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.vorp_inventory:getUserInventoryWeapons(source, callback)
Setters
give weapon to user
The player id
weapon id
target id
callback function syncronous or asyncronous
returns
true if the weapon was successfully given
exports.vorp_inventory:giveWeapon(source, weaponId, target,callback)
create weapon
The player id
weapon name
amount of ammo
weapon components
weapon components
callback function syncronous or asyncronous
leave this as nil, this is used internally only
custom serial number for weapon
custom label for weapon
custom desc for weapons
if async
exports.vorp_inventory:createWeapon(source, weaponName, ammo, components, comps, callback,serial,label,desc)
add bullets
The player id
bullet type
amount of bullets
callback function syncronous or asyncronous
returns
true if the bullets were successfully added
exports.vorp_inventory:addBullets(source, bulletType, amount,callback)
remove bullets from weapon
weapon id
bullet type
amount of bullets
callback function syncronous or asyncronous
returns
true if the bullets were successfully removed
exports.vorp_inventory:subBullets(weaponId, bulletType, amount,callback)
Getters
check if player can carry the item before adding it to the inventory
The player id
The item name
The amount of items
The callback function syncronous or asyncronous
returns
true if the player can carry the item
exports.vorp_inventory:canCarryItem(source, item, amount, callback)
get item amount from player inventory
The player id
callback function for syncronous or asyncronous
item name
item metadata
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
returns
the amount of items in the inventory
exports.vorp_inventory:getItemCount(source, callback, item, metadata, percentage)
get item by main id
The player id
item id
callback function syncronous or asyncronous
{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.vorp_inventory:getItemById(source, id, callback)
get item data
The player id
item name
callback function syncronous or asyncronous
item metadata
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
{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.vorp_inventory:getItem(source, item,callback, metadata,percentage)
Setters
add item to user
The player id
item name
amount of item
item metadata
callback function syncronous or asyncronous
if true will not trigger the event OnItemCreated
returns
true if the item was successfully added
exports.vorp_inventory:addItem(source, item, amount, metadata, callback,event)
remove item from user inventory
The player id
item name
amount of item
item metadata
callback function syncronous or asyncronous
event OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event
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
returns
true if the item was successfully removed
exports.vorp_inventory:subItem(source, item, amount, metadata, callback,event,percentage)
remove item from user inventory by its id exort available on verion 3.9 and up lower versions uses subItemID
The player id
item id
callback function syncronous or asyncronous
event OnItemRemoved to be fired, if true it wont be sent, false or nil it will fire the event
amount to remove
returns
true if the item was successfully removed
exports.vorp_inventory:subItemById(source, itemId,callback,event,amount)
- 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
The player id
item id
{ description:string?, image:string?,label:string?,weight:number?}
description image label and weight are reserved keys if they are not defined they will be ignored, image is the image name to apply
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
callback function syncronous or asyncronous
returns
true if the metadata was successfully set
exports.vorp_inventory:setItemMetadata(source, itemId, metadata, amount, callback)
register usable item
item name
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}
resource name for debug purposes so users can see in what resource this item is registered at
exports.vorp_inventory:registerUsableItem(item, callback,resourceName)
un register usable item when you stop a script for example
item name
exports.vorp_inventory:unRegisterUsableItem(item)
Getters
Setters
remove item from custom inventory by item id
inventory id
item id
callback function syncronous or asyncronous
returns
true if the item was successfully removed
exports.vorp_inventory:removeCustomInventoryItemById(invId, item_id, callback)
update item in custom inventory
inventory id
item id
metadata to update
amount of item
callback function syncronous or asyncronous
returns
true if the item was successfully updated
exports.vorp_inventory:updateCustomInventoryItem(invId, item_id, metadata, amount, callback)
add items to custom inventory
inventory id
items to add
charidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer
callback function syncronous or asyncronous
returns
true if the items were successfully added
exports.vorp_inventory:addItemsToCustomInventory(invid, items, charid,callback)
if in registerCustomInventory you set whitelistItems true then use this export to set which items are whitelisted and their amount
inventory id
item name
item limit
callback function syncronous or asyncronous
returns
true if the limit was successfully set
exports.vorp_inventory:setCustomInventoryItemLimit(invId, item, limit, callback)
Getters
Setter
remove weapon from custom inventory by weapon id
inventory id
weapon id
callback function syncronous or asyncronous
returns
true if the weapon was successfully removed
exports.vorp_inventory:removeCustomInventoryWeaponById(invId, weapon_id, callback)
remove weapon from custom inventory
inventory id
weapon name
callback function syncronous or asyncronous
returns
true if the weapon was successfully removed
exports.vorp_inventory:removeWeaponFromCustomInventory(invid,weaponName,callback)
add weapons to custom inventory
inventory id
{name: string, serial_number: string?, custom_label: string?, custom_desc: string?, components: table?}
charidentifier of the owner of the storage if custom inv is not shared , if its shared can be any characteridentifer
callback function syncronous or asyncronous
returns
true if the weapons were successfully added
exports.vorp_inventory:addWeaponsToCustomInventory(invid, weapons, charid,callback)
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
inventory id
weapon name
weapon limit
callback function syncronous or asyncronous
returns
true if the limit was successfully set
exports.vorp_inventory:setCustomInventoryWeaponLimit(invId, weapon, limit, callback)
Getters
register custom inventory
{ id:string, name:string, limit:number, acceptWeapons:boolean, shared:boolean, ignoreItemStackLimit:boolean, whitelistItems:boolean, UsePermissions:boolean, UseBlackList:boolean, whitelistWeapons:boolean,webhook:string }
exports.vorp_inventory:registerInventory(data)
remove inventory from session
inventory id
exports.vorp_inventory:removeInventory(invId)
open player inventory
{ 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.vorp_inventory:openPlayerInventory(data)
Events
Listen to when an item is used
AddEventHandler("vorp_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("vorp_inventory:Server:OnItemCreated",function(data,source)
-- data.count, data.name, data.metadata
end)
Listen to when an item is removed from player inventory
AddEventHandler("vorp_inventory:Server:OnItemRemoved",function(data,source)
-- data.count , data.name , no metadata is passed here
end)
Listen for inventory state change (opens or closes)
including custom inventories
AddEventHandler("vorp_inventory:Client:OnInvStateChange",function(boolean)
print(boolean)
end)
Statebags
contains data from the current weapon used in the inventory or last weapon used.
local key = string.format("GetEquippedWeaponData_%d",weaponHash)
local data = LocalPlayer.state[key]
local serial = data.serialNumber
local id = data.weaponId
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
LocalPlayer.state.IsInvActive
Player(source).state.IsInvActive
Global 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