From 53d27c528e1e3b51f1d484fec329fb5dbfb6c605 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Fri, 9 May 2025 03:17:28 -0400 Subject: [PATCH] minor cleanup, functions notated --- modules/inventory/codem-inventory/client.lua | 23 +++--- modules/inventory/core_inventory/client.lua | 82 ++++++++++--------- modules/inventory/jpr-inventory/client.lua | 51 ++++++------ modules/inventory/origen_inventory/client.lua | 30 +++---- modules/inventory/ox_inventory/client.lua | 20 ++--- modules/inventory/ps-inventory/client.lua | 51 ++++++------ modules/inventory/qb-inventory/client.lua | 47 +++++------ modules/inventory/qs-inventory/client.lua | 38 ++++----- modules/inventory/tgiann-inventory/client.lua | 33 ++++---- 9 files changed, 188 insertions(+), 187 deletions(-) diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index 2b7a208..ea2b347 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -4,7 +4,7 @@ Inventory = Inventory or {} local codem = exports['codem-inventory'] ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -21,7 +21,17 @@ Inventory.GetItemInfo = function(item) } end ----comment +---This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() local items = {} @@ -41,12 +51,3 @@ Inventory.GetPlayerInventory = function() return items end ----comment ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end \ No newline at end of file diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index c3d6ddc..f31858c 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -1,50 +1,12 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('core_inventory') ~= 'started' then return end - -Inventory = Inventory or {} - local core = exports.core_inventory Inventory = Inventory or {} ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item)) - local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end - ----comment ----@param item string ----@return boolean -Inventory.HasItem = function(item) - return core:hasItem(item, 1) -end - ----comment ----@param item string ----@return number -Inventory.GetItemCount = function(item) - return core:getItemCount(item) -end - -Inventory.GetPlayerInventory = function() - local playerItems = core:getInventory() - local repackedTable = {} - for _, v in pairs(playerItems) do - table.insert(repackedTable, { - name = v.name, - count = v.count, - metadata = v.metadata, - slot = v.id, - }) - end - return repackedTable -end - +---@return table Inventory.GetItemInfo = function(item) local frameworkName = Framework.GetFrameworkName() if not frameworkName then return {} end @@ -59,4 +21,44 @@ Inventory.GetItemInfo = function(item) if not dataRepack then return {} end end return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) } +end + +---Will return boolean if the player has the item. +---@param item string +---@return boolean +Inventory.HasItem = function(item) + return core:hasItem(item, 1) +end + +---This will return th count of the item in the players inventory, if not found will return 0. +---@param item string +---@return number +Inventory.GetItemCount = function(item) + return core:getItemCount(item) +end + +---This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item)) + local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +---This will return the players inventory in the format of {name, label, count, slot, metadata} +---@return table +Inventory.GetPlayerInventory = function() + local playerItems = core:getInventory() + local repackedTable = {} + for _, v in pairs(playerItems) do + table.insert(repackedTable, { + name = v.name, + count = v.count, + metadata = v.metadata, + slot = v.id, + }) + end + return repackedTable end \ No newline at end of file diff --git a/modules/inventory/jpr-inventory/client.lua b/modules/inventory/jpr-inventory/client.lua index 6aeb6f8..a2b0422 100644 --- a/modules/inventory/jpr-inventory/client.lua +++ b/modules/inventory/jpr-inventory/client.lua @@ -1,32 +1,12 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('jpr-inventory') ~= 'started' then return end - local jpr = exports['jpr-inventory'] + Inventory = Inventory or {} -RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data) - if source ~= 65535 then return end - TriggerEvent("inventory:client:SetCurrentStash", id) - TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) -end) - ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ----@return boolean -Inventory.HasItem = function(item) - return jpr:HasItem(item) -end - ----comment ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end - +---@return table Inventory.GetItemInfo = function(item) local itemData = Framework.Shared.Items[item] if not itemData then return {} end @@ -38,4 +18,27 @@ Inventory.GetItemInfo = function(item) description = itemData.description, image = Inventory.GetImagePath(itemData.name) } -end \ No newline at end of file +end + +---Will return boolean if the player has the item. +---@param item string +---@return boolean +Inventory.HasItem = function(item) + return jpr:HasItem(item) +end + +---This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data) + if source ~= 65535 then return end + TriggerEvent("inventory:client:SetCurrentStash", id) + TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) +end) \ No newline at end of file diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index 6e76284..8f70ff1 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -1,11 +1,9 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('origen_inventory') ~= 'started' then return end - Inventory = Inventory or {} - local origin = exports.origen_inventory ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -21,26 +19,23 @@ Inventory.GetItemInfo = function(item) } end ----comment +---Will return boolean if the player has the item. ---@param item string ---@return boolean Inventory.HasItem = function(item) return origin:HasItem(item) end ----comment +---This will return th count of the item in the players inventory, if not found will return 0. ---@param item string ---@return number Inventory.GetItemCount = function(item) - local searchItem = origin:Search('slots', item) - local count = 0 - for _, v in pairs(searchItem) do - count = count + v.count - end - return count + local inventory = origin:Search('count', item) + if not inventory then return 0 end + return inventory.count end ----comment +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -50,13 +45,14 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----comment +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() - local items = {} + local repack = {} local inventory = origin:GetInventory() + if not inventory then return {} end for _, v in pairs(inventory) do - table.insert(items, { + table.insert(repack, { name = v.name, label = v.label, count = v.count, @@ -67,5 +63,5 @@ Inventory.GetPlayerInventory = function() weight = v.weight }) end - return items -end + return repack +end \ No newline at end of file diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 284edd6..1fcbaea 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -4,7 +4,7 @@ local ox_inventory = exports.ox_inventory Inventory = Inventory or {} ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -20,23 +20,21 @@ Inventory.GetItemInfo = function(item) } end ----comment +---Will return boolean if the player has the item. ---@param item string ---@return boolean Inventory.HasItem = function(item) - local itemCount = ox_inventory:Search('count', item) - local hasItem = itemCount ~= 0 - return hasItem + return ox_inventory:Search('count', item) > 0 end ----comment +---This will return th count of the item in the players inventory, if not found will return 0. ---@param item string ---@return number Inventory.GetItemCount = function(item) return ox_inventory:GetItemCount(item, nil, false) end ----comment +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -46,14 +44,12 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----comment +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() - return exports.ox_inventory:GetPlayerItems() + return ox_inventory:GetPlayerItems() end Inventory.OpenShop = function(shopTitle, shopInventory) ox_inventory:openInventory("shop", { type = shopTitle, id = 1 }) -end - ---Bridge.RegisterModule("Inventory", Inventory) +end \ No newline at end of file diff --git a/modules/inventory/ps-inventory/client.lua b/modules/inventory/ps-inventory/client.lua index cf69bb0..b56364d 100644 --- a/modules/inventory/ps-inventory/client.lua +++ b/modules/inventory/ps-inventory/client.lua @@ -1,34 +1,12 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('ps-inventory') ~= 'started' then return end - local ps = exports['ps-inventory'] Inventory = Inventory or {} -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 }) -end) - - ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ----@return boolean -Inventory.HasItem = function(item) - return ps:HasItem(item) -end - ----comment ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - 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" -end - +---@return table Inventory.GetItemInfo = function(item) local itemData = Framework.Shared.Items[item] if not itemData then return {} end @@ -40,4 +18,27 @@ Inventory.GetItemInfo = function(item) description = itemData.description, image = Inventory.GetImagePath(itemData.name) } -end \ No newline at end of file +end + +---Will return boolean if the player has the item. +---@param item string +---@return boolean +Inventory.HasItem = function(item) + return ps:HasItem(item) +end + +---This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + 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" +end + +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 }) +end) \ No newline at end of file diff --git a/modules/inventory/qb-inventory/client.lua b/modules/inventory/qb-inventory/client.lua index 10cab4f..ef831f0 100644 --- a/modules/inventory/qb-inventory/client.lua +++ b/modules/inventory/qb-inventory/client.lua @@ -1,33 +1,12 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('qb-inventory') ~= 'started' then return end - local qb = exports['qb-inventory'] Inventory = Inventory or {} -RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id, data) - if source ~= 65535 then return end - TriggerEvent("inventory:client:SetCurrentStash", id) - TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) -end) - ----This will return a boolean if the player has the item in their inventory +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ----@return boolean -Inventory.HasItem = function(item) - return qb:HasItem(item) -end - ----This will return a string of the image path for the item ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("qb-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end - +---@return table Inventory.GetItemInfo = function(item) local itemData = Framework.Shared.Items[item] if not itemData then return {} end @@ -41,3 +20,25 @@ Inventory.GetItemInfo = function(item) } end +---Will return boolean if the player has the item. +---@param item string +---@return boolean +Inventory.HasItem = function(item) + return qb:HasItem(item) +end + +---This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("qb-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id, data) + if source ~= 65535 then return end + TriggerEvent("inventory:client:SetCurrentStash", id) + TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) +end) \ No newline at end of file diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index a1058aa..384710a 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -1,16 +1,10 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('qs-inventory') ~= 'started' then return end local quasar = exports["qs-inventory"] + Inventory = Inventory or {} ----comment ----@param id any ----@return nil -Inventory.OpenStash = function(id) - quasar:RegisterStash(id, 50, 50000) -end - ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -28,7 +22,7 @@ Inventory.GetItemInfo = function(item) } end ----comment +---Will return boolean if the player has the item. ---@param item string ---@return boolean Inventory.HasItem = function(item) @@ -36,7 +30,15 @@ Inventory.HasItem = function(item) return check and true or false end ----comment +---This will return th count of the item in the players inventory, if not found will return 0. +---@param item string +---@return number +Inventory.GetItemCount = function(item) + local searchItem = quasar:Search(item) + return searchItem or 0 +end + +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -46,15 +48,7 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----comment ----@param item string ----@return number -Inventory.GetItemCount = function(item) - local searchItem = quasar:Search(item) - return searchItem or 0 -end - ----comment +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() local items = {} @@ -74,3 +68,9 @@ Inventory.GetPlayerInventory = function() return items end +---comment +---@param id any +---@return nil +Inventory.OpenStash = function(id) + quasar:RegisterStash(id, 50, 50000) +end diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index ed33bd8..75c055e 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -4,12 +4,7 @@ local tgiann = exports["tgiann-inventory"] Inventory = Inventory or {} ----@param id any ----@return nil -Inventory.OpenStash = function(id) - -- open stash export... not sure what it is yet. -end - +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -25,7 +20,14 @@ Inventory.GetItemInfo = function(item) } end ----comment +---Will return boolean if the player has the item. +---@param item string +---@return boolean +Inventory.HasItem = function(item) + return tgiann:HasItem(item) +end + +---This will return th count of the item in the players inventory, if not found will return 0. ---@param item string ---@return number Inventory.GetItemCount = function(item) @@ -33,14 +35,7 @@ Inventory.GetItemCount = function(item) return searchItem or 0 end ----This will return a boolean if the player has the item in the inventory ----@param item string ----@return boolean -Inventory.HasItem = function(item) - return tgiann:HasItem(item) -end - --- This will return the image path, it is incredibley useful for menus etc +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -51,7 +46,7 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----This will return the player inventory in a table +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() local items = {} @@ -70,3 +65,9 @@ Inventory.GetPlayerInventory = function() end return items end + +---@param id any +---@return nil +Inventory.OpenStash = function(id) + -- open stash export... not sure what it is yet. +end \ No newline at end of file