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
|
||||
if GetResourceState('core_inventory') == 'missing' then return end
|
||||
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 {}
|
||||
|
||||
@@ -14,7 +12,7 @@ end
|
||||
|
||||
local cachedItemList = nil
|
||||
--- 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
|
||||
--- @return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -22,24 +20,22 @@ Inventory.GetItemInfo = function(item)
|
||||
return itemList[item] or {}
|
||||
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
|
||||
Inventory.Items = function()
|
||||
local frameworkName = Framework.GetFrameworkName()
|
||||
if not frameworkName then return {} end
|
||||
if cachedItemList then return cachedItemList end
|
||||
local allItems = core:getItemsList()
|
||||
if not allItems then return {} end
|
||||
local dataRepack = {}
|
||||
if frameworkName == 'es_extended' then
|
||||
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
|
||||
for itemName, itemData in pairs(allItems) do
|
||||
if itemData and itemData.name then
|
||||
dataRepack[itemName].image = Inventory.GetImagePath(itemData.name)
|
||||
dataRepack[itemName].stack = dataRepack[itemName].unique or false
|
||||
dataRepack[itemName] = {
|
||||
image = Inventory.GetImagePath(itemData.name),
|
||||
stack = itemData.unique or false
|
||||
}
|
||||
end
|
||||
end
|
||||
cachedItemList = dataRepack
|
||||
return dataRepack
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ if GetResourceState('core_inventory') == 'missing' then return end
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
Callback = Callback or Require("lib/callback/shared/callback.lua")
|
||||
local core = exports.core_inventory
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
@@ -20,8 +19,7 @@ end
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
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/api/server#additem
|
||||
-- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items
|
||||
local success = core:addItem(src, item, count, metadata)
|
||||
if not success then return false end
|
||||
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
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
if slot then
|
||||
local identifier = Framework.GetPlayerIdentifier(src)
|
||||
if not identifier then return false end
|
||||
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)
|
||||
-- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items
|
||||
return core:removeItemExact(src, slot, count)
|
||||
end
|
||||
core:removeItem(src, item, count)
|
||||
return true
|
||||
@@ -249,12 +239,6 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
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.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
|
||||
Reference in new issue
Block a user