Remove example scripts and update core logic
Deleted all files in the examples directory to clean up unused or test scripts. Updated fxmanifest.lua to enable ox_lib initialization. Improved error handling and entity tracking in utility functions, added prop removal, and made minor localization and code style adjustments throughout the codebase. Significant reword of inventory module, notification module, and framework module. Added support for wasabi_uikit, added support for keep-progressbars,
This commit is contained in:
1 parent
c40a260ea2
commit
343af95794
100 files changed
+2403
-2755
No files matched your search
@@ -1,40 +1,41 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "default"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
return Framework.GetItemInfo(item)
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "default"
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return Framework.HasItem(item)
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
return Framework.HasItem(item, requiredCount)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@description This will return their count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return Framework.GetItemCount(item)
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
return Framework:GetPlayerInventory()
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -42,8 +43,7 @@ Inventory.GetImagePath = function(item)
|
||||
return "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will remove the file extension from the item name if present.
|
||||
---example: "item.png" will become "item"
|
||||
---@description This will remove the file extension from the item name if present.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.StripPNG = function(item)
|
||||
@@ -53,8 +53,7 @@ Inventory.StripPNG = function(item)
|
||||
return item
|
||||
end
|
||||
|
||||
---This will remove the file extension from the item name if present.
|
||||
---example: "item.webp" will become "item"
|
||||
---@description This will remove the file extension from the item name if present.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.StripWebp = function(item)
|
||||
@@ -64,8 +63,8 @@ Inventory.StripWebp = function(item)
|
||||
return item
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
if not Framework.Shared or not Framework.Shared.Items then
|
||||
local itemList = Framework.ItemList() or { Items = {} }
|
||||
@@ -74,6 +73,4 @@ Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
|
||||
|
||||
return Inventory
|
||||
@@ -1,7 +1,14 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---This will add an item, and return true or false based on success
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "default"
|
||||
end
|
||||
|
||||
---@description This will add an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -9,18 +16,13 @@ Inventory = Inventory or {}
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
local success = Framework.AddItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
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)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "default"
|
||||
end
|
||||
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -29,36 +31,36 @@ end
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
item = type(item) == "table" and item.name or item
|
||||
local success = Framework.RemoveItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
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)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@description This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A Trunk Feature.")
|
||||
return false, print("This Inventory Has Not Been Bridged For A Trunk Feature.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will return success or failure.
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A ClearStash Feature.")
|
||||
return false, print("This Inventory Has Not Been Bridged For A ClearStash Feature.")
|
||||
end
|
||||
|
||||
---This will return a table with the item info,
|
||||
---example: {name = "coolitem", label = "a cool item name", stack = false, weight = 1000, description = "some item description", image = "coolitem.png"}
|
||||
---@description 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 return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
if not Framework.Shared or not Framework.Shared.Items then
|
||||
@@ -68,35 +70,31 @@ Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
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.
|
||||
---example: 0
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@param metadata table (optional)
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return Framework.GetItemCount(src, item, metadata)
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---example: {{weight = 10, name = "farts", metadata = {description = "this is a description"}, slot = 1, label = "stinky", count = 1}, {weight = 10, name = "farts", metadata = {description = "this is a description"}, slot = 2, label = "stinky", count = 1}}
|
||||
---@description This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
return Framework.GetPlayerInventory(src)
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---example {weight = 10, name = "farts", metadata = {description = "this is a description"}, slot = 1, label = "stinky", count = 1}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
return Framework.GetItemBySlot(src, slot)
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -106,74 +104,65 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return Framework.SetMetadata(src, item, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number|string
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.")
|
||||
return false, print("This Inventory Has Not Been Bridged For A Stash Feature.")
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
---@description 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
|
||||
---@param owner string (optional)
|
||||
---@param groups table (optional)
|
||||
---@param coords table (optional)
|
||||
---@return boolean
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
Inventory.Stashes[id] = {id = id, label = label, slots = slots, weight = weight, owner = owner, groups = groups, coords = coords}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return Framework.HasItem(src, item)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return Framework.HasItem(src, item, requiredCount)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@description 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.")
|
||||
return true, print("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)
|
||||
---@description 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.")
|
||||
return false, print("This Inventory Has Not Been Bridged For A UpdatePlate Feature.")
|
||||
end
|
||||
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@description This will open the specified shop for the src passed.
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
Inventory.OpenShop = function(src, shopTitle)
|
||||
return Bridge.Shops.OpenShop(src, shopTitle)
|
||||
end
|
||||
|
||||
-- This will register a shop, if it already exists it will return true.
|
||||
---@description This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
@@ -182,14 +171,14 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
|
||||
return Bridge.Shops.CreateShop(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||
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)
|
||||
---@description 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)
|
||||
return "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will remove the file extension from the item name if present.
|
||||
---@description This will remove the file extension from the item name if present.
|
||||
---example: "item.png" will become "item"
|
||||
---@param item string
|
||||
---@return string
|
||||
@@ -200,7 +189,7 @@ Inventory.StripPNG = function(item)
|
||||
return item
|
||||
end
|
||||
|
||||
---This will remove the file extension from the item name if present.
|
||||
---@description This will remove the file extension from the item name if present.
|
||||
---example: "item.webp" will become "item"
|
||||
---@param item string
|
||||
---@return string
|
||||
@@ -211,8 +200,12 @@ Inventory.StripWebp = function(item)
|
||||
return item
|
||||
end
|
||||
|
||||
---@description Opens another player's inventory for inspection/interaction
|
||||
---@param src number The source player who is opening the inventory
|
||||
---@param targetSrc number The target player whose inventory is being opened
|
||||
---@return boolean
|
||||
Inventory.OpenPlayerInventory = function(src, targetSrc)
|
||||
return false, Prints.Error("OpenPlayerInventory is not implemented in this inventory, because of this we dont have a way to open a players inventory.")
|
||||
return false, print("OpenPlayerInventory is not implemented in this inventory, because of this we dont have a way to open a players inventory.")
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,22 +1,16 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('codem-inventory') ~= 'started' then return end
|
||||
if GetResourceState('codem-inventory') == 'missing' then return end
|
||||
Inventory = Inventory or {}
|
||||
|
||||
local codem = exports['codem-inventory']
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "codem-inventory"
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList() or {}
|
||||
end
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -33,28 +27,34 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList() or {}
|
||||
end
|
||||
|
||||
---@description 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))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
||||
local file = LoadResourceFile("codem-inventory", string.format("html/itemimages/%s.png", item))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/itemimages/%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}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
local inventory = codem:getUserInventory()
|
||||
local inventory = codem:GetClientPlayerInventory()
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
count = v.amount or v.count,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
metadata = v.info or v.metadata or {},
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
@@ -63,9 +63,4 @@ 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)
|
||||
|
||||
return Inventory
|
||||
@@ -1,29 +1,45 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('codem-inventory') ~= 'started' then return end
|
||||
if GetResourceState('codem-inventory') == 'missing' then return end
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes 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 get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "codem-inventory"
|
||||
end
|
||||
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
local success = codem:AddItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success
|
||||
end
|
||||
|
||||
---@description Internal function to search for items with specific metadata in player inventory
|
||||
---@param src number
|
||||
---@param metadata table
|
||||
---@return boolean, number|nil
|
||||
local function runMetadataSearch(src, metadata)
|
||||
local inv = Framework.GetPlayerInventory(src) or {}
|
||||
for _, v in pairs(inv) do
|
||||
if v.metadata and v.metadata == metadata then
|
||||
return true, v.slot
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
@@ -32,17 +48,17 @@ end
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
if metadata then
|
||||
local found, foundSlot = runMetadataSearch(src, metadata)
|
||||
if found then slot = foundSlot end
|
||||
end
|
||||
local success = codem:RemoveItem(src, item, count, slot)
|
||||
if not success then return false 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)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList() or {}
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -58,7 +74,22 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList() or {}
|
||||
end
|
||||
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table (optional)
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return codem:GetItemsTotalAmount(src, item) or 0
|
||||
end
|
||||
|
||||
---@description This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
@@ -68,19 +99,18 @@ Inventory.GetPlayerInventory = function(src)
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
count = v.amount or v.count,
|
||||
metadata = v.info or v.metadata or {},
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = codem:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
@@ -90,13 +120,13 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
weight = slotData.weight,
|
||||
slot = slotData.slot,
|
||||
count = slotData.amount or slotData.count,
|
||||
metadata = slotData.info or slotData.metadata,
|
||||
stack = slotData.unique,
|
||||
metadata = slotData.info or slotData.metadata or {},
|
||||
stack = slotData.unique or false,
|
||||
description = slotData.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -106,103 +136,57 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return codem:SetItemMetadata(src, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number||string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
TriggerClientEvent('community_bridge:client:codem-inventory:openStash', src, id, { label = tbl.label, slots = tbl.slots, weight = tbl.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
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return codem:HasItem(src, item, 1)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return codem:HasItem(src, item, requiredCount or 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 add items to a trunk, and return true or false based on success
|
||||
---If a trunk with the identifier does not exist, it will create one with default values.
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
return false, print("AddItemsToTrunk is not implemented in codem-inventory, because of this we dont have a way to add items to a trunk.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@param _type string unused with ox_inventory
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false, print("ClearInventory is not implemented in codem-inventory, because of this we dont have a way to clear a stash.")
|
||||
codem:UpdateStash(id, {})
|
||||
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
|
||||
---@description This will add items to a stash, and return true or false based on success
|
||||
---@param id string
|
||||
---@param items table {item, count, metadata}
|
||||
---@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.")
|
||||
Inventory.AddStashItems = function(id, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
local repack = {}
|
||||
for _, v in pairs(items) do
|
||||
table.insert(repack, {
|
||||
item = v.item,
|
||||
amount = v.count or v.amount,
|
||||
info = v.metadata or v.info or {},
|
||||
unique = v.unique or v.stack or false,
|
||||
description = v.description or "none",
|
||||
weight = Inventory.GetItemInfo(v.item).weight or 0,
|
||||
type = 'item',
|
||||
slot = #repack + 1,
|
||||
})
|
||||
end
|
||||
codem:UpdateStash(id, repack)
|
||||
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)
|
||||
---@description 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))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
||||
local file = LoadResourceFile("codem-inventory", string.format("html/itemimages/%s.png", item))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/itemimages/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
exports['codem-inventory']:OpenInventory(src, target)
|
||||
end
|
||||
|
||||
|
||||
return Inventory
|
||||
@@ -1,35 +1,26 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('core_inventory') ~= 'started' then return end
|
||||
if GetResourceState('core_inventory') == 'missing' then return end
|
||||
local core = exports.core_inventory
|
||||
-- Core inventory docs available at https://docs.c8re.store/core-inventory/api/server#getitemslist
|
||||
Callback = Callback or Require("lib/callback/shared/callback.lua")
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local frameworkName = Framework.GetFrameworkName()
|
||||
if not frameworkName then return {} end
|
||||
local dataRepack = {}
|
||||
if frameworkName == 'es_extended' then
|
||||
local callbackData = Callback.Trigger('community_bridge:Callback:core_inventory', false)
|
||||
-- really really wish this inventory allowed me to pull the item list client side....
|
||||
dataRepack = callbackData[item]
|
||||
if not dataRepack then return {} end
|
||||
elseif frameworkName == 'qb-core' then
|
||||
dataRepack = Framework.Shared.Items[item]
|
||||
if not dataRepack then return {} end
|
||||
end
|
||||
return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) }
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "core_inventory"
|
||||
end
|
||||
|
||||
local cachedItemList = nil
|
||||
--- Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
--- https://docs.c8re.store/core-inventory/api/server#getitemslist
|
||||
--- @param item string
|
||||
--- @return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemList = Inventory.Items()
|
||||
return itemList[item] or {}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
@@ -38,13 +29,16 @@ Inventory.Items = function()
|
||||
if not frameworkName then return {} end
|
||||
local dataRepack = {}
|
||||
if frameworkName == 'es_extended' then
|
||||
local callbackData = Callback.Trigger('community_bridge:Callback:core_inventory', false)
|
||||
-- really really wish this inventory allowed me to pull the item list client side....
|
||||
dataRepack = callbackData
|
||||
if not dataRepack then return {} end
|
||||
if not cachedItemList then cachedItemList = Callback.Trigger('community_bridge:Callback:core_inventory', false) end
|
||||
dataRepack = cachedItemList or {}
|
||||
elseif frameworkName == 'qb-core' then
|
||||
dataRepack = Framework.Shared.Items
|
||||
if not dataRepack then return {} end
|
||||
dataRepack = Framework.Shared.Items or {}
|
||||
end
|
||||
for itemName, itemData in pairs(dataRepack) do
|
||||
if itemData and itemData.name then
|
||||
dataRepack[itemName].image = Inventory.GetImagePath(itemData.name)
|
||||
dataRepack[itemName].stack = dataRepack[itemName].unique or false
|
||||
end
|
||||
end
|
||||
return dataRepack
|
||||
end
|
||||
@@ -56,11 +50,12 @@ 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.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return core:getItemCount(item)
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
return core:getItemCount(item) >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
@@ -81,9 +76,9 @@ Inventory.GetPlayerInventory = function()
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.id,
|
||||
count = v.count or v.amount,
|
||||
metadata = v.metadata or v.info,
|
||||
slot = v.id or v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('core_inventory') ~= 'started' then return end
|
||||
if GetResourceState('core_inventory') == 'missing' then return end
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
Callback = Callback or Require("lib/callback/shared/callback.lua")
|
||||
local core = exports.core_inventory
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "core_inventory"
|
||||
end
|
||||
|
||||
---This will add an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
@@ -14,18 +20,14 @@ local core = exports.core_inventory
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
-- docs specify a table returned on success, on failure it returns false.
|
||||
-- https://docs.c8re.store/core-inventory/api/server#additem
|
||||
local success = core:addItem(src, item, count, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return core:addItem(src, item, count, metadata)
|
||||
return success or false
|
||||
end
|
||||
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "core_inventory"
|
||||
end
|
||||
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
@@ -39,7 +41,7 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
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
|
||||
slot = v.id or v.slot
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -53,11 +55,12 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
identifier = string.gsub(identifier, ":", "")
|
||||
end
|
||||
local weirdInventoryName = 'content-' .. identifier
|
||||
-- No return value specified in docs, so we assume none.
|
||||
-- https://docs.c8re.store/core-inventory/api/server#removeitemexact
|
||||
return core:removeItemExact(weirdInventoryName, slot, count)
|
||||
end
|
||||
core:removeItem(src, item, count)
|
||||
return true
|
||||
-- I hate this inventory so much, I am so sorry for this.
|
||||
end
|
||||
|
||||
---This will return the count of the item in the players inventory, if not found will return 0.
|
||||
@@ -93,24 +96,24 @@ Inventory.GetPlayerInventory = function(src)
|
||||
local playerItems = core:getInventory(src)
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.metadata and v.count > 1 then
|
||||
if (v.metadata or v.info) and (v.count or v.amount) > 1 then
|
||||
local plaseFixThisExportCuzThisIsPainful = core:getItems(src, v.name)
|
||||
if plaseFixThisExportCuzThisIsPainful then
|
||||
for _, item in pairs(plaseFixThisExportCuzThisIsPainful) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = item.count,
|
||||
metadata = item.metadata,
|
||||
slot = item.id,
|
||||
count = item.count or item.amount,
|
||||
metadata = item.metadata or item.info,
|
||||
slot = item.id or item.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
else
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.id,
|
||||
count = v.count or v.amount,
|
||||
metadata = v.metadata or v.info,
|
||||
slot = v.id or v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -126,12 +129,12 @@ 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
|
||||
if (v.slot == slot) or (v.id == slot) then
|
||||
return {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.slot,
|
||||
slot = v.id or v.slot,
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -156,7 +159,7 @@ end
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
core:openInventory(src, id, _type, tbl.slots, tbl.weight, true, nil, false)
|
||||
core:openInventory(src, id, _type, tbl.slots or 30, tbl.weight or 50000, true, nil, false)
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
@@ -185,12 +188,14 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return core:getItemCount(src, item) > 0
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
local count = Inventory.GetItemCount(src, item, nil)
|
||||
return count >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
@@ -212,15 +217,6 @@ Inventory.AddTrunkItems = function(identifier, items)
|
||||
return false, print("AddItemsToTrunk is not implemented in core_inventory, because of this we dont have a way to add items to a trunk.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false, print("ClearInventory is not implemented in core_inventory, because of this we dont have a way to clear a stash.")
|
||||
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
|
||||
@@ -267,9 +263,7 @@ end
|
||||
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
local identifier = Framework.GetPlayerIdentifier(target)
|
||||
if not identifier then return false end
|
||||
exports.core_inventory:openInventory(src, 'stash-'.. identifier:gsub(':',''), 'stash', nil, nil, true, nil, false)
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('jpr-inventory') ~= 'started' then return end
|
||||
if GetResourceState('jpr-inventory') == 'missing' then return end
|
||||
local jpr = exports['jpr-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "jpr-inventory"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -20,28 +26,7 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "jpr-inventory"
|
||||
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 return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('jpr-inventory') ~= 'started' then return end
|
||||
if GetResourceState('jpr-inventory') == 'missing' then return end
|
||||
|
||||
local jpr = exports['jpr-inventory']
|
||||
local registeredShops = {}
|
||||
@@ -7,37 +7,43 @@ local registeredShops = {}
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---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 exports['jpr-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge Item added')
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "jpr-inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@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')
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
local canCarry = Inventory.CanCarryItem(src, item, count)
|
||||
if not canCarry then return false end
|
||||
local success = exports['jpr-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge Item added')
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = exports['jpr-inventory']:RemoveItem(src, item, count, slot, 'community_bridge Item removed')
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -46,17 +52,10 @@ Inventory.GetItemInfo = function(item)
|
||||
return itemTable
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = jpr:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
@@ -72,78 +71,27 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
}
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number||string
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
local tbl = Inventory.Stashes[id] or {weight = 1000000, slots = 50}
|
||||
TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = tbl.weight, slots = tbl.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
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---If a trunk with the identifier does not exist, it will create one with default values.
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
return false, print("AddItemsToTrunk is not implemented in jpr-inventory, because of this we dont have a way to add items to a trunk.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false, print("ClearInventory is not implemented in jpr-inventory, because of this we dont have a way to clear a stash.")
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return jpr:HasItem(src, item, 1)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return jpr:HasItem(src, item, requiredCount or 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)
|
||||
---@description 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
|
||||
@@ -158,7 +106,7 @@ Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
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)
|
||||
---@description 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)
|
||||
@@ -168,26 +116,26 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will open the specified shop for the src passed.
|
||||
---@description This will open the specified shop for the src passed.
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
Inventory.OpenShop = function(src, shopTitle)
|
||||
jpr:OpenShop(src, shopTitle)
|
||||
end
|
||||
|
||||
---This will register a shop, if it already exists it will return true.
|
||||
---@description This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param inventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||
if not shopTitle or not shopInventory or not shopCoords then return end
|
||||
Inventory.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups)
|
||||
if not shopTitle or not inventory or not shopCoords then return end
|
||||
if registeredShops[shopTitle] then return true end
|
||||
|
||||
local repackItems = {}
|
||||
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
|
||||
for k, v in pairs(shopInventory) do
|
||||
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
|
||||
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #inventory, }
|
||||
for k, v in pairs(inventory) do
|
||||
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or v.amount or 1, slot = k })
|
||||
end
|
||||
|
||||
jpr:CreateShop(repackedShopItems)
|
||||
@@ -195,11 +143,12 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@param src number
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
local identifier = Framework.GetPlayerIdentifier(target)
|
||||
if not identifier then return false end
|
||||
exports['jpr-inventory']:OpenInventory(src, identifier)
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('origen_inventory') ~= 'started' then return end
|
||||
if GetResourceState('origen_inventory') == 'missing' then return end
|
||||
if GetResourceState('ox_inventory') ~= 'missing' then return end
|
||||
Inventory = Inventory or {}
|
||||
local origin = exports.origen_inventory
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "origen_inventory"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = origin:Items(item)
|
||||
local itemData = Inventory.Items()[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
@@ -19,26 +26,16 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "origen_inventory"
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return origin:Items()
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return origin:HasItem(item)
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
local count = Inventory.GetItemCount(item)
|
||||
return count >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@description This will return their count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
@@ -47,7 +44,7 @@ Inventory.GetItemCount = function(item)
|
||||
return inventory.count
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -57,7 +54,7 @@ Inventory.GetImagePath = function(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}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local repack = {}
|
||||
@@ -67,10 +64,10 @@ Inventory.GetPlayerInventory = function()
|
||||
table.insert(repack, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
count = v.amount or v.count,
|
||||
slot = v.slot,
|
||||
metadata = v.metadata,
|
||||
stack = v.unique,
|
||||
metadata = v.metadata or v.info or {},
|
||||
stack = v.unique or v.stack or false,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
@@ -78,8 +75,4 @@ Inventory.GetPlayerInventory = function()
|
||||
return repack
|
||||
end
|
||||
|
||||
Inventory.OpenStash = function(id)
|
||||
origin:openInventory('stash', id, { label = id, weight = 400000, slots = 100, })
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,42 +1,49 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('origen_inventory') ~= 'started' then return end
|
||||
if GetResourceState('origen_inventory') == 'missing' then return end
|
||||
if GetResourceState('ox_inventory') ~= 'missing' then return end
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
local origin = exports.origen_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 origin:AddItem(src, item, count, metadata, slot, true)
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "origen_inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@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)
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
local canCarry = Inventory.CanCarryItem(src, item, count)
|
||||
if not canCarry then return false end
|
||||
local success = origin:addItem(src, item, count, metadata, slot, false)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = origin:removeItem(src, item, count, metadata, slot, false)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---@description This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
@@ -48,8 +55,8 @@ Inventory.AddTrunkItems = function(identifier, items)
|
||||
for _, v in pairs(items) do
|
||||
table.insert(repack_items, {
|
||||
name = v.item,
|
||||
amount = v.count,
|
||||
metadata = v.metadata or {}
|
||||
amount = v.count or v.amount,
|
||||
metadata = v.metadata or v.info or {}
|
||||
})
|
||||
end
|
||||
if #repack_items == 0 then return false end
|
||||
@@ -57,13 +64,14 @@ Inventory.AddTrunkItems = function(identifier, items)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param identifier string
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@param _type string unused with ox_inventory
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(identifier, _type)
|
||||
if type(identifier) ~= "string" then return false end
|
||||
if Inventory.Stashes[identifier] then Inventory.Stashes[identifier] = nil end
|
||||
local id = identifier
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
local id = id
|
||||
if _type == "trunk" then
|
||||
id = "trunk_"..id
|
||||
elseif _type == "glovebox" then
|
||||
@@ -71,7 +79,7 @@ Inventory.ClearStash = function(identifier, _type)
|
||||
elseif _type == "stash" then
|
||||
id = "stash_"..id
|
||||
end
|
||||
local inv = origin:getInventory(identifier, _type)
|
||||
local inv = origin:getInventory(id, _type)
|
||||
if not inv then return false end
|
||||
local indexed = inv.inventory
|
||||
for _, v in pairs(indexed) do
|
||||
@@ -82,7 +90,7 @@ Inventory.ClearStash = function(identifier, _type)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -98,23 +106,22 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return origin:Items()
|
||||
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.
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@param metadata table (optional)
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return origin:getItemCount(src, item, metadata, false) or 0
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@description This will return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
@@ -125,8 +132,8 @@ Inventory.GetPlayerInventory = function(src)
|
||||
if v.slot then
|
||||
table.insert(repack, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.metadata or {},
|
||||
count = v.amount or v.count,
|
||||
metadata = v.metadata or v.info or {},
|
||||
slot = v.slot,
|
||||
label = v.label or "Unknown"
|
||||
})
|
||||
@@ -135,20 +142,19 @@ Inventory.GetPlayerInventory = function(src)
|
||||
return repack
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local playerInv = Inventory.GetPlayerInventory(src)
|
||||
for _, v in pairs(playerInv) do
|
||||
if v.slot == slot then
|
||||
return {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
count = v.count or v.amount,
|
||||
weight = v.weight or 0,
|
||||
metadata = v.metadata,
|
||||
metadata = v.metadata or v.info or {},
|
||||
slot = v.slot,
|
||||
label = v.label
|
||||
}
|
||||
@@ -157,7 +163,7 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
return {}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -167,51 +173,43 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
origin:setMetadata(src, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number|string
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
return origin:OpenInventory(src, _type, id)
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
---@description 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
|
||||
---@param owner string (optional)
|
||||
---@param groups table (optional)
|
||||
---@param coords table (optional)
|
||||
---@return boolean
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
Inventory.Stashes[id] = {id = id, label = label or id, slots = slots, weight = weight, owner = owner, groups = groups, coords = coords}
|
||||
origin:registerStash(id, label, slots, weight, owner, groups, coords)
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return origin:getItemCount(src , item) > 0
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return origin:getItemCount(src , item) > (requiredCount or 0)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@description This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -220,7 +218,7 @@ 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)
|
||||
---@description 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
|
||||
@@ -235,7 +233,7 @@ Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
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)
|
||||
---@description 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)
|
||||
@@ -245,11 +243,12 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@param src number
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
exports.origen_inventory:OpenInventory(src, "otherplayer", target)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ox_inventory') ~= 'started' then return end
|
||||
if GetResourceState('qs-inventory') == 'started' then return end
|
||||
if GetResourceState('origen_inventory') == 'started' then return end
|
||||
if GetResourceState('ox_inventory') == 'missing' then return end
|
||||
if GetResourceState('tgiann-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('qs-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('origen_inventory') ~= 'missing' then return end
|
||||
--check for providers =/
|
||||
|
||||
local ox_inventory = exports.ox_inventory
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "ox_inventory"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -23,33 +31,28 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "ox_inventory"
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return ox_inventory:Items()
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return ox_inventory:Search('count', item) > 0
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
return ox_inventory:Search('count', item, nil) >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@description This will return their count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return ox_inventory:GetItemCount(item, nil, false)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -59,7 +62,7 @@ Inventory.GetImagePath = function(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}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
return ox_inventory:GetPlayerItems()
|
||||
|
||||
@@ -1,71 +1,50 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ox_inventory') ~= 'started' then return end
|
||||
if GetResourceState('qs-inventory') == 'started' then return end
|
||||
if GetResourceState('origen_inventory') == 'started' then return end
|
||||
if GetResourceState('ox_inventory') == 'missing' then return end
|
||||
if GetResourceState('tgiann-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('qs-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('origen_inventory') ~= 'missing' then return end
|
||||
--check for providers =/
|
||||
|
||||
local ox_inventory = exports.ox_inventory
|
||||
local registeredShops = {}
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---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)
|
||||
if not ox_inventory:CanCarryItem(src, item, count, metadata) then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return ox_inventory:AddItem(src, item, count, metadata)
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "ox_inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
if not ox_inventory:CanCarryItem(src, item, count, metadata) then return false end
|
||||
local success = ox_inventory:AddItem(src, item, count, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success
|
||||
end
|
||||
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = ox_inventory:RemoveItem(src, item, count, metadata, slot)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return ox_inventory:RemoveItem(src, item, count, metadata, slot)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
local id = "trunk"..identifier
|
||||
if type(items) ~= "table" then return false end
|
||||
Inventory.RegisterStash(id, identifier, 20, 10000, nil, nil, nil)
|
||||
Wait(100) -- Wait for the stash to be registered just in case
|
||||
for _, v in pairs(items) do
|
||||
ox_inventory:AddItem(id, v.item, v.count, v.metadata)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
ox_inventory:ClearInventory(_type..id, nil)
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -81,41 +60,37 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return ox_inventory:Items()
|
||||
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.
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@param metadata table (optional)
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return ox_inventory:GetItemCount(src, item, metadata, false)
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@description This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
return ox_inventory:GetInventoryItems(src, false)
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
return ox_inventory:GetSlot(src, slot)
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -125,52 +100,70 @@ 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 _type string
|
||||
---@param id number||string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
--local tbl = Inventory.Stashes[id]
|
||||
ox_inventory:forceOpenInventory(src, _type, id)
|
||||
end
|
||||
|
||||
-- restores stashes to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources))
|
||||
---This will register a stash
|
||||
---@description 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
|
||||
---@param owner string (optional)
|
||||
---@param groups table (optional)
|
||||
---@param coords table (optional)
|
||||
---@return boolean
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
id = tostring(id)
|
||||
-- ox standard doesnt return anything so probably shouldnt return so everything else has the same standard. Id is pointless if its a param already. Yeaaaa probably should change this.
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
Inventory.Stashes[id] = {id = id, label = label, slots = slots, weight = weight, owner = owner, groups = groups, coords = coords}
|
||||
ox_inventory:RegisterStash(id, label, slots, weight, owner, groups, coords)
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return ox_inventory:GetItemCount(src, item, nil, false) > 0
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
ox_inventory:forceOpenInventory(src, _type, id)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@description This will add items to a stash, and return true or false based on success
|
||||
---@param id string
|
||||
---@param items table {item, count, metadata}
|
||||
---@return boolean
|
||||
Inventory.AddStashItems = function(id, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
local success = false
|
||||
for _, v in pairs(items) do
|
||||
success = ox_inventory:AddItem(id, v.item, v.count or v.amount, v.metadata or v.info or {})
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@param _type string unused with ox_inventory
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
id = tostring(id)
|
||||
ox_inventory:ClearInventory(id)
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
-- ox standard doesnt return anything so probably shouldnt return so everything else has the same standard. Yeaaaa probably should change this.
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return ox_inventory:GetItemCount(src, item, nil, false) >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---@description This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -179,17 +172,34 @@ 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)
|
||||
---@description 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)
|
||||
ox_inventory:UpdateVehicle(oldplate, newplate)
|
||||
if GetResourceState('jg-mechanic') ~= 'started' then return true end
|
||||
-- ox standard doesnt return anything so probably shouldnt return so everything else has the same standard. Yeaaaa probably should change this.
|
||||
if GetResourceState('jg-mechanic') ~= 'missing' then return true end
|
||||
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)
|
||||
---@description This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
local id = "trunk"..identifier
|
||||
if type(items) ~= "table" then return false end
|
||||
Inventory.RegisterStash(id, identifier, 20, 10000, nil, nil, nil)
|
||||
Wait(100)
|
||||
local success = false
|
||||
for _, v in pairs(items) do
|
||||
success = ox_inventory:AddItem(id, v.item, v.count or v.amount, v.metadata or v.info or {})
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
---@description 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)
|
||||
@@ -199,46 +209,31 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
-- restores shops to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources))
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@description 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
|
||||
|
||||
-- restores shops to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources))
|
||||
-- This will register a shop, if it already exists it will return true.
|
||||
---@description This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param inventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.RegisterShop = 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)
|
||||
Inventory.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups)
|
||||
ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = inventory, groups = shopGroups, })
|
||||
-- ox standard doesnt return anything so probably shouldnt return so everything else has the same standard. Yeaaaa probably should change this.
|
||||
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 }
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@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
|
||||
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
exports.ox_inventory:openInventory('player', target)
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
ox_inventory:forceOpenInventory(src, 'player', target)
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,5 +1,5 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ps-inventory') ~= 'started' then return end
|
||||
if GetResourceState('ps-inventory') == 'missing' then return end
|
||||
local ps = exports['ps-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ps-inventory') ~= 'started' then return end
|
||||
if GetResourceState('ps-inventory') == 'missing' then return end
|
||||
local sloth = exports['ps-inventory']
|
||||
local registeredShops = {}
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---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('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
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "ps-inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
local success = sloth:AddItem(src, item, count, slot, metadata, 'community_bridge')
|
||||
if not success then return false end
|
||||
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 success or false
|
||||
end
|
||||
|
||||
local function runMetadataSearch(src, metadata)
|
||||
local inv = Framework.GetPlayerInventory(src) or {}
|
||||
for k, v in pairs(inv) do
|
||||
if v.metadata and v.metadata == metadata then
|
||||
return true, v.slot
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
if metadata then
|
||||
local found, itemSlot = runMetadataSearch(src, metadata)
|
||||
if found then
|
||||
slot = itemSlot
|
||||
end
|
||||
end
|
||||
local success = sloth:RemoveItem(src, item, count, slot, 'community_bridge')
|
||||
if not success then return false end
|
||||
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')
|
||||
return success or false
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddItemsToTrunk = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
return false, print("AddItemsToTrunk is not implemented in ps-inventory, because of this we dont have a way to add items to a trunk.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false, print("ClearInventory is not implemented in ps-inventory, because of this we dont have a way to clear a stash.")
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -72,100 +72,45 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = sloth:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
local item = sloth:GetItemBySlot(src, slot)
|
||||
if not item then return {} end
|
||||
return {
|
||||
name = slotData.name,
|
||||
label = slotData.label or slotData.name,
|
||||
weight = slotData.weight,
|
||||
name = item.name,
|
||||
label = item.label or item.name,
|
||||
weight = item.weight,
|
||||
slot = slot,
|
||||
count = slotData.amount,
|
||||
metadata = slotData.info,
|
||||
stack = slotData.unique,
|
||||
description = slotData.description
|
||||
count = item.amount,
|
||||
metadata = item.info,
|
||||
stack = item.unique,
|
||||
description = item.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@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 _type string
|
||||
---@param id number||string
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
TriggerClientEvent('community_bridge:client:ps-inventory:openStash', src, id, { label = tbl.label, maxweight = tbl.weight, slots = tbl.slots, })
|
||||
sloth:OpenInventory(_type, id, nil, src)
|
||||
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
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return sloth:HasItem(src, item, 1)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return sloth:HasItem(src, item, requiredCount or 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)
|
||||
---@description 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
|
||||
@@ -176,11 +121,12 @@ Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
}
|
||||
local values = { newplate = newplate, oldplate = oldplate }
|
||||
MySQL.transaction.await(queries, values)
|
||||
-- ox standard doesnt return anything so probably shouldnt return so everything else has the same standard. Yeaaaa probably should change this.
|
||||
if GetResourceState('jg-mechanic') ~= 'started' then return true end
|
||||
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)
|
||||
---@description 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)
|
||||
@@ -190,31 +136,41 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@description 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.
|
||||
---@description This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param inventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.RegisterShop = 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
|
||||
Inventory.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups)
|
||||
assert(shopTitle, "RegisterShop: shopTitle is required")
|
||||
assert(inventory, "RegisterShop: shopInventory is required")
|
||||
assert(shopCoords, "RegisterShop: shopCoords is required")
|
||||
assert(shopGroups, "RegisterShop: shopGroups is required")
|
||||
|
||||
local repackItems = {}
|
||||
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
|
||||
for k, v in pairs(shopInventory) do
|
||||
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
|
||||
for k, v in pairs(inventory) do
|
||||
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.amount or v.count or 1, slot = k })
|
||||
end
|
||||
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #inventory, }
|
||||
|
||||
sloth:CreateShop(repackedShopItems)
|
||||
registeredShops[shopTitle] = true
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@param src number
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
sloth:OpenInventoryById(src, target)
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,12 +1,18 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-inventory') ~= 'started' then return end
|
||||
if GetResourceState('qb-inventory') == 'missing' then return end
|
||||
if GetResourceState('codem-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('origen_inventory') ~= 'missing' then return end
|
||||
local qb = exports['qb-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qb-inventory"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -22,26 +28,21 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qb-inventory"
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return qb:HasItem(item)
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
return qb:HasItem(item, requiredCount or 1)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
|
||||
@@ -1,106 +1,64 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-inventory') ~= 'started' then return end
|
||||
if GetResourceState('qb-inventory') == 'missing' then return end
|
||||
if GetResourceState('ox_inventory') ~= 'missing' then return end
|
||||
if GetResourceState('codem-inventory') ~= 'missing' then return end
|
||||
if GetResourceState('origen_inventory') ~= 'missing' then return end
|
||||
local qbInventory = exports['qb-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
local registeredShops = {}
|
||||
local v1ShopData = {}
|
||||
Inventory.Old = {}
|
||||
Inventory.Version = nil
|
||||
Inventory.ShopData = {}
|
||||
|
||||
local function getInventoryNewVersion()
|
||||
if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then return true end
|
||||
return false
|
||||
if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then Inventory.Version = true end
|
||||
Inventory.Version = false
|
||||
end
|
||||
|
||||
---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)
|
||||
if getInventoryNewVersion() then if not qbInventory:CanAddItem(src, item, count) then return false end end
|
||||
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 qbInventory:AddItem(src, item, count, slot, metadata, 'community_bridge')
|
||||
end
|
||||
AddEventHandler('onResourceStart', function(resourceName)
|
||||
if resourceName ~= "community_bridge" then return end
|
||||
getInventoryNewVersion()
|
||||
end)
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qb-inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
if Inventory.Version then if not qbInventory:CanAddItem(src, item, count) then return false end end
|
||||
local success = qbInventory:AddItem(src, item, count, slot, metadata, 'community_bridge')
|
||||
if not success then return false end
|
||||
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 success or false
|
||||
end
|
||||
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = qbInventory:RemoveItem(src, item, count, slot, 'community_bridge')
|
||||
if not success then return false end
|
||||
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 qbInventory:RemoveItem(src, item, count, slot, 'community_bridge')
|
||||
return success or false
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---If a trunk with the identifier does not exist, it will create one with default values.
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
local fullTrunkId = "trunk-"..identifier
|
||||
local repacked_items = {}
|
||||
local slot = 0
|
||||
for _, item in pairs(items) do
|
||||
slot = slot + 1
|
||||
repacked_items[slot] = {
|
||||
name = item.item,
|
||||
amount = item.count,
|
||||
info = item.metadata,
|
||||
type = item.type or "item",
|
||||
slot = slot,
|
||||
}
|
||||
end
|
||||
local newVersion = getInventoryNewVersion()
|
||||
if newVersion then
|
||||
qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId })
|
||||
Wait(1000)
|
||||
for i = 1, #repacked_items do
|
||||
local v = repacked_items[i]
|
||||
qbInventory:AddItem(fullTrunkId, v.name, v.amount, v.slot, v.info, "community_bridge, adding items to trunk")
|
||||
end
|
||||
else
|
||||
-- I dont have a copy of this version to test it, if you run into issues please let me know.
|
||||
TriggerEvent("inventory:server:addTrunkItems", fullTrunkId, repacked_items)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if _type == "trunk" then
|
||||
id = "trunk-"..id
|
||||
elseif _type == "glovebox" then
|
||||
id = "glovebox-"..id
|
||||
end
|
||||
if qbInventory:GetInventory(id) then
|
||||
qbInventory:ClearStash(id)
|
||||
end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -116,17 +74,16 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = qbInventory:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
@@ -142,64 +99,88 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
}
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number||string
|
||||
---@param _type string "stash", "trunk", "glovebox"
|
||||
---@param id string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
|
||||
if getInventoryNewVersion() then
|
||||
return qbInventory:OpenInventory(src, id)
|
||||
end
|
||||
|
||||
TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = tbl.weight, slots = tbl.slots})
|
||||
if not Inventory.Version then return Inventory.Old.OpenStash(src, _type, id) end
|
||||
return qbInventory:OpenInventory(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
|
||||
---@description This will add items to a stash, and return true or false based on success
|
||||
---@param id string
|
||||
---@param items table {item, count, metadata}
|
||||
---@return boolean
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
Inventory.AddStashItems = function(id, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
if not Inventory.Version then return Inventory.Old.AddStashItems(id, items) end
|
||||
local success = false
|
||||
for _, item in pairs(items) do
|
||||
success = qbInventory:AddItem(id, item.item, item.count or item.amount, nil, item.metadata or item.info, "community_bridge, adding items to stash")
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
local fullTrunkId = "trunk-"..identifier
|
||||
if not Inventory.Version then return Inventory.Old.AddTrunkItems(fullTrunkId, items) end
|
||||
if not qbInventory:GetInventory(fullTrunkId) then
|
||||
qbInventory:CreateInventory(fullTrunkId, {label = fullTrunkId, slots = 15, maxweight = 10000})
|
||||
end
|
||||
Wait(1000)
|
||||
for i = 1, #items do
|
||||
qbInventory:AddItem(fullTrunkId, items[i].name, items[i].amount or items[i].count, items[i].slot or nil, items[i].info or items[i].metadata or {}, "community_bridge, adding items to trunk")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
if not Inventory.Version then return Inventory.Old.ClearStash(id, _type) end
|
||||
if _type == "trunk" then
|
||||
id = "trunk-"..id
|
||||
elseif _type == "glovebox" then
|
||||
id = "glovebox-"..id
|
||||
end
|
||||
local inv = qbInventory:GetInventory(id)
|
||||
if not inv then return true end
|
||||
qbInventory:ClearStash(id)
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return qbInventory:HasItem(src, item, 1)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
return qbInventory:HasItem(src, item, requiredCount or 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@description 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
|
||||
if not Inventory.Version then return Inventory.Old.CanCarryItem(src, item, count) end
|
||||
return qbInventory:CanAddItem(src, item, count)
|
||||
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)
|
||||
---@description 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)
|
||||
@@ -209,87 +190,128 @@ Inventory.GetImagePath = function(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)
|
||||
---@description 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 newVersion = getInventoryNewVersion()
|
||||
if newVersion then
|
||||
local gloveboxInv = qbInventory:GetInventory('glovebox-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
|
||||
local storedGloveBox = Bridge.Tables.DeepClone(gloveboxInv, nil, nil)
|
||||
local trunkInv = qbInventory:GetInventory('trunk-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
|
||||
local storedTrunk = Bridge.Tables.DeepClone(trunkInv, nil, nil)
|
||||
qbInventory:ClearStash('glovebox-'..oldplate)
|
||||
qbInventory:ClearStash('trunk-'..oldplate)
|
||||
qbInventory:CreateInventory('glovebox-'..newplate, {label = 'glovebox-'..newplate, slots = storedGloveBox.slots, maxweight = storedGloveBox.maxweight})
|
||||
qbInventory:SetInventory('glovebox-'..newplate, storedGloveBox.items, "Community Bridge Moving Items In GloveBox")
|
||||
qbInventory:CreateInventory('trunk-'..newplate, {label = 'trunk-'..newplate, slots = storedTrunk.slots, maxweight = storedTrunk.maxweight})
|
||||
qbInventory:SetInventory('trunk-'..newplate, storedTrunk.items, "Community Bridge Moving Items In Trunk")
|
||||
return true
|
||||
else
|
||||
local queries = {
|
||||
'UPDATE inventory_glovebox SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE inventory_trunk SET plate = @newplate WHERE plate = @oldplate',
|
||||
}
|
||||
local values = { newplate = newplate, oldplate = oldplate }
|
||||
MySQL.transaction.await(queries, values)
|
||||
end
|
||||
if not Inventory.Version then return Inventory.Old.UpdatePlate(oldplate, newplate) end
|
||||
local gloveboxInv = qbInventory:GetInventory('glovebox-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
|
||||
local storedGloveBox = Bridge.Tables.DeepClone(gloveboxInv, nil, nil)
|
||||
local trunkInv = qbInventory:GetInventory('trunk-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
|
||||
local storedTrunk = Bridge.Tables.DeepClone(trunkInv, nil, nil)
|
||||
qbInventory:ClearStash('glovebox-'..oldplate)
|
||||
qbInventory:ClearStash('trunk-'..oldplate)
|
||||
qbInventory:CreateInventory('glovebox-'..newplate, {label = 'glovebox-'..newplate, slots = storedGloveBox.slots, maxweight = storedGloveBox.maxweight})
|
||||
qbInventory:SetInventory('glovebox-'..newplate, storedGloveBox.items, "Community Bridge Moving Items In GloveBox")
|
||||
qbInventory:CreateInventory('trunk-'..newplate, {label = 'trunk-'..newplate, slots = storedTrunk.slots, maxweight = storedTrunk.maxweight})
|
||||
qbInventory:SetInventory('trunk-'..newplate, storedTrunk.items, "Community Bridge Moving Items In Trunk")
|
||||
if GetResourceState('jg-mechanic') ~= 'started' then return true end
|
||||
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||
end
|
||||
|
||||
---This will open the specified shop for the src passed.
|
||||
---@description 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
|
||||
return qbInventory:OpenShop(src, shopTitle)
|
||||
else
|
||||
local shopData = v1ShopData[shopTitle]
|
||||
if not shopData then return false end
|
||||
TriggerClientEvent("inventory:client:OpenInventory", src, "shop", shopTitle, shopData)
|
||||
end
|
||||
if not Inventory.Version then return Inventory.Old.OpenShop(src, shopTitle) end
|
||||
return qbInventory:OpenShop(src, shopTitle)
|
||||
end
|
||||
|
||||
--This will register a shop, if it already exists it will return true.
|
||||
---@description This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param inventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||
if not shopTitle or not shopInventory then return end
|
||||
if registeredShops[shopTitle] then return true end
|
||||
registeredShops[shopTitle] = true
|
||||
local newVersion = getInventoryNewVersion()
|
||||
if newVersion then
|
||||
local repackedShopItems = {}
|
||||
for _, v in pairs(shopInventory) do
|
||||
table.insert(repackedShopItems, {name = v.name, price = v.price, amount = v.count or 1000})
|
||||
end
|
||||
qbInventory:CreateShop({ name = shopTitle, label = shopTitle, coords = shopCoords, items = repackedShopItems, })
|
||||
return true
|
||||
else
|
||||
local shopData = { label = shopTitle, items = {}, slots = 0 }
|
||||
|
||||
for _, v in pairs(shopInventory) do
|
||||
table.insert(shopData.items, { name = v.name, price = v.price, amount = v.count or 1000, info = {}, type = 'item' })
|
||||
end
|
||||
|
||||
shopData.slots = #shopData.items
|
||||
-- TriggerClientEvent("inventory:client:OpenInventory", src, "shop", shopTitle, shopData)
|
||||
v1ShopData[shopTitle] = shopData
|
||||
print("QB-INVENTORY: You are using an outdated version of qb-inventory, please update to the latest version. Stuff will still work but you are using litterally the most exploitable inventory in fivem.")
|
||||
Inventory.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups)
|
||||
if not shopTitle or not inventory then return end
|
||||
if Inventory.ShopData[shopTitle] then return true end
|
||||
if not Inventory.Version then return Inventory.Old.RegisterShop(shopTitle, inventory, shopCoords, shopGroups) end
|
||||
local repackedShopItems = {}
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(repackedShopItems, {name = v.name, price = v.price, amount = v.count or v.amount or 1000})
|
||||
end
|
||||
Inventory.ShopData[shopTitle] = { inventory = repackedShopItems, coords = shopCoords, groups = shopGroups }
|
||||
qbInventory:CreateShop({ name = shopTitle, label = shopTitle, coords = shopCoords, items = repackedShopItems, })
|
||||
end
|
||||
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@param src number
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
exports['qb-inventory']:OpenInventory(src, target)
|
||||
end
|
||||
|
||||
Inventory.Old.OpenShop = function(src, shopTitle)
|
||||
local shopData = Inventory.ShopData[shopTitle]
|
||||
if not shopData then return false end
|
||||
TriggerClientEvent("inventory:client:OpenInventory", src, "shop", shopTitle, shopData)
|
||||
end
|
||||
|
||||
Inventory.Old.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups)
|
||||
local shopData = { label = shopTitle, items = {}, slots = 0 }
|
||||
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(shopData.items, { name = v.name, price = v.price, amount = v.count or v.amount or 1000, info = v.metadata or v.info or {}, type = 'item' })
|
||||
end
|
||||
|
||||
shopData.slots = #shopData.items
|
||||
Inventory.ShopData[shopTitle] = shopData
|
||||
print("QB-INVENTORY: You are using an outdated version of qb-inventory, please update to the latest version. Stuff will still work but you are using litterally the most exploitable inventory in fivem.")
|
||||
end
|
||||
|
||||
Inventory.Old.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE inventory_glovebox SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE inventory_trunk SET plate = @newplate WHERE plate = @oldplate',
|
||||
}
|
||||
local values = { newplate = newplate, oldplate = oldplate }
|
||||
MySQL.transaction.await(queries, values)
|
||||
if GetResourceState('jg-mechanic') ~= 'started' then return true end
|
||||
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||
end
|
||||
|
||||
Inventory.Old.OpenStash = function(src, _type, id)
|
||||
local tbl = Inventory.Stashes[id]
|
||||
TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = tbl.weight or 5000, slots = tbl.slots or 20})
|
||||
end
|
||||
|
||||
Inventory.Old.AddTrunkItems = function(fullTrunkId, items)
|
||||
TriggerEvent("inventory:server:addTrunkItems", fullTrunkId, items)
|
||||
return true
|
||||
end
|
||||
|
||||
Inventory.Old.AddStashItems = function(id, items)
|
||||
return false, print("AddStashItems is not supported with qb-inventory v1")
|
||||
end
|
||||
|
||||
Inventory.Old.ClearStash = function(id, _type)
|
||||
return false, print("ClearStash is not supported with qb-inventory v1")
|
||||
end
|
||||
|
||||
Inventory.Old.CanCarryItem = function(src, item, count)
|
||||
local oldQbInventoryConfig = Require('config.lua', 'qb-inventory')
|
||||
local maxInvWeight = oldQbInventoryConfig.MaxWeight or 100000
|
||||
local maxInvSlots = oldQbInventoryConfig.MaxSlots or 30
|
||||
local packedWeight = 0
|
||||
local addedSlots = 1
|
||||
local stackCheck = Inventory.GetItemInfo(item).stack
|
||||
local playerInv = Framework.GetPlayerInventory(src)
|
||||
if not playerInv then return false end
|
||||
for k, v in pairs(playerInv) do
|
||||
if v.name then
|
||||
local weight = Inventory.GetItemInfo(v.name).weight or 0
|
||||
count = count + v.count
|
||||
packedWeight = packedWeight + (weight * v.count)
|
||||
end
|
||||
end
|
||||
local slotsUsed = #playerInv
|
||||
if not stackCheck then addedSlots = count end
|
||||
if slotsUsed + addedSlots > maxInvSlots then return false end
|
||||
if packedWeight + (Inventory.GetItemInfo(item).weight or 0) * count > maxInvWeight then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,40 +1,40 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qs-inventory') ~= 'started' then return end
|
||||
if GetResourceState('qs-inventory') == 'missing' then return end
|
||||
local quasar = exports["qs-inventory"]
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemsData = quasar:GetItemList()
|
||||
if not itemsData then return {} end
|
||||
local itemData = itemsData[item]
|
||||
if not itemData 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 = Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qs-inventory"
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemsData = quasar:GetItemList()
|
||||
if not itemsData then return {} end
|
||||
itemsData = itemsData[item]
|
||||
if not itemsData then return {} end
|
||||
return {
|
||||
name = itemsData.name or "Missing Name",
|
||||
label = itemsData.label or "Missing Label",
|
||||
stack = itemsData.unique or "false",
|
||||
weight = itemsData.weight or "0",
|
||||
description = itemsData.description or "none",
|
||||
image = Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return quasar:GetItemList()
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
@@ -42,7 +42,7 @@ Inventory.HasItem = function(item)
|
||||
return check and true or false
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@description 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)
|
||||
@@ -50,7 +50,7 @@ Inventory.GetItemCount = function(item)
|
||||
return searchItem or 0
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -60,7 +60,7 @@ Inventory.GetImagePath = function(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}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
@@ -69,10 +69,10 @@ Inventory.GetPlayerInventory = function()
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
count = v.amount or v.count,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
metadata = v.info or v.metadata or {},
|
||||
stack = v.unique or v.stack or false,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
@@ -80,11 +80,4 @@ Inventory.GetPlayerInventory = function()
|
||||
return items
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param id any
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(id)
|
||||
quasar:RegisterStash(id, 50, 50000)
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,12 +1,18 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qs-inventory') ~= 'started' then return end
|
||||
if GetResourceState('qs-inventory') == 'missing' then return end
|
||||
|
||||
local quasar = exports['qs-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---This will add an item, and return true or false based on success
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qs-inventory"
|
||||
end
|
||||
|
||||
---@description This will add an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -15,17 +21,13 @@ Inventory.Stashes = Inventory.Stashes or {}
|
||||
---@return boolean
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
if not quasar:CanCarryItem(src, item, count) then return false end
|
||||
local success = quasar:AddItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return quasar:AddItem(src, item, count, slot, metadata)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "qs-inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -33,46 +35,22 @@ end
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = quasar:RemoveItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return quasar:RemoveItem(src, item, count, slot, metadata)
|
||||
return success
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
Inventory.AddTrunkItems = function(identifier, items)
|
||||
if type(items) ~= "table" then return false end
|
||||
return false
|
||||
--[[
|
||||
for k, v in pairs(items) do
|
||||
--
|
||||
In testing this inventory allowed it on owned vehicle but not unowned vehicles,
|
||||
also attempted registering it as a stash with no luck.
|
||||
was thinking about just forcing it in sql but there is data attached that I assume is a timestamp
|
||||
kinda not sure on this one atm...
|
||||
Also there is no GetInventory(identifier) only by player source
|
||||
--quasar:AddToTrunk(identifier, v.count, v.metadata, v.item, v.metadata)
|
||||
end
|
||||
return true
|
||||
--]]
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
if type(id) ~= "string" then return false end
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return false
|
||||
--[[
|
||||
quasar:ClearOtherInventory(_type, id)
|
||||
|
||||
return true
|
||||
--]]
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -90,24 +68,23 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return quasar:GetItemList()
|
||||
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.
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return quasar:GetItemTotalAmount(src, item)
|
||||
if metadata then print("qs-inventory does not support metadata searching for item counts, you will need to get the inventory and parse it manually.") end
|
||||
return quasar:GetItemTotalAmount(src, item) or 0
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@description This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
@@ -116,20 +93,18 @@ Inventory.GetPlayerInventory = function(src)
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
count = v.amount or v.count,
|
||||
metadata = v.info or v.metadata or {},
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local playerItems = quasar:GetInventory(src)
|
||||
for _, item in pairs(playerItems) do
|
||||
@@ -139,9 +114,9 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
label = item.label,
|
||||
weight = item.weight,
|
||||
slot = slot,
|
||||
count = item.amount,
|
||||
metadata = item.info,
|
||||
stack = item.unique or false,
|
||||
count = item.amount or item.count,
|
||||
metadata = item.info or item.metadata or {},
|
||||
stack = item.unique or item.stack or false,
|
||||
description = item.description
|
||||
}
|
||||
end
|
||||
@@ -149,7 +124,7 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
return {}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -159,62 +134,40 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return quasar:SetItemMetadata(src, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number||string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
if not Inventory.Stashes[id] then return end
|
||||
local tbl = Inventory.Stashes[id]
|
||||
TriggerEvent("inventory:server:OpenInventory", _type, id, tbl and { maxweight = tbl.weight, slots = tbl.slots })
|
||||
TriggerEvent("inventory:server:OpenInventory", _type, id, tbl and { maxweight = tbl.weight or 5000, slots = tbl.slots or 20 })
|
||||
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
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
Inventory.HasItem = function(src, item, requiredCount)
|
||||
local count = quasar:GetItemTotalAmount(src, item)
|
||||
if not count then return false end
|
||||
return count > 0
|
||||
return count >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@description 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)
|
||||
return quasar:CanCarryItem(src, item, count) or false
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@description 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
|
||||
@@ -229,7 +182,7 @@ Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
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)
|
||||
---@description 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)
|
||||
@@ -239,12 +192,4 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
exports['qs-inventory']:OpenInventory(src, target)
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,10 +1,17 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('tgiann-inventory') ~= 'started' then return end
|
||||
if GetResourceState('tgiann-inventory') == 'missing' then return end
|
||||
|
||||
local tgiann = exports["tgiann-inventory"]
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "tgiann-inventory"
|
||||
end
|
||||
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -21,20 +28,15 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "tgiann-inventory"
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return tgiann:HasItem(item)
|
||||
Inventory.HasItem = function(item, requiredCount)
|
||||
return tgiann:HasItem(item, requiredCount)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@description This will return their count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
@@ -42,7 +44,7 @@ Inventory.GetItemCount = function(item)
|
||||
return searchItem or 0
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -54,7 +56,7 @@ Inventory.GetImagePath = function(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}
|
||||
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
@@ -74,10 +76,4 @@ Inventory.GetPlayerInventory = function()
|
||||
return items
|
||||
end
|
||||
|
||||
---@param id any
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(id)
|
||||
tgiann:OpenInventory('stash', id, { maxweight = 400000, slots = 100 })
|
||||
end
|
||||
|
||||
return Inventory
|
||||
@@ -1,43 +1,46 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('tgiann-inventory') ~= 'started' then return end
|
||||
if GetResourceState('tgiann-inventory') == 'missing' then return end
|
||||
|
||||
local tgiann = exports["tgiann-inventory"]
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
---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)
|
||||
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 get the name of the in use resource.
|
||||
---@description This will get the name of the in use resource.
|
||||
---@return string
|
||||
Inventory.GetResourceName = function()
|
||||
return "tgiann-inventory"
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@description 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
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@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 tgiann:RemoveItem(src, item, count, slot, metadata)
|
||||
Inventory.AddItem = function(src, item, count, slot, metadata)
|
||||
if not tgiann:CanCarryItem(src, item, count) then return false end
|
||||
local success = tgiann:AddItem(src, item, count, slot, metadata, false)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@description 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 (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
local success = tgiann:RemoveItem(src, item, count, slot, metadata)
|
||||
if not success then return false end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return success or false
|
||||
end
|
||||
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
@@ -53,25 +56,23 @@ Inventory.GetItemInfo = function(item)
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@description This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return tgiann:GetItemList()
|
||||
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.
|
||||
---@description This will return the count of the item in the players inventory, if not found will return 0.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@param metadata table (optional)
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
local _item = tgiann:GetItemByName(src, item, metadata)
|
||||
return _item.amount or 0
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@description This will return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
@@ -85,12 +86,10 @@ Inventory.GetPlayerInventory = function(src)
|
||||
return items
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@description Returns the specified slot data as a table.
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
---@return table {weight, name, metadata, slot, label, count}
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local item = tgiann:GetItemBySlot(src, slot)
|
||||
if not item then return {} end
|
||||
@@ -99,14 +98,14 @@ Inventory.GetItemBySlot = function(src, slot)
|
||||
label = item.label,
|
||||
weight = item.weight,
|
||||
slot = slot,
|
||||
count = item.amount,
|
||||
metadata = item.info,
|
||||
stack = item.unique or false,
|
||||
count = item.amount or item.count,
|
||||
metadata = item.info or item.metadata or {},
|
||||
stack = item.unique or item.stack or false,
|
||||
description = item.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@description This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
@@ -116,42 +115,18 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
tgiann:UpdateItemMetadata(src, item, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@description This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param id number||string
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(src, _type, id)
|
||||
_type = _type or "stash"
|
||||
local tbl = Inventory.Stashes[id]
|
||||
local tbl = Inventory.Stashes[id] or {weight = 1000000, slot = 50, label = "Stash"}
|
||||
return tgiann:ForceOpenInventory(src, _type, id, tbl and { maxWeight = tbl.weight , slots = tbl.slot, label = tbl.label})
|
||||
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
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = slots,
|
||||
weight = weight,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@description This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
@@ -159,7 +134,7 @@ 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.
|
||||
---@description This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
@@ -168,7 +143,7 @@ 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)
|
||||
---@description 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
|
||||
@@ -184,7 +159,7 @@ Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||
end
|
||||
|
||||
---This will add items to a trunk, and return true or false based on success
|
||||
---@description This will add items to a trunk, and return true or false based on success
|
||||
---@param identifier string
|
||||
---@param items table
|
||||
---@return boolean
|
||||
@@ -197,7 +172,7 @@ Inventory.AddTrunkItems = function(identifier, items)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param id string
|
||||
---@return boolean
|
||||
Inventory.ClearStash = function(id, _type)
|
||||
@@ -207,7 +182,7 @@ Inventory.ClearStash = function(id, _type)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@description This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
@@ -219,30 +194,13 @@ Inventory.GetImagePath = function(item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
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 }
|
||||
---@description This will open a players inventory, used for admin purposes and stuff.
|
||||
---@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
|
||||
|
||||
---@param target number
|
||||
Inventory.OpenPlayerInventory = function(src, target)
|
||||
assert(src, "OpenPlayerInventory: src is required")
|
||||
if not target then
|
||||
target = src
|
||||
end
|
||||
exports['tgiann-inventory']:OpenInventoryById(src, target)
|
||||
assert(target, "OpenPlayerInventory: target is required")
|
||||
tgiann:OpenInventoryById(src, target)
|
||||
end
|
||||
|
||||
|
||||
return Inventory
|
||||
Reference in new issue
Block a user