update core_inventory bridging to the current docs
I dont have a copy of this, im banned from his discord and im doing this blindly based on the docs with no explanation of whats in these returned tables. If you are the creator and want me to tweak this please send a copy to my keymaster. TheRealMrNewb
This commit is contained in:
1 parent
5c9a97c1c0
commit
a4d984b951
2 files changed
+14
-34
No files matched your search
@@ -1,8 +1,6 @@
|
|||||||
---@diagnostic disable: duplicate-set-field
|
---@diagnostic disable: duplicate-set-field
|
||||||
if GetResourceState('core_inventory') == 'missing' then return end
|
if GetResourceState('core_inventory') == 'missing' then return end
|
||||||
local core = exports.core_inventory
|
local core = exports.core_inventory
|
||||||
-- Core inventory docs available at https://docs.c8re.store/core-inventory/api/server#getitemslist
|
|
||||||
Callback = Callback or Require("lib/callback/shared/callback.lua")
|
|
||||||
|
|
||||||
Inventory = Inventory or {}
|
Inventory = Inventory or {}
|
||||||
|
|
||||||
@@ -14,7 +12,7 @@ end
|
|||||||
|
|
||||||
local cachedItemList = nil
|
local cachedItemList = nil
|
||||||
--- Return the item info in oxs format, {name, label, stack, weight, description, image}
|
--- Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||||
--- https://docs.c8re.store/core-inventory/api/server#getitemslist
|
--- https://docs.c8re.store/core-inventory/exports#client-exports-%E2%80%94-inventory-ui
|
||||||
--- @param item string
|
--- @param item string
|
||||||
--- @return table
|
--- @return table
|
||||||
Inventory.GetItemInfo = function(item)
|
Inventory.GetItemInfo = function(item)
|
||||||
@@ -22,24 +20,22 @@ Inventory.GetItemInfo = function(item)
|
|||||||
return itemList[item] or {}
|
return itemList[item] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
---This will return the entire items table from the inventory.
|
---This will return the entire items table from the inventory in the ox format.
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.Items = function()
|
Inventory.Items = function()
|
||||||
local frameworkName = Framework.GetFrameworkName()
|
if cachedItemList then return cachedItemList end
|
||||||
if not frameworkName then return {} end
|
local allItems = core:getItemsList()
|
||||||
|
if not allItems then return {} end
|
||||||
local dataRepack = {}
|
local dataRepack = {}
|
||||||
if frameworkName == 'es_extended' then
|
for itemName, itemData in pairs(allItems) do
|
||||||
if not cachedItemList then cachedItemList = Callback.Trigger('community_bridge:Callback:core_inventory', false) end
|
|
||||||
dataRepack = cachedItemList or {}
|
|
||||||
elseif frameworkName == 'qb-core' then
|
|
||||||
dataRepack = Framework.Shared.Items or {}
|
|
||||||
end
|
|
||||||
for itemName, itemData in pairs(dataRepack) do
|
|
||||||
if itemData and itemData.name then
|
if itemData and itemData.name then
|
||||||
dataRepack[itemName].image = Inventory.GetImagePath(itemData.name)
|
dataRepack[itemName] = {
|
||||||
dataRepack[itemName].stack = dataRepack[itemName].unique or false
|
image = Inventory.GetImagePath(itemData.name),
|
||||||
|
stack = itemData.unique or false
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
cachedItemList = dataRepack
|
||||||
return dataRepack
|
return dataRepack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ if GetResourceState('core_inventory') == 'missing' then return end
|
|||||||
|
|
||||||
Inventory = Inventory or {}
|
Inventory = Inventory or {}
|
||||||
Inventory.Stashes = Inventory.Stashes or {}
|
Inventory.Stashes = Inventory.Stashes or {}
|
||||||
Callback = Callback or Require("lib/callback/shared/callback.lua")
|
|
||||||
local core = exports.core_inventory
|
local core = exports.core_inventory
|
||||||
|
|
||||||
---This will get the name of the in use resource.
|
---This will get the name of the in use resource.
|
||||||
@@ -20,8 +19,7 @@ end
|
|||||||
---@param metadata table
|
---@param metadata table
|
||||||
---@return boolean
|
---@return boolean
|
||||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||||
-- docs specify a table returned on success, on failure it returns false.
|
-- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items
|
||||||
-- https://docs.c8re.store/core-inventory/api/server#additem
|
|
||||||
local success = core:addItem(src, item, count, metadata)
|
local success = core:addItem(src, item, count, metadata)
|
||||||
if not success then return false end
|
if not success then return false end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||||
@@ -48,16 +46,8 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
|||||||
end
|
end
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||||
if slot then
|
if slot then
|
||||||
local identifier = Framework.GetPlayerIdentifier(src)
|
-- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items
|
||||||
if not identifier then return false end
|
return core:removeItemExact(src, slot, count)
|
||||||
local framework = Bridge.Framework.GetFrameworkName()
|
|
||||||
if framework == 'es_extended' then
|
|
||||||
identifier = string.gsub(identifier, ":", "")
|
|
||||||
end
|
|
||||||
local weirdInventoryName = 'content-' .. identifier
|
|
||||||
-- No return value specified in docs, so we assume none.
|
|
||||||
-- https://docs.c8re.store/core-inventory/api/server#removeitemexact
|
|
||||||
return core:removeItemExact(weirdInventoryName, slot, count)
|
|
||||||
end
|
end
|
||||||
core:removeItem(src, item, count)
|
core:removeItem(src, item, count)
|
||||||
return true
|
return true
|
||||||
@@ -249,12 +239,6 @@ Inventory.GetImagePath = function(item)
|
|||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
---This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this.
|
|
||||||
Callback.Register('community_bridge:Callback:core_inventory', function(source)
|
|
||||||
local items = core:getItemsList()
|
|
||||||
return items or {}
|
|
||||||
end)
|
|
||||||
|
|
||||||
---This will return the entire items table from the inventory.
|
---This will return the entire items table from the inventory.
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.Items = function()
|
Inventory.Items = function()
|
||||||
|
|||||||
Reference in new issue
Block a user