Inventory
Documentation for vorp inventory system
This documentation is for developers who are making scripts for VORP Core Framework
Exports
Getters
returns
a table containing all the items in the inventory
local result = exports.vorp_inventory:getInventoryItems()
Getters
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)
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)
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
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)
The player id
weapon name
amount of ammo
weapon components
weapon components
callback function syncronous or asyncronous
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)
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)
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)
The player id
exports.vorp_inventory:removeAllUserAmmo(source)
Events
Listen to when an item is used
AddEventHandler("vorp_inventory:Server:OnItemUse",function(data)
local source = data.source
local itemName = data.item
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