2025-05-09 02:00:02 -04:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
2025-01-10 16:36:20 -05:00
|
|
|
if GetResourceState('ox_inventory') ~= 'started' then return end
|
2025-06-18 09:55:22 -04:00
|
|
|
if GetResourceState('qs-inventory') == 'started' then return end
|
|
|
|
|
if GetResourceState('origen_inventory') == 'started' then return end
|
|
|
|
|
|
2025-01-10 16:36:20 -05:00
|
|
|
local ox_inventory = exports.ox_inventory
|
|
|
|
|
|
|
|
|
|
Inventory = Inventory or {}
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
2025-03-03 01:09:24 -05:00
|
|
|
---@param item string
|
|
|
|
|
---@return table
|
2025-01-10 16:36:20 -05:00
|
|
|
Inventory.GetItemInfo = function(item)
|
|
|
|
|
local itemData = ox_inventory:Items(item)
|
|
|
|
|
if not itemData then return {} end
|
2025-05-09 02:00:02 -04:00
|
|
|
return {
|
2025-01-10 16:36:20 -05:00
|
|
|
name = itemData.name or "Missing Name",
|
|
|
|
|
label = itemData.label or "Missing Label",
|
|
|
|
|
stack = itemData.stack or "true",
|
|
|
|
|
weight = itemData.weight or "0",
|
|
|
|
|
description = itemData.description or "none",
|
|
|
|
|
image = (itemData.client and itemData.client.image) or Inventory.GetImagePath(item),
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-09 17:26:16 -04:00
|
|
|
---This will return the entire items table from the inventory.
|
|
|
|
|
---@return table
|
|
|
|
|
Inventory.Items = function()
|
|
|
|
|
return ox_inventory:Items()
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---Will return boolean if the player has the item.
|
2025-03-03 01:09:24 -05:00
|
|
|
---@param item string
|
|
|
|
|
---@return boolean
|
2025-02-17 12:52:37 -05:00
|
|
|
Inventory.HasItem = function(item)
|
2025-05-09 03:17:28 -04:00
|
|
|
return ox_inventory:Search('count', item) > 0
|
2025-02-17 12:52:37 -05:00
|
|
|
end
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---This will return th count of the item in the players inventory, if not found will return 0.
|
2025-04-07 14:37:22 -04:00
|
|
|
---@param item string
|
|
|
|
|
---@return number
|
|
|
|
|
Inventory.GetItemCount = function(item)
|
|
|
|
|
return ox_inventory:GetItemCount(item, nil, false)
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---This will get the image path for this item, if not found will return placeholder.
|
2025-03-03 01:09:24 -05:00
|
|
|
---@param item string
|
|
|
|
|
---@return string
|
2025-01-10 16:36:20 -05:00
|
|
|
Inventory.GetImagePath = function(item)
|
2025-04-16 05:24:03 -05:00
|
|
|
item = Inventory.StripPNG(item)
|
2025-01-10 16:36:20 -05:00
|
|
|
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
|
|
|
|
|
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
|
|
|
|
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
2025-03-03 01:09:24 -05:00
|
|
|
---@return table
|
2025-02-05 01:54:55 -05:00
|
|
|
Inventory.GetPlayerInventory = function()
|
2025-05-09 03:17:28 -04:00
|
|
|
return ox_inventory:GetPlayerItems()
|
2025-02-05 01:54:55 -05:00
|
|
|
end
|
|
|
|
|
|
2025-05-10 00:01:56 -04:00
|
|
|
return Inventory
|