diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 1d81bc3..fa9028f 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -72,7 +72,7 @@ Framework.GetItem = function(src, item, metadata) return repackedTable end ----This will get the data about an item such as name, label, stack, weight, description and image. +---This will return a table with the item info, {name, label, stack, weight, description, image} ---@param item string ---@return table Framework.GetItemInfo = function(item) @@ -89,8 +89,13 @@ Framework.GetItemInfo = function(item) return repackedTable end --- Framework.GetItemCount(src, item, metadata) --- Returns the count of items matching the specified name and if passed metadata from the player's inventory. +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. +---@param src number +---@param item string +---@param metadata table +---@return number Framework.GetItemCount = function(src, item, metadata) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -105,7 +110,7 @@ Framework.GetItemCount = function(src, item, metadata) return count end ----comment +---This will return a boolean if the player has the item. ---@param src number ---@param item string ---@return boolean diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index 48cfc2b..eac7130 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -1,37 +1,41 @@ ---@diagnostic disable: duplicate-set-field Inventory = Inventory or {} ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will add an item, and return true or false based on success ---@param src number ---@param item string ---@param count number ---@param slot number ---@param metadata table ----@return boolean|nil +---@return boolean Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) return Framework.AddItem(src, item, count, slot, metadata) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will remove an item, and return true or false based on success ---@param src number ---@param item string ---@param count number ---@param slot number ---@param metadata table ----@return boolean|nil +---@return boolean Inventory.RemoveItem = function(src, item, count, slot, metadata) item = type(item) == "table" and item.name or item + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) return Framework.RemoveItem(src, item, count, slot, metadata) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will return a table with the item info, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) return Framework.GetItemInfo(item) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. ---@param src number ---@param item string ---@param metadata table @@ -40,14 +44,16 @@ Inventory.GetItemCount = function(src, item, metadata) return Framework.GetItemCount(src, item, metadata) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This wil return the players inventory. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) return Framework.GetPlayerInventory(src) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ---@return table @@ -55,19 +61,32 @@ Inventory.GetItemBySlot = function(src, slot) return Framework.GetItemBySlot(src, slot) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ---@param slot number ---@param metadata table ----@return boolean +---@return nil Inventory.SetMetadata = function(src, item, slot, metadata) return Framework.SetMetadata(src, item, slot, metadata) end ----This will fallback to framework add item functions when an inventory does not have the specifiec function. +---This will open the specified stash for the src passed. ---@param src number ----@param id string||number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.") +end + +---This will register a stash +---@param id number||string ---@param label string ---@param slots number ---@param weight number @@ -75,11 +94,52 @@ end ---@param groups table ---@param coords table ---@return boolean -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.") end ----This will provide a image of the community bridge logo if the inventory isnt bridged for the specific path. +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return Framework.HasItem(src, item) +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return false, Prints.Error("This Inventory Has Not Been Bridged For A CanCarryItem Feature.") +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) +---@param oldplate string +---@param newplate string +---@return boolean +Inventory.UpdatePlate = function(oldplate, newplate) + return false, Prints.Error("This Inventory Has Not Been Bridged For A UpdatePlate Feature.") +end + +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + return false, Prints.Error("This Inventory Has Not Been Bridged For A OpenShop Feature.") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return false, Prints.Error("This Inventory Has Not Been Bridged For A CreateShop Feature.") +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) ---@param item string ---@return string Inventory.GetImagePath = function(item) diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index ea2b347..4893b37 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -51,3 +51,7 @@ Inventory.GetPlayerInventory = function() return items end +RegisterNetEvent('community_bridge:client:codem-inventory:openStash', function(id, data) + if source ~= 65535 then return end + TriggerServerEvent('codem-inventory:server:openstash', id, data.slots, data.weight, data.label) +end) \ No newline at end of file diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 8963a93..4f68f4b 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -5,6 +5,33 @@ Inventory = Inventory or {} local codem = exports['codem-inventory'] +---This will add an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return codem:AddItem(src, item, count, slot, metadata) +end + +---This will remove an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return codem:RemoveItem(src, item, count, slot) +end + +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table Inventory.GetItemInfo = function(item) local itemData = codem:GetItemList(item) if not itemData then return {} end @@ -18,15 +45,9 @@ Inventory.GetItemInfo = function(item) } end -Inventory.AddItem = function(src, item, count, slot, metadata) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) - return codem:AddItem(src, item, count, slot, metadata) -end - -Inventory.GetItemBySlot = function(src, slot) - return codem:GetItemBySlot(src, slot) -end - +---This wil return the players inventory. +---@param src number +---@return table Inventory.GetPlayerInventory = function(src) local identifier = Framework.GetPlayerIdentifier(src) local playerItems = codem:GetInventory(identifier, src) @@ -42,26 +63,65 @@ Inventory.GetPlayerInventory = function(src) return repackedTable end -Inventory.RemoveItem = function(src, item, count, slot, metadata) - if not slot and metadata then - local inv = Inventory.GetPlayerInventory(src) - if not inv then return false end - for _, v in pairs(inv) do - if v.name == item and v.metadata == metadata then - slot = v.slot - break - end - end - end - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) - return codem:RemoveItem(src, item, count, slot) +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table +Inventory.GetItemBySlot = function(src, slot) + local slotData = codem:GetItemBySlot(src, slot) + if not slotData then return {} end + return { + name = v.name, + label = v.label or v.name, + weight = v.weight, + slot = v.slot, + count = v.amount or v.count, + metadata = v.info or v.metadata, + stack = v.unique, + description = v.description + } end +---This will set the metadata of an item in the inventory. +---@param src number +---@param item string +---@param slot number +---@param metadata table +---@return nil Inventory.SetMetadata = function(src, item, slot, metadata) return codem:SetItemMetadata(src, slot, metadata) end ----comment +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + TriggerClientEvent('community_bridge:client:codem-inventory:openStash', src, id, { label = label, slots = slots, weight = weight }) +end + +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return true +end + +---This will return a boolean if the player has the item. ---@param src number ---@param item string ---@return boolean @@ -69,23 +129,26 @@ Inventory.HasItem = function(src, item) return codem:HasItem(src, item, 1) end -Inventory.GetItemBySlot = function(src, slot) - local slotData = codem:GetItemBySlot(src, slot) - if not slotData then return {} end - for _, v in pairs(slotData) do - return { - name = v.name, - label = v.name, - weight = v.weight, - slot = v.slot, - count = v.amount, - metadata = v.info, - stack = v.unique, - description = v.description - } - end +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return true end +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) +---@param oldplate string +---@param newplate string +---@return boolean +Inventory.UpdatePlate = function(oldplate, newplate) + return false, print("Unable to update plate for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.") +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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)) @@ -93,3 +156,19 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end + +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + print("Unable to open shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return true, print("Unable to Create Shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.") +end \ No newline at end of file diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index e190413..d9869fa 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -5,16 +5,6 @@ Inventory = Inventory or {} local core = exports.core_inventory ----comment ----@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 add an item, and return true or false based on success ---@param src number ---@param item string @@ -24,24 +14,16 @@ end ---@return boolean Inventory.AddItem = function(src, item, count, slot, metadata) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) - local itemsAdd = core:addItem(src, item, count, metadata) - return itemsAdd -end - -Inventory.GetPlayerInventory = function(src) - local playerItems = core:getInventory(src) - 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 + return core:addItem(src, item, count, metadata) end +---This will remove an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean Inventory.RemoveItem = function(src, item, count, slot, metadata) if not slot and metadata then local inv = Inventory.GetPlayerInventory(src) @@ -69,27 +51,9 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) -- I hate this inventory so much, I am so sorry for this. end ----This will get the item from the specified slot. ----@param src number ----@param slot number ----@return table -Inventory.GetItemBySlot = function(src, slot) - local inv = Inventory.GetPlayerInventory(src) - if not inv then return {} end - for _, v in pairs(inv) do - if v.slot == slot then - return { - name = v.name, - count = v.count, - metadata = v.metadata, - slot = v.slot, - } - end - end - return {} -end - ----Returns the total count of an item in the inventory. +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. ---@param src number ---@param item string ---@param metadata table @@ -110,13 +74,43 @@ Inventory.GetItemCount = function(src, item, metadata) return count or 0 end ----Returns boolean if the player has the item in their inventory. +---This wil return the players inventory. ---@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - local count = core:getItemCount(src, item) - return count > 0 +---@return table +Inventory.GetPlayerInventory = function(src) + local playerItems = core:getInventory(src) + 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 + +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table +Inventory.GetItemBySlot = function(src, slot) + local inv = Inventory.GetPlayerInventory(src) + if not inv then return {} end + for _, v in pairs(inv) do + if v.slot == slot then + return { + name = v.name, + count = v.count, + metadata = v.metadata, + slot = v.slot, + } + end + end + return {} end ---This will set the metadata of an item in the inventory. @@ -129,7 +123,56 @@ Inventory.SetMetadata = function(src, item, slot, metadata) core:setMetadata(src, slot, metadata) end ----comment +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + if not slots then slots = 30 end + local mathyShit = slots / 2 + core:openInventory(playerid, id, 'stash', mathyShit, mathyShit, true, nil, false) +end + +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + if not slots then slots = 30 end + local mathyShit = slots / 2 + core:openInventory(nil, id, 'stash', mathyShit, mathyShit, false, nil, false) + return true +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return core:getItemCount(src, item) > 0 +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return true +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -148,10 +191,37 @@ Inventory.UpdatePlate = function(oldplate, newplate) } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) end +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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 open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.") +end + + +-- This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this. lib.callback.register('community_bridge:Callback:core_inventory', function(source) local items = core:getItemsList() return items or {} diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index 908374f..df331af 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -2,55 +2,46 @@ if GetResourceState('jpr-inventory') ~= 'started' then return end local jpr = exports['jpr-inventory'] +local registeredShops = {} Inventory = Inventory or {} ----comment ----@param id string||number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return true -end - ----comment +---This will add an item, and return true or false based on success ---@param src number ---@param item string +---@param count number +---@param slot number +---@param metadata table ---@return boolean -Inventory.HasItem = function(src, item) - return jpr:HasItem(src, item, 1) +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return exports['jpr-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge Item added') end ----comment +---This will remove an item, and return true or false based on success ---@param src number ----@param id string||number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = weight, slots = slots }) -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" +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return exports['jpr-inventory']:RemoveItem(src, item, count, slot, 'community_bridge Item removed') end ----comment +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table +Inventory.GetItemInfo = function(item) + local itemTable = Framework.GetItemInfo(item) + itemTable.image = Inventory.GetImagePath(item) + return itemTable +end + +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ---@return table @@ -69,7 +60,51 @@ Inventory.GetItemBySlot = function(src, slot) } end ----comment +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = weight, slots = slots }) +end + +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return true +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return jpr:HasItem(src, item, 1) +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return true +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -81,18 +116,32 @@ Inventory.UpdatePlate = function(oldplate, newplate) local values = { newplate = newplate, oldplate = oldplate } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) end +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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 -local registeredShops = {} - +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string Inventory.OpenShop = function(src, shopTitle) - return jpr:OpenShop(src, shopTitle) + jpr:OpenShop(src, shopTitle) end -Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) if not shopTitle or not shopInventory or not shopCoords then return end if registeredShops[shopTitle] then return true end @@ -104,6 +153,5 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG jpr:CreateShop(repackedShopItems) registeredShops[shopTitle] = true - --Inventory.OpenShop(src, shopTitle) return true end \ No newline at end of file diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index a2e69f5..11d4cfa 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -3,29 +3,37 @@ if GetResourceState('origen_inventory') ~= 'started' then return end Inventory = Inventory or {} -local origen_inventory = exports.origen_inventory +local origin = exports.origen_inventory -Inventory.AddItem = function(src, item, count, slot, metadata) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) - return origen_inventory:AddItem(src, item, count, metadata, slot, true) -end - -Inventory.RemoveItem = function(src, item, count, slot, metadata) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) - return origen_inventory:removeItem(src, item, count, metadata, slot, true) -end - ----comment +---This will add an item, and return true or false based on success ---@param src number ---@param item string +---@param count number +---@param slot number +---@param metadata table ---@return boolean -Inventory.HasItem = function(src, item) - local count = origen_inventory:getItemCount(src , item) - return count > 0 +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return origin:AddItem(src, item, count, metadata, slot, true) end +---This will remove an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return origin:removeItem(src, item, count, metadata, slot, true) +end + +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table Inventory.GetItemInfo = function(item) - local itemData = origen_inventory:Items(item) + local itemData = origin:Items(item) if not itemData then return {} end return { name = itemData.name or "Missing Name", @@ -37,79 +45,106 @@ Inventory.GetItemInfo = function(item) } end + +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. +---@param src number +---@param item string +---@param metadata table +---@return number Inventory.GetItemCount = function(src, item, metadata) - if not metadata then - return origen_inventory:GetItemTotalAmount(src, item) - else - local items = origen_inventory:GetInventory(src) - local count = 0 - for _, itemInfo in pairs(items) do - if itemInfo.name == item and itemInfo.info == metadata or itemInfo.metadata == metadata then - count = count + itemInfo.count - end - end - return count - end + return origin:getItemCount(src, item, metadata, false) end +---This wil return the players inventory. +---@param src number +---@return table Inventory.GetPlayerInventory = function(src) - local playerItems = origen_inventory:GetInventory(src) - local repackedTable = {} - for _, v in pairs(playerItems.inventory) do - table.insert(repackedTable, { - name = v.name, - count = v.count, - metadata = v.metadata, - slot = v.slot, - }) - end - return repackedTable + return origin:GetInventory(src) end +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table Inventory.GetItemBySlot = function(src, slot) - -- This inventory got rid of almost all the great exports they had =( - local slotData = Inventory.GetInventoryItems(src) - for _, item in pairs(slotData) do - if item.slot == slot then + local inv = origin:getInventory(src) + for k, v in pairs(inv) do + if v.slot == slot then return { - name = item.name, - label = item.name, - weight = item.weight, - slot = slot, - count = item.amount, - metadata = item.metadata, - stack = item.unique or false, - description = item.description + weight = v.weight, + name = v.name, + metadata = v.metadata, + slot = v.slot, + label = v.label, + count = v.count } end end return {} end -Inventory.CanCarryItem = function(src, item, count) - return origen_inventory:CanCarryItems(src, item, count) -end - -Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return origen_inventory:RegisterStash(id, { label = label, slots = slots, weight = weight }) -end - -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - return origen_inventory:OpenInventory(src, 'stash', id) -end - +---This will set the metadata of an item in the inventory. +---@param src number +---@param item string +---@param slot number +---@param metadata table +---@return nil Inventory.SetMetadata = function(src, item, slot, metadata) - Inventory.RemoveItem (src, item, 1, slot, nil) - Inventory.AddItem(src, item, 1, slot, metadata) + origin:setMetadata(src, 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" +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + return origin:OpenInventory(src, 'stash', id) end +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return origin:registerStash(id, label, slots, weight, owner, groups, coords) +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return origin:getItemCount(src , item) > 0 +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return origin:canCarryItem(src, item, count) +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) +---@param oldplate string +---@param newplate string +---@return boolean Inventory.UpdatePlate = function(oldplate, newplate) local queries = { 'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate', @@ -118,6 +153,31 @@ Inventory.UpdatePlate = function(oldplate, newplate) local values = { newplate = newplate, oldplate = oldplate } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true -end \ No newline at end of file + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("origin", 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" +end + +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + print("Currently runtime shops are not supported in origen_inventory") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return true, print("Currently runtime shops are not supported in origen_inventory") +end diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index cbe0569..02e6cfb 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -2,6 +2,7 @@ if GetResourceState('ox_inventory') ~= 'started' then return end local ox_inventory = exports.ox_inventory +local registeredShops = {} Inventory = Inventory or {} @@ -17,20 +18,6 @@ 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 - return { - 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)), - } -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 @@ -43,24 +30,25 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) return ox_inventory:RemoveItem(src, item, count, metadata, slot) end ----comment ----@param src number +---This will return a table with the item info, {name, label, stack, weight, description, image} ---@param item string ----@param metadata table ---@return table -Inventory.GetItem = function(src, item, metadata) - return ox_inventory:GetItem(src, item, metadata, false) +Inventory.GetItemInfo = function(item) + local itemData = ox_inventory:Items(item) + if not itemData then return {} end + return { + 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)), + } end ----This will get the item from the specified slot. ----@param src number ----@param slot number ----@return table -Inventory.GetItemBySlot = function(src, slot) - return ox_inventory:GetSlot(src, slot) -end - ----comment +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. ---@param src number ---@param item string ---@param metadata table @@ -69,15 +57,6 @@ Inventory.GetItemCount = function(src, item, metadata) return ox_inventory:GetItemCount(src, item, metadata, false) end ----comment ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - local count = ox_inventory:GetItemCount(src, item, nil, false) - return count > 0 -end - ---This wil return the players inventory. ---@param src number ---@return table @@ -85,13 +64,38 @@ Inventory.GetPlayerInventory = function(src) return ox_inventory:GetInventoryItems(src, false) end ----This is to get if there is available space in the inventory. +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table +Inventory.GetItemBySlot = function(src, slot) + return ox_inventory:GetSlot(src, slot) +end + +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ----@param count number ----@return boolean -Inventory.CanCarryItem = function(src, item, count) - return ox_inventory:CanCarryItem(src, item, count) +---@param slot number +---@param metadata table +---@return nil +Inventory.SetMetadata = function(src, item, slot, metadata) + ox_inventory:SetMetadata(src, slot, metadata) +end + +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id) end ---This will register a stash @@ -107,28 +111,21 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor return ox_inventory:RegisterStash(id, label, slots, weight, owner) end ----comment ----@param src number ----@param id number||string ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id) -end - ----This will set the metadata of an item in the inventory. +---This will return a boolean if the player has the item. ---@param src number ---@param item string ----@param slot number ----@param metadata table ----@return nil -Inventory.SetMetadata = function(src, item, slot, metadata) - ox_inventory:SetMetadata(src, slot, metadata) +---@return boolean +Inventory.HasItem = function(src, item) + return ox_inventory:GetItemCount(src, item, nil, false) > 0 +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return ox_inventory:CanCarryItem(src, item, count) end ---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) @@ -138,8 +135,7 @@ end Inventory.UpdatePlate = function(oldplate, newplate) ox_inventory:UpdateVehicle(oldplate, newplate) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) end ---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) @@ -152,16 +148,38 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end -local registeredShops = {} - +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string Inventory.OpenShop = function(src, shopTitle) TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle}) end +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) if registeredShops[shopTitle] then return true end registeredShops[shopTitle] = true ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, }) --return Inventory.OpenShop(src, shopTitle) return true +end + + + +---UNUSED: +---This will return generic item data from the specified inventory, with the items total count. +--- +---format without metadata { count, stack, name, weight, label } +--- +---fortmat with metadata { count, stack, name, weight, label, metadata } +---@param src number +---@param item string +---@param metadata table +---@return table +Inventory.GetItem = function(src, item, metadata) + return ox_inventory:GetItem(src, item, metadata, false) end \ No newline at end of file diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index 60ef824..879312e 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -1,27 +1,90 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('ps-inventory') ~= 'started' then return end - local sloth = exports['ps-inventory'] +local registeredShops = {} Inventory = Inventory or {} - ----comment ----@param id string||number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table +---This will add an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table ---@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return true +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return sloth:AddItem(src, item, count, slot, metadata, 'community_bridge') end ----comment +---This will remove an item, and return true or false based on success ---@param src number ----@param id string||number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return sloth:RemoveItem(src, item, count, slot, 'community_bridge') +end + +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table +Inventory.GetItemInfo = function(item) + local itemData = QBCore.Shared.Items[item] + if not itemData then return {} end + return { + 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 = Inventory.GetImagePath(item), + } +end + +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table +Inventory.GetItemBySlot = function(src, slot) + local slotData = sloth:GetItemBySlot(src, slot) + if not slotData then return {} end + return { + name = slotData.name, + label = slotData.label or slotData.name, + weight = slotData.weight, + slot = slot, + count = slotData.amount, + metadata = slotData.info, + stack = slotData.unique, + description = slotData.description + } +end + +---This will set the metadata of an item in the inventory. +---@param src number +---@param item string +---@param slot number +---@param metadata table +---@return nil +Inventory.SetMetadata = function(src, item, slot, metadata) + local itemData = Inventory.GetItemBySlot(src, slot) + if not itemData then return end + if itemData.count > 1 then return print("Items with more than 1 count cannot be set with metadata plase adjust item to unique in the qb shared item name : "..item) end + Inventory.RemoveItem(src, item, 1, slot) + return Inventory.AddItem(src, item, 1, slot, metadata) +end + +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string ---@param label string ---@param slots number ---@param weight number @@ -33,17 +96,20 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo TriggerClientEvent('community_bridge:client:ps-inventory:openStash', src, id, { label = label, maxweight = weight, slots = slots, }) 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" +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return true end ----comment +---This will return a boolean if the player has the item. ---@param src number ---@param item string ---@return boolean @@ -51,52 +117,16 @@ Inventory.HasItem = function(src, item) return sloth:HasItem(src, item, 1) end ----comment ----@param src number ----@param slot number ----@return table -Inventory.GetItemBySlot = function(src, slot) - local slotData = sloth:GetItemBySlot(src, slot) - if not slotData then return {} end - return { - name = slotData.name, - label = slotData.name, - weight = slotData.weight, - slot = slot, - count = slotData.amount, - metadata = slotData.info, - stack = slotData.unique, - description = slotData.description - } -end - ----comment +---This is to get if there is available space in the inventory, will return boolean. ---@param src number ---@param item string ----@param amount number ----@param slot number ----@param metadata table +---@param count number ---@return boolean -Inventory.AddItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) - return sloth:AddItem(src, item, amount, slot, metadata, 'community_bridge') +Inventory.CanCarryItem = function(src, item, count) + return true end ----comment ----@param src number ----@param item string ----@param amount number ----@param slot number ----@param metadata table ----@return boolean -Inventory.RemoveItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) - return sloth:RemoveItem(src, item, amount, slot, 'community_bridge') -end - ----comment +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -108,16 +138,31 @@ Inventory.UpdatePlate = function(oldplate, newplate) local values = { newplate = newplate, oldplate = oldplate } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) end -local registeredShops = {} +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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 +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string Inventory.OpenShop = function(src, shopTitle) return sloth:OpenShop(src, shopTitle) end +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) if not shopTitle or not shopInventory or not shopCoords then return end if registeredShops[shopTitle] then return true end @@ -130,6 +175,5 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG sloth:CreateShop(repackedShopItems) registeredShops[shopTitle] = true - --Inventory.OpenShop(src, shopTitle) return true end \ No newline at end of file diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index bfd7b74..adb6418 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -1,46 +1,46 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('qb-inventory') ~= 'started' then return end - local qbInventory = exports['qb-inventory'] Inventory = Inventory or {} +local registeredShops = {} +local v1ShopData = {} + local function getInventoryNewVersion() - if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then - return true - else - return false - end + if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then return true end + return false end ----comment ----@param id string ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return true -end - ----comment +---This will add an item, and return true or false based on success ---@param src number ----@param id number||string ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = weight, slots = slots }) +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return exports['qb-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge') end +---This will remove an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return exports['qb-inventory']:RemoveItem(src, item, count, slot, 'community_bridge') +end +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table Inventory.GetItemInfo = function(item) local itemData = Framework.Shared.Items[item] if not itemData then return {} end @@ -54,26 +54,9 @@ Inventory.GetItemInfo = function(item) } 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" -end - ----comment ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - return qbInventory:HasItem(src, item, 1) -end - ----comment +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ---@return table @@ -92,7 +75,61 @@ Inventory.GetItemBySlot = function(src, slot) } end ----comment +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = weight, slots = slots }) +end + +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return true +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return qbInventory:HasItem(src, item, 1) +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return true +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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 + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -119,25 +156,12 @@ Inventory.UpdatePlate = function(oldplate, newplate) MySQL.transaction.await(queries, values) end if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) end -Inventory.AddItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) - return exports['qb-inventory']:AddItem(src, item, amount, slot, metadata, 'community_bridge') -end - -Inventory.RemoveItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) - return exports['qb-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge') -end - -local registeredShops = {} -local v1ShopData = {} - +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string Inventory.OpenShop = function(src, shopTitle) local newVersion = getInventoryNewVersion() if newVersion then @@ -149,6 +173,11 @@ Inventory.OpenShop = function(src, shopTitle) end end +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) if not shopTitle or not shopInventory or not shopCoords then return end if registeredShops[shopTitle] then return true end diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index f7e06ed..a792c4f 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -5,7 +5,7 @@ local quasar = exports['qs-inventory'] Inventory = Inventory or {} ----This will add the item if found and return a boolean on success +---This will add an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -18,7 +18,7 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return quasar:AddItem(src, item, count, slot, metadata) end ----This will remove the item if found and return a boolean on success +---This will remove an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -30,101 +30,7 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) return quasar:RemoveItem(src, item, count, slot, metadata) end ----This will return a number of the items count in the inventory ----@param src number ----@param item string ----@param metadata table ----@return number -Inventory.GetItemCount = function(src, item, metadata) - return quasar:GetItemTotalAmount(src, item) -end - ----This will return the player inventory in a table following ox_inventory format ----@param src number ----@return table -Inventory.GetPlayerInventory = function(src) - local playerItems = quasar:GetInventory(src) - local repackedTable = {} - for _, v in pairs(playerItems) do - table.insert(repackedTable, { - name = v.name, - count = v.amount, - metadata = v.info, - slot = v.slot, - }) - end - return repackedTable -end - ----This will return a boolean of if the player has the item in the inventory ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - local count = quasar:GetItemTotalAmount(src, item) - if not count then return false end - return count > 0 -end - ----This will return the item data in the inventory based on the slot if not found will return nil ----@param src number ----@param slot number ----@return table | nil -Inventory.GetItemBySlot = function(src, slot) - local playerItems = quasar:GetInventory(src) - for _, item in pairs(playerItems) do - if item.slot == slot then - return { - name = item.name, - label = item.label, - weight = item.weight, - slot = slot, - count = item.amount, - metadata = item.info, - stack = item.unique or false, - description = item.description - } - end - end - return nil -end - ----This will return a boolean if the player can carry the item ----@param src number ----@param item string ----@param count number ----@return boolean -Inventory.CanCarryItem = function(src, item, count) - return quasar:CanCarryItem(src, item, count) -end - ----@param id string ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return true -end - ----@param src number ----@param id string ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table ----@return nil -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerEvent("inventory:server:OpenInventory", "stash", id, { maxweight = weight, slots = slots }) - TriggerClientEvent("inventory:client:SetCurrentStash",src, id) -end - ----This will return the data to an item +---This will return a table with the item info, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -142,25 +48,118 @@ Inventory.GetItemInfo = function(item) } end +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. +---@param src number +---@param item string +---@param metadata table +---@return number +Inventory.GetItemCount = function(src, item, metadata) + return quasar:GetItemTotalAmount(src, item) +end +---This wil return the players inventory. +---@param src number +---@return table +Inventory.GetPlayerInventory = function(src) + local playerItems = quasar:GetInventory(src) + local repackedTable = {} + for _, v in pairs(playerItems) do + table.insert(repackedTable, { + name = v.name, + count = v.amount, + metadata = v.info, + slot = v.slot, + }) + end + return repackedTable +end + +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} +---@param src number +---@param slot number +---@return table +Inventory.GetItemBySlot = function(src, slot) + local playerItems = quasar:GetInventory(src) + for _, item in pairs(playerItems) do + if item.slot == slot then + return { + name = item.name, + label = item.label, + weight = item.weight, + slot = slot, + count = item.amount, + metadata = item.info, + stack = item.unique or false, + description = item.description + } + end + end + return {} +end + +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ---@param slot number ---@param metadata table ----@return boolean +---@return nil Inventory.SetMetadata = function(src, item, slot, metadata) return quasar:SetItemMetadata(src, slot, metadata) 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" +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + TriggerEvent("inventory:server:OpenInventory", "stash", id, { maxweight = weight, slots = slots }) + TriggerClientEvent("inventory:client:SetCurrentStash",src, id) end +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + --exports['qs-inventory']:RegisterStash(src, id, stashSlots, stashWeight) -- this needs to pass source to register, need to plan around this. + return true +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + local count = quasar:GetItemTotalAmount(src, item) + if not count then return false end + return count > 0 +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return quasar:CanCarryItem(src, item, count) +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -172,6 +171,31 @@ Inventory.UpdatePlate = function(oldplate, newplate) local values = { newplate = newplate, oldplate = oldplate } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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" +end + +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + print("Currently qs shop is not bridged") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return false, print("Currently qs shop is not bridged") end \ No newline at end of file diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index 553d998..995d989 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -5,7 +5,7 @@ local tgiann = exports["tgiann-inventory"] Inventory = Inventory or {} ----This Will add the item if found and return boolean on success +---This will add an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -13,12 +13,11 @@ Inventory = Inventory or {} ---@param metadata table ---@return boolean Inventory.AddItem = function(src, item, count, slot, metadata) - if not tgiann:CanCarryItem(src, item, count) then return false end TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) return tgiann:AddItem(src, item, count, slot, metadata, false) end ----This Will remove the item if found and return boolean on success +---This will remove an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -30,37 +29,35 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) return tgiann:RemoveItem(src, item, count, slot, metadata) end --- +---This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table +Inventory.GetItemInfo = function(item) + local itemData = tgiann:GetItemList() + if not itemData[item] then return {} end + return { + 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), + } +end + +---This will return the count of the item in the players inventory, if not found will return 0. +--- +---if metadata is passed it will find the matching items count. ---@param src number ---@param item string ---@param metadata table ----@return table -Inventory.GetItem = function(src, item, metadata) - local item = tgiann:GetItemByName(src, item, metadata) - item.count = item.amount - item.metadata = item.info - return item -end - ----This will return a boolean if the player has the item in their inventory ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - return tgiann:HasItem(src, item, 1) -end - ----This will return the count of the item in the players inventory ----@param src number ----@param item string ----@param metadata optional table ---@return number Inventory.GetItemCount = function(src, item, metadata) local _item = tgiann:GetItemByName(src, item, metadata) return _item.amount or 0 end ----This will return the players inventory in a table in the format ox_inventory uses +---This wil return the players inventory. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) @@ -74,27 +71,9 @@ Inventory.GetPlayerInventory = function(src) return items end ----This will return a boolean if the player can carry the item ----@param src number ----@param item string ----@param count number ----@return boolean -Inventory.CanCarryItem = function(src, item, count) - return tgiann:CanCarryItem(src, item, count) -end - ----comment ----@param id string or number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner) - return tgiann:CreateCustomStashWithItem(id, {}) -end - ----This will return the item data in the slot the item is found +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ---@return table @@ -113,24 +92,7 @@ Inventory.GetItemBySlot = function(src, slot) } end ----This will return a table of the item data including the image (very useful for menus etc) ----@param item string ----@return table -Inventory.GetItemInfo = function(item) - local itemData = tgiann:GetItemList() - if not itemData[item] then return {} end - return { - 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), - } -end - ----This will update the item metadata for an item with the provided slot and metadata, its best to get the item first ----And then set the metadata +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ---@param slot number @@ -140,18 +102,51 @@ Inventory.SetMetadata = function(src, item, slot, metadata) tgiann:UpdateItemMetadata(src, item, slot, metadata) end ----This will return the image path for the item ----@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) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" +---This will open the specified stash for the src passed. +---@param src number +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return nil +Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) + print("Currently not bridged for stashes") end ----This will update the plate to a vehicle in the inventory +---This will register a stash +---@param id number||string +---@param label string +---@param slots number +---@param weight number +---@param owner string +---@param groups table +---@param coords table +---@return boolean +Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) + return false, print("Currently not bridged for stashes") +end + +---This will return a boolean if the player has the item. +---@param src number +---@param item string +---@return boolean +Inventory.HasItem = function(src, item) + return tgiann:HasItem(src, item, 1) +end + +---This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return tgiann:CanCarryItem(src, item, count) +end + +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -163,6 +158,50 @@ Inventory.UpdatePlate = function(oldplate, newplate) local values = { newplate = newplate, oldplate = oldplate } MySQL.transaction.await(queries, values) if GetResourceState('jg-mechanic') ~= 'started' then return true end - exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) - return true + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) +end + +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@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) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + + +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + print("Currently tgiann-inventory is not bridged for shops") +end + +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table +Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + return false, print("Currently tgiann-inventory is not bridged for shops") +end + +---UNUSED: +---This will return generic item data from the specified inventory, with the items total count. +--- +---format without metadata { count, stack, name, weight, label } +--- +---fortmat with metadata { count, stack, name, weight, label, metadata } +---@param src number +---@param item string +---@param metadata table +---@return table +Inventory.GetItem = function(src, item, metadata) + local item = tgiann:GetItemByName(src, item, metadata) + item.count = item.amount + item.metadata = item.info + return item end \ No newline at end of file