2025-05-09 02:00:02 -04:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
2025-12-14 16:22:35 -05:00
|
|
|
if GetResourceState('origen_inventory') == 'missing' then return end
|
|
|
|
|
if GetResourceState('ox_inventory') ~= 'missing' then return end
|
2025-01-10 16:36:20 -05:00
|
|
|
Inventory = Inventory or {}
|
2025-01-31 19:15:33 -05:00
|
|
|
local origin = exports.origen_inventory
|
2025-01-10 16:36:20 -05:00
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description This will get the name of the in use resource.
|
|
|
|
|
---@return string
|
|
|
|
|
Inventory.GetResourceName = function()
|
|
|
|
|
return "origen_inventory"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@description 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)
|
2025-12-14 16:22:35 -05:00
|
|
|
local itemData = Inventory.Items()[item]
|
2025-05-09 02:00:02 -04:00
|
|
|
if not itemData then return {} end
|
|
|
|
|
return {
|
2025-01-10 16:36:20 -05:00
|
|
|
name = itemData.name or "Missing Name",
|
|
|
|
|
label = itemData.label or "Missing Label",
|
|
|
|
|
stack = itemData.unique or "false",
|
|
|
|
|
weight = itemData.weight or "0",
|
|
|
|
|
description = itemData.description or "none",
|
|
|
|
|
image = itemData.image or Inventory.GetImagePath(item),
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description Will return boolean if the player has the item.
|
2025-03-03 01:09:24 -05:00
|
|
|
---@param item string
|
2025-12-14 16:22:35 -05:00
|
|
|
---@param requiredCount number (optional)
|
2025-03-03 01:09:24 -05:00
|
|
|
---@return boolean
|
2025-12-14 16:22:35 -05:00
|
|
|
Inventory.HasItem = function(item, requiredCount)
|
|
|
|
|
local count = Inventory.GetItemCount(item)
|
|
|
|
|
return count >= (requiredCount or 1)
|
2025-02-17 12:50:50 -05:00
|
|
|
end
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description This will return their 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)
|
2025-05-09 03:17:28 -04:00
|
|
|
local inventory = origin:Search('count', item)
|
|
|
|
|
if not inventory then return 0 end
|
|
|
|
|
return inventory.count
|
2025-04-07 14:37:22 -04:00
|
|
|
end
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description 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("origen_inventory", string.format("html/images/%s.png", item))
|
|
|
|
|
local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item)
|
|
|
|
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
2025-02-05 01:54:55 -05:00
|
|
|
end
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description 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
|
|
|
local repack = {}
|
2025-02-05 01:54:55 -05:00
|
|
|
local inventory = origin:GetInventory()
|
2025-05-09 03:17:28 -04:00
|
|
|
if not inventory then return {} end
|
2025-02-05 01:54:55 -05:00
|
|
|
for _, v in pairs(inventory) do
|
2025-05-09 03:17:28 -04:00
|
|
|
table.insert(repack, {
|
2025-02-05 01:54:55 -05:00
|
|
|
name = v.name,
|
|
|
|
|
label = v.label,
|
2025-12-14 16:22:35 -05:00
|
|
|
count = v.amount or v.count,
|
2025-02-05 01:54:55 -05:00
|
|
|
slot = v.slot,
|
2025-12-14 16:22:35 -05:00
|
|
|
metadata = v.metadata or v.info or {},
|
|
|
|
|
stack = v.unique or v.stack or false,
|
2025-02-05 01:54:55 -05:00
|
|
|
close = v.useable,
|
|
|
|
|
weight = v.weight
|
|
|
|
|
})
|
|
|
|
|
end
|
2025-05-09 03:17:28 -04:00
|
|
|
return repack
|
2025-05-09 06:21:18 -04:00
|
|
|
end
|
|
|
|
|
|
2025-05-10 00:01:56 -04:00
|
|
|
return Inventory
|