Inventory Update
Added serverside iteminfo and consolidated image path. Now returns full nui path in .image
This commit is contained in:
1 parent
5d3a9d1950
commit
bd0074a156
22 files changed
+83
-9
No files matched your search
@@ -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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user