2025-05-09 02:00:02 -04:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
2025-01-13 14:28:09 -05:00
|
|
|
if GetResourceState('ps-inventory') ~= 'started' then return end
|
2025-02-17 12:57:20 -05:00
|
|
|
local ps = exports['ps-inventory']
|
2025-02-17 12:56:06 -05:00
|
|
|
|
2025-01-13 14:28:09 -05:00
|
|
|
Inventory = Inventory or {}
|
|
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
|
|
|
|
---@param item string
|
|
|
|
|
---@return table
|
|
|
|
|
Inventory.GetItemInfo = function(item)
|
|
|
|
|
local itemData = Framework.Shared.Items[item]
|
|
|
|
|
if not itemData then return {} end
|
|
|
|
|
return {
|
|
|
|
|
name = itemData.name,
|
|
|
|
|
label = itemData.label,
|
|
|
|
|
stack = itemData.unique,
|
|
|
|
|
weight = itemData.weight,
|
|
|
|
|
description = itemData.description,
|
|
|
|
|
image = Inventory.GetImagePath(itemData.name)
|
|
|
|
|
}
|
|
|
|
|
end
|
2025-03-03 01:09:24 -05:00
|
|
|
|
2025-07-09 17:26:16 -04:00
|
|
|
---This will return the entire items table from the inventory.
|
|
|
|
|
---@return table
|
|
|
|
|
Inventory.Items = function()
|
|
|
|
|
return Framework.Shared.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:56:06 -05:00
|
|
|
Inventory.HasItem = function(item)
|
2025-02-17 12:57:20 -05:00
|
|
|
return ps:HasItem(item)
|
2025-02-17 12:56:06 -05:00
|
|
|
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-13 14:28:09 -05:00
|
|
|
Inventory.GetImagePath = function(item)
|
2025-04-16 05:24:03 -05:00
|
|
|
item = Inventory.StripPNG(item)
|
2025-01-13 14:28:09 -05:00
|
|
|
local file = LoadResourceFile("ps-inventory", string.format("html/images/%s.png", item))
|
|
|
|
|
local imagePath = file and string.format("nui://ps-inventory/html/images/%s.png", item)
|
|
|
|
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
2025-02-17 12:56:06 -05:00
|
|
|
end
|
2025-04-10 07:04:15 -04:00
|
|
|
|
2025-05-09 03:17:28 -04:00
|
|
|
RegisterNetEvent('community_bridge:client:ps-inventory:openStash', function(id, data)
|
|
|
|
|
if source ~= 65535 then return end
|
|
|
|
|
TriggerEvent('ps-inventory:client:SetCurrentStash', id)
|
|
|
|
|
TriggerServerEvent('ps-inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
2025-05-10 00:01:56 -04:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return Inventory
|