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
+184 -183

No files matched your search

+12 -11
View File
@@ -4,7 +4,7 @@ Inventory = Inventory or {}
local codem = exports['codem-inventory'] local codem = exports['codem-inventory']
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
@@ -21,7 +21,17 @@ Inventory.GetItemInfo = function(item)
} }
end 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 ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local items = {}
@@ -41,12 +51,3 @@ Inventory.GetPlayerInventory = function()
return items return items
end 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 ---@diagnostic disable: duplicate-set-field
if GetResourceState('core_inventory') ~= 'started' then return end if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {}
local core = exports.core_inventory local core = exports.core_inventory
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return string ---@return table
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
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local frameworkName = Framework.GetFrameworkName() local frameworkName = Framework.GetFrameworkName()
if not frameworkName then return {} end if not frameworkName then return {} end
@@ -60,3 +22,43 @@ Inventory.GetItemInfo = function(item)
end end
return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) } return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) }
end 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
+26 -23
View File
@@ -1,32 +1,12 @@
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
if GetResourceState('jpr-inventory') ~= 'started' then return end if GetResourceState('jpr-inventory') ~= 'started' then return end
local jpr = exports['jpr-inventory'] local jpr = exports['jpr-inventory']
Inventory = Inventory or {} Inventory = Inventory or {}
RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data) ---Return the item info in oxs format, {name, label, stack, weight, description, image}
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
---@param item string ---@param item string
---@return boolean ---@return table
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
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = Framework.Shared.Items[item] local itemData = Framework.Shared.Items[item]
if not itemData then return {} end if not itemData then return {} end
@@ -39,3 +19,26 @@ Inventory.GetItemInfo = function(item)
image = Inventory.GetImagePath(itemData.name) 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)
+12 -16
View File
@@ -1,11 +1,9 @@
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
if GetResourceState('origen_inventory') ~= 'started' then return end if GetResourceState('origen_inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local origin = exports.origen_inventory local origin = exports.origen_inventory
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
@@ -21,26 +19,23 @@ Inventory.GetItemInfo = function(item)
} }
end end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
return origin:HasItem(item) return origin:HasItem(item)
end end
---comment ---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
local searchItem = origin:Search('slots', item) local inventory = origin:Search('count', item)
local count = 0 if not inventory then return 0 end
for _, v in pairs(searchItem) do return inventory.count
count = count + v.count
end
return count
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -50,13 +45,14 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local repack = {}
local inventory = origin:GetInventory() local inventory = origin:GetInventory()
if not inventory then return {} end
for _, v in pairs(inventory) do for _, v in pairs(inventory) do
table.insert(items, { table.insert(repack, {
name = v.name, name = v.name,
label = v.label, label = v.label,
count = v.count, count = v.count,
@@ -67,5 +63,5 @@ Inventory.GetPlayerInventory = function()
weight = v.weight weight = v.weight
}) })
end end
return items return repack
end end
+7 -11
View File
@@ -4,7 +4,7 @@ local ox_inventory = exports.ox_inventory
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
@@ -20,23 +20,21 @@ Inventory.GetItemInfo = function(item)
} }
end end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
local itemCount = ox_inventory:Search('count', item) return ox_inventory:Search('count', item) > 0
local hasItem = itemCount ~= 0
return hasItem
end end
---comment ---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
return ox_inventory:GetItemCount(item, nil, false) return ox_inventory:GetItemCount(item, nil, false)
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -46,14 +44,12 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
return exports.ox_inventory:GetPlayerItems() return ox_inventory:GetPlayerItems()
end end
Inventory.OpenShop = function(shopTitle, shopInventory) Inventory.OpenShop = function(shopTitle, shopInventory)
ox_inventory:openInventory("shop", { type = shopTitle, id = 1 }) ox_inventory:openInventory("shop", { type = shopTitle, id = 1 })
end end
--Bridge.RegisterModule("Inventory", Inventory)
+25 -24
View File
@@ -1,34 +1,12 @@
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
if GetResourceState('ps-inventory') ~= 'started' then return end if GetResourceState('ps-inventory') ~= 'started' then return end
local ps = exports['ps-inventory'] local ps = exports['ps-inventory']
Inventory = Inventory or {} Inventory = Inventory or {}
RegisterNetEvent('community_bridge:client:ps-inventory:openStash', function(id, data) ---Return the item info in oxs format, {name, label, stack, weight, description, image}
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
---@param item string ---@param item string
---@return boolean ---@return table
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
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = Framework.Shared.Items[item] local itemData = Framework.Shared.Items[item]
if not itemData then return {} end if not itemData then return {} end
@@ -41,3 +19,26 @@ Inventory.GetItemInfo = function(item)
image = Inventory.GetImagePath(itemData.name) 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 ---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-inventory') ~= 'started' then return end if GetResourceState('qb-inventory') ~= 'started' then return end
local qb = exports['qb-inventory'] local qb = exports['qb-inventory']
Inventory = Inventory or {} Inventory = Inventory or {}
RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id, data) ---Return the item info in oxs format, {name, label, stack, weight, description, image}
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
---@param item string ---@param item string
---@return boolean ---@return table
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
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = Framework.Shared.Items[item] local itemData = Framework.Shared.Items[item]
if not itemData then return {} end if not itemData then return {} end
@@ -41,3 +20,25 @@ Inventory.GetItemInfo = function(item)
} }
end 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 ---@diagnostic disable: duplicate-set-field
if GetResourceState('qs-inventory') ~= 'started' then return end if GetResourceState('qs-inventory') ~= 'started' then return end
local quasar = exports["qs-inventory"] local quasar = exports["qs-inventory"]
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param id any
---@return nil
Inventory.OpenStash = function(id)
quasar:RegisterStash(id, 50, 50000)
end
---comment
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
@@ -28,7 +22,7 @@ Inventory.GetItemInfo = function(item)
} }
end end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
@@ -36,7 +30,15 @@ Inventory.HasItem = function(item)
return check and true or false return check and true or false
end 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 ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -46,15 +48,7 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@param item string
---@return number
Inventory.GetItemCount = function(item)
local searchItem = quasar:Search(item)
return searchItem or 0
end
---comment
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local items = {}
@@ -74,3 +68,9 @@ Inventory.GetPlayerInventory = function()
return items return items
end 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 {} Inventory = Inventory or {}
---@param id any ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@return nil
Inventory.OpenStash = function(id)
-- open stash export... not sure what it is yet.
end
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
@@ -25,7 +20,14 @@ Inventory.GetItemInfo = function(item)
} }
end 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 ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
@@ -33,14 +35,7 @@ Inventory.GetItemCount = function(item)
return searchItem or 0 return searchItem or 0
end end
---This will return a boolean if the player has the item in the inventory ---This will get the image path for this item, if not found will return placeholder.
---@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
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -51,7 +46,7 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end 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 ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local items = {}
@@ -70,3 +65,9 @@ Inventory.GetPlayerInventory = function()
end end
return items return items
end end
---@param id any
---@return nil
Inventory.OpenStash = function(id)
-- open stash export... not sure what it is yet.
end