⚓Server
🟡 Server Exports
Items
--Get Table of Item List
--@param itemName? string
local origenItems = exports.origen_inventory:Items(itemName)
--- If not itemName then get ALL item list.
--- If itemName then get specific item info.
registerStash
ALIAS: exports.origen_inventory:RegisterStash(...)
--Create runtime stash
---@param id string | number
---@param labelOrStashData string | table
---@param slots number
---@param maxWeight number
---@param owner? table | string -- WIP
---@param groups? table -- WIP
---@param coords? table -- WIP
---@return table | false
exports.origen_inventory:registerStash(id, labelOrStashData, slots, maxWeight, owner, groups, coords)
-- Example usage 1
exports.origen_inventory:registerStash('police_locker', {
label = "Police Locker",
slots = 10,
weight = 100
})
-- Example usage 2
exports.origen_inventory:registerStash('police_locker', "Police Locker", 10, 100000)
getInventory
ALIAS: exports.origen_inventory:GetInventory(...)
---Get Inventory
---@param inventory string | number
---@param inventoryType? string
---@return table | false
local inventory = exports.origen_inventory:getInventory(inventory, inventoryType)
if inventory then
print("Inventory", json.encode(inventory))
end
--- Examples
local playerId = 1 -- or stashId
local stashId = 'test'
local trunkId = 'trunk_abc1212'
exports.origen_inventory:getInventory(playerId) -- return player inventory
exports.origen_inventory:getInventory(stashId) -- return stash id
exports.origen_inventory:getInventory(trunkId) -- return stash (trunk)
--- IMPORTANT!
--- inventoryType is optional and can be used to force the algorithm to search only one type of inventory,
--- for example if for some reason you want to search a chest as a stash you can force it.
--- Inventory types:
-- number :: player server id
-- 'stash'
-- 'trunk'
-- 'glovebox'
getItems
ALIAS:
exports.origen_inventory:getInventoryItems(...)
exports.origen_inventory:GetInventoryItems(...
---@param inventory string | number
---@return table
local inventoryItems = exports.origen_inventory:getItems(inventory)
for slot, item in pairs(inventoryItems) do
print("The item on slot", slot, "is", item.name)
end
addItem
ALIAS: exports.origen_inventory:AddItem(...)
---@param inventory string | number
---@param itemName string
---@param count? number
---@param metadata? string | table
---@param slot? number
---@param ignoreWeight? boolean
---@return boolean, (string | table)
exports.origen_inventory:addItem(inventory, itemName, amount, metadata, slot, ignoreWeight)
-- Example
local myStashId = 'iLoveAlex' -- Or playerId (number)
local success, msgOrItem = exports.origen_inventory:addItem(myStashId, 'tosti', 1, false, false, false)
-- or
local success, msgOrItem = exports.origen_inventory:addItem(myStashId, 'tosti', 1)
-- or
local success, msgOrItem = exports.origen_inventory:addItem(myStashId, 'tosti', 1, { whatIs = 'this' }, false)
-- or
local success, msgOrItem = exports.origen_inventory:addItem(myStashId, 'tosti', 1, { whatIs = 'this' }, 2)
-- or
local success, msgOrItem = exports.origen_inventory:addItem(myStashId, 'tosti', 1, false, 2)
--- If not error, msgOrItem will be a last created item
print(success, msgOrItem)
--- Error msg:
--- invalid_inventory : 'Invalid inventory ID'
--- invalid_item : 'Item not found on item list
--- invalid_slot : 'Slot not found, maybe inventory full?'
--- inventory_full : '...'
--- inventory_slot_mismatch : 'Slot has item but not same name'
--- inventory_slot_mismatch_2 : 'Slot is different to giving'
addItems
---@param inventory string | number
---@param items table
---@return boolean, (string | table)
exports.origen_inventory:addItems(inventory, items)
-- Example
local myStashId = 'iLoveAlex' -- Or playerId (number)
local success, msg = exports.origen_inventory:addItems(myStashId, {
{ 'tosti', 1 },
{ 'weapon_pistol', 1 }
})
-- or
local success, items = exports.origen_inventory:addItem(myStashId, {
{
name = 'tosti',
amount = 1,
metadata = {
pollitoPio = true
}
},
{
name = 'weapon_pistol',
amount = 1
}
})
--- This return a list of items (#items == 0 if errors are encountered)
print(success, items)
removeItem
ALIAS: exports.origen_inventory:RemoveItem(...)
---Remove Inventory Item
---@param inventory string | number
---@param itemName string
---@param count? number Defaults 1
---@param metadata? table
---@param slot? number
---@param ignoreTotal? boolean Equals to remove ALL coincidences of the item.
---@return false
---@return string|table
exports.origen_inventory:removeItem(inventory, itemName, count, metadata, slot, ignoreTotal)
--- Examples
local playerId = 1 -- or stashId
exports.origen_inventory:removeItem(playerId , 'tosti') -- Remove 1
exports.origen_inventory:removeItem(playerId , 'tosti', 2) -- Remove 2
exports.origen_inventory:removeItem(playerId , 'tosti', 1, false, 1) -- Remove 1 on slot 1 (if exist)
exports.origen_inventory:removeItem(playerId , 'tosti', 1, {hello = 'world'}, false, true) -- Remove all with metadata
exports.origen_inventory:removeItem(playerId , 'tosti', 1, false, 5, true) -- Remove all on slot 5
--- Error msg:
--- invalid_inventory : 'Invalid inventory ID'
--- invalid_item : 'Item not found on item list
--- invalid_slot : 'Slot not found, maybe inventory empty?
--- inventory_slot_mismatch : 'Slot has item but not same name'
--- inventory_slot_mismatch_2 : 'Slot is different to giving'
getItem
ALIAS: exports.origen_inventory:GetItem(...)
---@param inventory string | number
---@param itemName string
---@param metadata string | table
---@param returnsCount any
---@return false | table, string?
exports.origen_inventory:getItem(inventory, itemName, metadata, returnsCount)
-- Usage
--- Hypothetical inventory
--[[
{
[1] = {
name = 'tosti'.
amount = 2,
metadata = {
whatIs = 'this'
},
slot = 1
},
[2] = {
name = 'tosti'.
amount = 5,
metadata = {},
slot = 2
}
}
--- ]]
-- Returns the amount with a metadata, the search is NOT strict, meaning if there are many metadata, it will only search for the one you have placed.
-- If you disable returnsCount, the search will be strict and will return all items that match only the metadata provided.
local playerInventory = 1 -- source?
local itemCount = exports.origen_inventory:getItem(playerInventory, 'tosti', false, true)
print(itemCount) -- returns 7
local itemData = exports.origen_inventory:getItem(playerInventory, 'tosti', { whatIs = 'this' }, false)
print(itemData) -- returns {{ name = 'tosti', amount = 1, metadata = { whatIs = 'this' } }}
local itemData = exports.origen_inventory:getItem(playerInventory, 'tosti', false, false)
print(itemData) -- returns all name coincidence items, as table
getItemCount
ALIAS: exports.origen_inventory:GetItemCount(...)
---Get Inventory Item Count
---@param inventory string | number
---@param itemName string
---@param metadata table | string
---@param strict boolean
---@return false, string?
exports.origen_inventory:getItemCount(inventory, itemName, metadata, strict)
-- Same as above, but allowing a strict search or not. (Only returns a number, not the items)
local playerInventory = 1 -- source?
local itemCount = exports.origen_inventory:getItemCount(playerInventory, 'tosti', false, false)
print(itemCount) -- returns 7
local itemCount = exports.origen_inventory:getItemCount(playerInventory, 'tosti', { whatIs = 'this' }, true)
print(itemCount) -- returns 1
--- Examples
local fakeInventory = {
[1] = { count = 1, metadata = { hello = 'world', test = 'no' }, name = 'tosti' },
[2] = { count = 2, metadata = { hello = 'world' }, name = 'tosti' }
}
local playerId = 1 -- or stashId
exports.origen_inventory:getItemCount(playerId , 'tosti') -- return 3
exports.origen_inventory:getItemCount(playerId , 'tosti'. {hello = 'world'}) -- return 3
exports.origen_inventory:getItemCount(playerId , 'tosti', {hello = 'world'}, true) -- return 1
setMetadata
ALIAS: exports.origen_inventory:SetMetadata(...)
--- Set Metadata to item
--- @param inventory string | number
--- @param slot number
--- @param metadata table
--- @return boolean
--- @return string
exports.origen_inventory:setMetadata(inventory, slot, metadata)
-- Example
local inventory = 'police_locker'
local slot = 1
local metadata = {
hello = "world"
}
exports.origen_inventory:setMetadata(inventory, slot, metadata)
saveInventory
exports.origen_inventory:saveInventory(inventory)
Happy Coding!
Deprecated Exports
These exports continue to function as long as they are on this list, please prioritize replacing with new exports.
Support for these exports is a lower priority, you can request new exports on our support discord.
CanCarryItem
exports.origen_inventory:CanCarryItem(playerId, item, amount)
StashGetItemByname
exports.origen_inventory:StashGetItemByname(stash_name, item_name)
CanCarryItem
exports.origen_inventory:CanCarryItems(playerId, item, amount)
GiveWeaponToPlayer
exports.origen_inventory:GiveWeaponToPlayer(playerId, weapon_name, ammo)
ClearInventory
exports.origen_inventory:ClearInventory(playerId, filter)
SetInventoryItems
exports.origen_inventory:SetInventoryItems(playerId, item, amount)
GetTotalWeight
exports.origen_inventory:GetTotalWeight(playerId)
HasItem
exports.origen_inventory:HasItem(playerId, item, amount)
GetItemByName
exports.origen_inventory:GetItemByName(playerId, item)
GetSlotsByItem
exports.origen_inventory:GetSlotsByItem(items, item)
GetItemByslot
exports.origen_inventory:GetItemBySlot(playerId, slot)
GetFirstSlotByItem
exports.origen_inventory:GetFirstSlotByItem(items, item)
GetItemTotalAmount
exports.origen_inventory:GetItemTotalAmount(playerId, item)
AddItemMetadata
exports.origen_inventory:AddItemMetadata(playerId, item, slot, metadata)
SetInventoryData
exports.origen_inventory:SetInventoryData(fromInventory, toInventory, fromSlot, toSlot, fromAmount, toAmount)
OpenInventory
--[[
Inventory Types:
- playerId
- otherplayer
- stash
- trunk
- glovebox
- drop
- shop
]]
exports.origen_inventory:OpenInventory(playerId, inventory_type, inventory_id)
-- Example
exports.origen_inventory:OpenInventory(1, 'stash', 'police-locker')
GetItemLabel
exports.origen_inventory:GetItemLabel(item)
SaveInventory
exports.origen_inventory:SaveInventory(playerId, isOffline?)
LoadInventory
-- Note: firstLoading represents whether the inventory should be loaded from the database (true) or from the cache (false).
exports.origen_inventory:LoadInventory(playerId, firstLoading?)
GetPlayerInventory
exports.origen_inventory:getPlayerInventory(playerId)
GetUsableItem
exports.origen_inventory:GetUsableItem(name)
CreateUseableItem
exports.origen_inventory:CreateUseableItem(name, cb)
UseItem
exports.origen_inventory:UseItem(playerId, name)
UseItemSlot
exports.origen_inventory:UseItemSlot(slot, inventory_id)
GetTotalWeightByItems
local items = { 'id_card', 'sandwich' }
exports.origen_inventory:GetTotalWeightByItems(items)
OpenInventoryById
exports.origen_inventory:OpenInventoryById(playerId, otherPlayerId)
GetItemByMetadata
exports.origen_inventory:GetItemByMetadata(playerId, metaKey, metaValue)
GetItemsByMetadata
exports.origen_inventory:GetItemsByMetadata(playerId, metaKey, metaValue)
GetItemByMetaKey
exports.origen_inventory:GetItemByMetaKey(playerId, metaKey)
GetItemsByMetaKey
exports.origen_inventory:GetItemsByMetaKey(playerId, metaKey)
GetItemInfoBySlot
exports.origen_inventory:GetItemInfoBySlot(playerId, itemName, slot)
Last updated