minor cleanup, functions notated

This commit is contained in:
MrNewb committed 2025-05-09 03:17:28 -04:00
1 parent c651b767ba
commit 53d27c528e
9 files changed
+188 -187

No files matched your search

+12 -11
View File
@@ -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
+42 -40
View File
@@ -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
+27 -24
View File
@@ -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
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)
+13 -17
View File
@@ -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
+8 -12
View File
@@ -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
+26 -25
View File
@@ -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
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)
+24 -23
View File
@@ -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)
+19 -19
View File
@@ -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
+17 -16
View File
@@ -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