From bd0074a156486e2037c889f7effd3854c628fb39 Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Wed, 16 Apr 2025 05:24:03 -0500 Subject: [PATCH] Inventory Update Added serverside iteminfo and consolidated image path. Now returns full nui path in .image --- modules/framework/qb-core/server.lua | 12 ++++++++---- modules/inventory/_default/client.lua | 7 +++++++ modules/inventory/_default/server.lua | 7 +++++++ modules/inventory/codem-inventory/client.lua | 4 +++- modules/inventory/codem-inventory/server.lua | 1 + modules/inventory/core_inventory/client.lua | 1 + modules/inventory/core_inventory/server.lua | 1 + modules/inventory/jpr-inventory/client.lua | 1 + modules/inventory/jpr-inventory/server.lua | 1 + modules/inventory/origen_inventory/client.lua | 1 + modules/inventory/origen_inventory/server.lua | 1 + modules/inventory/ox_inventory/client.lua | 1 + modules/inventory/ox_inventory/server.lua | 19 +++++++++++++++++++ modules/inventory/ps-inventory/client.lua | 1 + modules/inventory/ps-inventory/server.lua | 1 + modules/inventory/qb-inventory/client.lua | 3 ++- modules/inventory/qb-inventory/server.lua | 16 ++++++++++++++++ modules/inventory/qs-inventory/client.lua | 1 + modules/inventory/qs-inventory/server.lua | 1 + modules/inventory/tgiann-inventory/client.lua | 1 + modules/inventory/tgiann-inventory/server.lua | 1 + modules/progressbar/qb-progressbar/client.lua | 10 +++++++--- 22 files changed, 83 insertions(+), 9 deletions(-) diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index ff641b1..8df05f2 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -5,7 +5,7 @@ if GetResourceState('qbx_core') == 'started' then return end QBCore = exports['qb-core']:GetCoreObject() Framework = {} - +Framework.Shared = QBCore.Shared Framework.GetFrameworkName = function() return 'qb-core' end @@ -222,7 +222,9 @@ Framework.AddHunger = function(src, value) local playerData = player.PlayerData local newHunger = (playerData.metadata.hunger or 0) + value player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100)) + TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst) --TriggerClientEvent('hud:client:UpdateStress', src, newStress) + return newHunger end @@ -235,6 +237,7 @@ Framework.AddThirst = function(src, value) local playerData = player.PlayerData local newThirst = (playerData.metadata.thirst or 0) + value player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100)) + TriggerClientEvent('hud:client:UpdateNeeds', src, playerData.metadata.hunger, newThirst) --TriggerClientEvent('hud:client:UpdateStress', src, newStress) return newThirst end @@ -412,8 +415,8 @@ Framework.SetMetadata = function(src, item, slot, metadata) end end end - player.Functions.RemoveItem(item, 1, itemSlot) - return player.Functions.AddItem(item, 1, freeSlot, metadata) + if not player.Functions.RemoveItem(item, 1, itemSlot) then return false end + return player.Functions.AddItem(item, 1, slot, metadata) end ---This will get all owned vehicles for the player @@ -460,4 +463,5 @@ end) Framework.Commands = {} Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...) QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...) -end \ No newline at end of file +end + diff --git a/modules/inventory/_default/client.lua b/modules/inventory/_default/client.lua index afd63b6..21991ad 100644 --- a/modules/inventory/_default/client.lua +++ b/modules/inventory/_default/client.lua @@ -26,4 +26,11 @@ end ---@return string Inventory.GetImagePath = function(item) return "https://avatars.githubusercontent.com/u/47620135" +end + +Inventory.StripPNG = function(item) + if string.find(item, ".png") then + item = string.gsub(item, ".png", "") + end + return item end \ No newline at end of file diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index 87eb68c..2d42c54 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -83,4 +83,11 @@ end ---@return string Inventory.GetImagePath = function(item) return "https://avatars.githubusercontent.com/u/47620135" +end + +Inventory.StripPNG = function(item) + if string.find(item, ".png") then + item = string.gsub(item, ".png", "") + end + return item end \ No newline at end of file diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index fc616b5..11be4c5 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -8,13 +8,14 @@ local codem = exports['codem-inventory'] ---@return table Inventory.GetItemInfo = function(item) local itemData = codem:GetItemList(item) + local image = itemData.image and Inventory.GetImagePath(itemData.image) or Inventory.GetImagePath(item) local repackedTable = { 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), + image = image, } return repackedTable or {} end @@ -43,6 +44,7 @@ end ---@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" diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 55d0b3b..cbf6847 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -86,6 +86,7 @@ Inventory.GetItemBySlot = function(src, slot) end 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" diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index 21d4fac..2e9cce0 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -10,6 +10,7 @@ Inventory = Inventory or {} ---@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" diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index 1fbfaca..f4aa30d 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -8,6 +8,7 @@ local core = exports.core_inventory ---@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" diff --git a/modules/inventory/jpr-inventory/client.lua b/modules/inventory/jpr-inventory/client.lua index 7f1afdd..f7deebc 100644 --- a/modules/inventory/jpr-inventory/client.lua +++ b/modules/inventory/jpr-inventory/client.lua @@ -20,6 +20,7 @@ end ---@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" diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index 06b4f12..9c7cf01 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -43,6 +43,7 @@ end ---@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" diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index 7f86414..a7f8359 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -43,6 +43,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) 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" diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index 5605d56..4bc27d4 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -104,6 +104,7 @@ Inventory.SetMetadata = function(src, item, slot, metadata) end Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) 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" diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 721f8ca..766c571 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -40,6 +40,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) 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" diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index e16db1e..a195b31 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -16,6 +16,24 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return ox_inventory:AddItem(src, item, count, metadata) end +Inventory.GetItemInfo = function(item) + local itemData = ox_inventory:Items(item) + if not itemData then return {} end + local repackedTable = { + 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 = string.format("nui://ox_inventory/web/images/%s", itemData.client + and itemData.client.image + or string.format("%s.png", item) + ), + } + return repackedTable +end +-- string.format("nui://ox_inventory/web/images/%s.png", item) + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string @@ -148,6 +166,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) 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" diff --git a/modules/inventory/ps-inventory/client.lua b/modules/inventory/ps-inventory/client.lua index 7e459e2..6d37dd6 100644 --- a/modules/inventory/ps-inventory/client.lua +++ b/modules/inventory/ps-inventory/client.lua @@ -22,6 +22,7 @@ end ---@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" diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index 3854241..ff95702 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -36,6 +36,7 @@ end ---@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" diff --git a/modules/inventory/qb-inventory/client.lua b/modules/inventory/qb-inventory/client.lua index 2507543..0818f4f 100644 --- a/modules/inventory/qb-inventory/client.lua +++ b/modules/inventory/qb-inventory/client.lua @@ -21,6 +21,7 @@ end ---@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" @@ -35,7 +36,7 @@ Inventory.GetItemInfo = function(item) stack = itemData.unique, weight = itemData.weight, description = itemData.description, - image = Inventory.GetImagePath(itemData.name) + image = Inventory.GetImagePath(itemData.image or itemData.name) } return repackedTable end diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index 03b43ff..ba70836 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -40,10 +40,26 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo end +Inventory.GetItemInfo = function(item) + local itemData = Framework.Shared.Items[item] + if not itemData then return {} end + local repackedTable = { + name = itemData.name, + label = itemData.label, + stack = itemData.unique, + weight = itemData.weight, + description = itemData.description, + image = Inventory.GetImagePath(itemData.image or itemData.name) + } + return repackedTable +end + ---comment ---@param item string ---@return string Inventory.GetImagePath = function(item) + -- check if contains.png and remove it if it does + 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" diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index 99a9c8b..91a1671 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -39,6 +39,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item)) local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index a3496d1..699917f 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -153,6 +153,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item)) local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index 93183fd..5ddcee4 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -44,6 +44,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item)) local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item)) local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item) diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index 0456e1d..6219a5e 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -135,6 +135,7 @@ end ---@param item string ---@return string Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item)) local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item)) local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item) diff --git a/modules/progressbar/qb-progressbar/client.lua b/modules/progressbar/qb-progressbar/client.lua index a98cf58..5540dce 100644 --- a/modules/progressbar/qb-progressbar/client.lua +++ b/modules/progressbar/qb-progressbar/client.lua @@ -44,15 +44,19 @@ end ---@param options table ---@param cb any ---@param qbFormat boolean ----@return nil +---@return success boolean function ProgressBar.Open(options, cb, qbFormat) if not exports['progressbar'] then return false end if not qbFormat then options = convertFromOx(options) end - - exports['progressbar']:Progress(options, cb) + local prom = promise.new() + exports['progressbar']:Progress(options, function(cancelled) + if cb then cb(not cancelled) end + prom:resolve(not cancelled) + end) + return Citizen.Await(prom) end