ed
This commit is contained in:
parent
510e3ffcf2
commit
f43cf424cf
305 changed files with 34683 additions and 0 deletions
|
@ -0,0 +1,55 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
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)
|
||||
return Framework.GetItemInfo(item)
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return Framework.HasItem(item)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return Framework.GetItemCount(item)
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
return "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
Inventory.StripPNG = function(item)
|
||||
if string.find(item, ".png") then
|
||||
item = string.gsub(item, ".png", "")
|
||||
end
|
||||
return item
|
||||
end
|
||||
|
||||
---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 = {} }
|
||||
return itemList.Items
|
||||
end
|
||||
return Framework.Shared.Items
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,196 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
Inventory = Inventory 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 Framework.AddItem(src, item, count, slot, metadata)
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
item = type(item) == "table" and item.name or item
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return Framework.RemoveItem(src, item, count, slot, metadata)
|
||||
end
|
||||
|
||||
---This will 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.")
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will return success or failure.
|
||||
---@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.")
|
||||
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"}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
return Framework.GetItemInfo(item)
|
||||
end
|
||||
|
||||
---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 = {} }
|
||||
return itemList.Items
|
||||
end
|
||||
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
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@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}}
|
||||
---@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}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
return Framework.GetItemBySlot(src, slot)
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return Framework.SetMetadata(src, item, 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]
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.")
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
---@param id number|string
|
||||
---@param label string
|
||||
---@param slots number
|
||||
---@param weight number
|
||||
---@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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return Framework.HasItem(src, item)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A CanCarryItem Feature.")
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
return false, Prints.Error("This Inventory Has Not Been Bridged For A UpdatePlate Feature.")
|
||||
end
|
||||
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
Inventory.OpenShop = function(src, shopTitle)
|
||||
return Bridge.Shops.OpenShop(src, shopTitle)
|
||||
end
|
||||
|
||||
-- This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||
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)
|
||||
---@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.
|
||||
---example: "item.png" will become "item"
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.StripPNG = function(item)
|
||||
if string.find(item, ".png") then
|
||||
item = string.gsub(item, ".png", "")
|
||||
end
|
||||
return item
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,65 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('codem-inventory') ~= 'started' then return end
|
||||
Inventory = Inventory or {}
|
||||
|
||||
local codem = exports['codem-inventory']
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = codem:GetItemList(item)
|
||||
if not itemData then return {} end
|
||||
local image = itemData.image and Inventory.GetImagePath(itemData.image) or Inventory.GetImagePath(item)
|
||||
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 = image,
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList()
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
local inventory = codem:getUserInventory()
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
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
|
|
@ -0,0 +1,193 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('codem-inventory') ~= 'started' 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 remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return codem:RemoveItem(src, item, count, slot)
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = codem:GetItemList(item)
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.unique or "false",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return codem:GetItemList()
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
local identifier = Framework.GetPlayerIdentifier(src)
|
||||
local playerItems = codem:GetInventory(identifier, src)
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = codem:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
return {
|
||||
name = v.name,
|
||||
label = v.label or v.name,
|
||||
weight = v.weight,
|
||||
slot = v.slot,
|
||||
count = v.amount or v.count,
|
||||
metadata = v.info or v.metadata,
|
||||
stack = v.unique,
|
||||
description = v.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return codem:SetItemMetadata(src, slot, metadata)
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return codem:HasItem(src, item, 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will 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.
|
||||
---@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 codem-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
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
return false, print("Unable to update plate for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.")
|
||||
end
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,85 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('core_inventory') ~= 'started' then return end
|
||||
local core = exports.core_inventory
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.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 return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
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
|
||||
if not dataRepack then return {} end
|
||||
elseif frameworkName == 'qb-core' then
|
||||
dataRepack = Framework.Shared.Items
|
||||
if not dataRepack then return {} end
|
||||
end
|
||||
return dataRepack
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return core:hasItem(item, 1)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return core:getItemCount(item)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item))
|
||||
local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local playerItems = core:getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.id,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,260 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('core_inventory') ~= 'started' then return end
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
local core = exports.core_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 core:addItem(src, item, count, metadata)
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
if not slot and metadata then
|
||||
local inv = Inventory.GetPlayerInventory(src)
|
||||
if not inv then return false end
|
||||
for _, v in pairs(inv) do
|
||||
if v.name == item and v.metadata == metadata then
|
||||
slot = v.slot
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
if slot then
|
||||
local identifier = Framework.GetPlayerIdentifier(src)
|
||||
if not identifier then return false end
|
||||
local framework = Bridge.Framework.GetFrameworkName()
|
||||
if framework == 'es_extended' then
|
||||
identifier = string.gsub(identifier, ":", "")
|
||||
end
|
||||
local weirdInventoryName = 'content-' .. identifier
|
||||
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.
|
||||
---if metadata is passed it will find the matching items count.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
if metadata then
|
||||
local inv = Inventory.GetPlayerInventory(src)
|
||||
local deepCount = 0
|
||||
if not inv then return 0 end
|
||||
for _, v in pairs(inv) do
|
||||
if v.name == item and v.metadata == metadata then
|
||||
deepCount = deepCount + v.count
|
||||
end
|
||||
end
|
||||
return deepCount
|
||||
end
|
||||
local count = core:getItemCount(src, item)
|
||||
return count or 0
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
local frameworkInUse = Bridge.Framework.GetFrameworkName()
|
||||
if frameworkInUse == 'qb-core' then
|
||||
return Bridge.Framework.GetPlayerInventory(src)
|
||||
end
|
||||
local playerItems = core:getInventory(src)
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.metadata and v.count > 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,
|
||||
})
|
||||
end
|
||||
end
|
||||
else
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.id,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local inv = Inventory.GetPlayerInventory(src)
|
||||
if not inv then return {} end
|
||||
for _, v in pairs(inv) do
|
||||
if v.slot == slot then
|
||||
return {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
metadata = v.metadata,
|
||||
slot = v.slot,
|
||||
}
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
core: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]
|
||||
core:openInventory(src, id, _type, tbl.slots, tbl.weight, true, nil, false)
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
---@param id number|string
|
||||
---@param label string
|
||||
---@param slots number
|
||||
---@param weight number
|
||||
---@param owner string
|
||||
---@param groups table
|
||||
---@param coords table
|
||||
---@return boolean
|
||||
---@return string|number
|
||||
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
|
||||
if Inventory.Stashes[id] then return true, id end
|
||||
if not slots then slots = 30 end
|
||||
local mathyShit = slots / 2
|
||||
Inventory.Stashes[id] = {
|
||||
id = id,
|
||||
label = label,
|
||||
slots = mathyShit,
|
||||
weight = mathyShit,
|
||||
owner = owner,
|
||||
groups = groups,
|
||||
coords = coords
|
||||
}
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return core:getItemCount(src, item) > 0
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will 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 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
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
-- have no clue if this will work but fingers crossed
|
||||
local queries = {
|
||||
'UPDATE coreinventories SET name = @newplate WHERE name = @oldplate',
|
||||
'UPDATE coreinventories SET name = @newplate WHERE name = @glovebox_oldplate',
|
||||
'UPDATE coreinventories SET name = @newplate WHERE name = @trunk_oldplate',
|
||||
}
|
||||
local values = {
|
||||
newplate = newplate,
|
||||
oldplate = oldplate,
|
||||
glovebox_oldplate = 'glovebox-' .. oldplate,
|
||||
trunk_oldplate = 'trunk-' .. oldplate
|
||||
}
|
||||
MySQL.transaction.await(queries, values)
|
||||
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)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item))
|
||||
local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this.
|
||||
Callback.Register('community_bridge:Callback:core_inventory', function(source)
|
||||
local items = core:getItemsList()
|
||||
return items or {}
|
||||
end)
|
||||
|
||||
---This will return the entire items table from the inventory.
|
||||
---@return table
|
||||
Inventory.Items = function()
|
||||
return core:getItemsList()
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,52 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('jpr-inventory') ~= 'started' then return end
|
||||
local jpr = exports['jpr-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 itemData = Framework.Shared.Items[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = Inventory.GetImagePath(itemData.name)
|
||||
}
|
||||
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.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data)
|
||||
if source ~= 65535 then return end
|
||||
TriggerEvent("inventory:client:SetCurrentStash", id)
|
||||
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
||||
end)
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,192 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('jpr-inventory') ~= 'started' then return end
|
||||
|
||||
local jpr = exports['jpr-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("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 remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return exports['jpr-inventory']:RemoveItem(src, item, count, slot, 'community_bridge Item removed')
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemTable = Framework.GetItemInfo(item)
|
||||
itemTable.image = Inventory.GetImagePath(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}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = jpr:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
return {
|
||||
name = slotData.name,
|
||||
label = slotData.label,
|
||||
weight = slotData.weight,
|
||||
slot = slot,
|
||||
count = slotData.amount,
|
||||
metadata = slotData.info,
|
||||
stack = slotData.unique,
|
||||
description = slotData.description
|
||||
}
|
||||
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: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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return jpr:HasItem(src, item, 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE trunkitems 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
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory 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
|
||||
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 })
|
||||
end
|
||||
|
||||
jpr:CreateShop(repackedShopItems)
|
||||
registeredShops[shopTitle] = true
|
||||
return true
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,79 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('origen_inventory') ~= 'started' then return end
|
||||
Inventory = Inventory or {}
|
||||
local origin = exports.origen_inventory
|
||||
|
||||
---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)
|
||||
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 = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
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.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return origin:HasItem(item)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
local inventory = origin:Search('count', item)
|
||||
if not inventory then return 0 end
|
||||
return inventory.count
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("origen_inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local repack = {}
|
||||
local inventory = origin:GetInventory()
|
||||
if not inventory then return {} end
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(repack, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
slot = v.slot,
|
||||
metadata = v.metadata,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
return repack
|
||||
end
|
||||
|
||||
Inventory.OpenStash = function(id)
|
||||
origin:openInventory('stash', id, { label = id, weight = 400000, slots = 100, })
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,242 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('origen_inventory') ~= 'started' 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 remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return origin:removeItem(src, item, count, metadata, slot, true)
|
||||
end
|
||||
|
||||
---This will 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)
|
||||
local repack_items = {}
|
||||
for _, v in pairs(items) do
|
||||
table.insert(repack_items, {
|
||||
name = v.item,
|
||||
amount = v.count,
|
||||
metadata = v.metadata or {}
|
||||
})
|
||||
end
|
||||
if #repack_items == 0 then return false end
|
||||
origin:addItems(id, repack_items)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
|
||||
---@param identifier string
|
||||
---@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
|
||||
if _type == "trunk" then
|
||||
id = "trunk_"..id
|
||||
elseif _type == "glovebox" then
|
||||
id = "glovebox_"..id
|
||||
elseif _type == "stash" then
|
||||
id = "stash_"..id
|
||||
end
|
||||
local inv = origin:getInventory(identifier, _type)
|
||||
if not inv then return false end
|
||||
local indexed = inv.inventory
|
||||
for _, v in pairs(indexed) do
|
||||
if v.slot then
|
||||
origin:removeItem(id, v.name, v.amount, nil, v.slot)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = origin:Items(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 = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return origin:getItemCount(src, item, metadata, false) or 0
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
local playerInv = origin:GetInventory(src)
|
||||
local inv = playerInv.inventory or {}
|
||||
local repack = {}
|
||||
for _, v in pairs(inv) do
|
||||
if v.slot then
|
||||
table.insert(repack, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.metadata or {},
|
||||
slot = v.slot,
|
||||
label = v.label or "Unknown"
|
||||
})
|
||||
end
|
||||
end
|
||||
return repack
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local playerInv = Inventory.GetPlayerInventory(src)
|
||||
for _, v in pairs(playerInv) do
|
||||
if v.slot == slot then
|
||||
return {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
weight = v.weight or 0,
|
||||
metadata = v.metadata,
|
||||
slot = v.slot,
|
||||
label = v.label
|
||||
}
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
origin: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]
|
||||
return origin:OpenInventory(src, _type, 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
|
||||
}
|
||||
origin:registerStash(id, label, slots, weight, owner, groups, coords)
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return origin:getItemCount(src , item) > 0
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return origin:canCarryItem(src, item, count)
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE trunkitems 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
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("origin", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,62 @@
|
|||
---@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
|
||||
|
||||
local ox_inventory = exports.ox_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 itemData = ox_inventory:Items(item)
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.stack or "true",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = (itemData.client and itemData.client.image) or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return ox_inventory:Search('count', item) > 0
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
return ox_inventory:GetItemCount(item, nil, false)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
return ox_inventory:GetPlayerItems()
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,227 @@
|
|||
---@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
|
||||
|
||||
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)
|
||||
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 remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return ox_inventory:RemoveItem(src, item, count, metadata, slot)
|
||||
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}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = ox_inventory:Items(item)
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.stack or "true",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = string.format("nui://ox_inventory/web/images/%s", itemData.client and itemData.client.image or string.format("%s.png", item)),
|
||||
}
|
||||
end
|
||||
|
||||
---This will 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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return ox_inventory:GetItemCount(src, item, metadata, false)
|
||||
end
|
||||
|
||||
---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}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
return ox_inventory:GetSlot(src, slot)
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
ox_inventory:SetMetadata(src, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _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
|
||||
|
||||
---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
|
||||
}
|
||||
ox_inventory:RegisterStash(id, label, slots, weight, owner, groups)
|
||||
return true, id
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return ox_inventory:GetItemCount(src, item, nil, false) > 0
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return ox_inventory:CanCarryItem(src, item, count)
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@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
|
||||
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||
end
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
Inventory.OpenShop = function(src, shopTitle)
|
||||
TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle})
|
||||
end
|
||||
|
||||
-- This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.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)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
---UNUSED:
|
||||
---This will return generic item data from the specified inventory, with the items total count.
|
||||
---format without metadata { count, stack, name, weight, label }
|
||||
---fortmat with metadata { count, stack, name, weight, label, metadata }
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return table
|
||||
Inventory.GetItem = function(src, item, metadata)
|
||||
return ox_inventory:GetItem(src, item, metadata, false)
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,52 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ps-inventory') ~= 'started' then return end
|
||||
local ps = exports['ps-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 itemData = Framework.Shared.Items[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = Inventory.GetImagePath(itemData.name)
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return ps:HasItem(item)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("ps-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://ps-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
RegisterNetEvent('community_bridge:client:ps-inventory:openStash', function(id, data)
|
||||
if source ~= 65535 then return end
|
||||
TriggerEvent('ps-inventory:client:SetCurrentStash', id)
|
||||
TriggerServerEvent('ps-inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
||||
end)
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,214 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('ps-inventory') ~= 'started' 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 remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return sloth:RemoveItem(src, item, count, slot, 'community_bridge')
|
||||
end
|
||||
|
||||
---This will 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}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = QBCore.Shared.Items[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.stack or "true",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---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}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = sloth:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
return {
|
||||
name = slotData.name,
|
||||
label = slotData.label or slotData.name,
|
||||
weight = slotData.weight,
|
||||
slot = slot,
|
||||
count = slotData.amount,
|
||||
metadata = slotData.info,
|
||||
stack = slotData.unique,
|
||||
description = slotData.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
local itemData = Inventory.GetItemBySlot(src, slot)
|
||||
if not itemData then return end
|
||||
if itemData.count > 1 then return print("Items with more than 1 count cannot be set with metadata plase adjust item to unique in the qb shared item name : "..item) end
|
||||
Inventory.RemoveItem(src, item, 1, slot)
|
||||
return Inventory.AddItem(src, item, 1, slot, metadata)
|
||||
end
|
||||
|
||||
---This will open the specified stash for the src passed.
|
||||
---@param src number
|
||||
---@param _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:ps-inventory:openStash', src, id, { label = tbl.label, maxweight = 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 return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return sloth:HasItem(src, item, 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE trunkitems 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
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("ps-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://ps-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
-- This will open the specified shop for the src passed.
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
Inventory.OpenShop = function(src, shopTitle)
|
||||
return sloth:OpenShop(src, shopTitle)
|
||||
end
|
||||
|
||||
-- This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.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
|
||||
|
||||
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 })
|
||||
end
|
||||
|
||||
sloth:CreateShop(repackedShopItems)
|
||||
registeredShops[shopTitle] = true
|
||||
return true
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,52 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-inventory') ~= 'started' then return end
|
||||
local qb = exports['qb-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 itemData = Framework.Shared.Items[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = Inventory.GetImagePath(itemData.image or itemData.name)
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return qb:HasItem(item)
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("qb-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id, data)
|
||||
if source ~= 65535 then return end
|
||||
TriggerEvent("inventory:client:SetCurrentStash", id)
|
||||
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
||||
end)
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,278 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-inventory') ~= 'started' then return end
|
||||
local qbInventory = exports['qb-inventory']
|
||||
|
||||
Inventory = Inventory or {}
|
||||
Inventory.Stashes = Inventory.Stashes or {}
|
||||
|
||||
local registeredShops = {}
|
||||
local v1ShopData = {}
|
||||
|
||||
local function getInventoryNewVersion()
|
||||
if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then return true end
|
||||
return 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)
|
||||
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
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return qbInventory:RemoveItem(src, item, count, slot, 'community_bridge')
|
||||
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}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = Framework.Shared.Items[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = Inventory.GetImagePath(itemData.image or itemData.name)
|
||||
}
|
||||
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}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local slotData = qbInventory:GetItemBySlot(src, slot)
|
||||
if not slotData then return {} end
|
||||
return {
|
||||
name = slotData.name,
|
||||
label = slotData.name,
|
||||
weight = slotData.weight,
|
||||
slot = slotData.slot,
|
||||
count = slotData.amount,
|
||||
metadata = slotData.info,
|
||||
stack = slotData.unique,
|
||||
description = slotData.description
|
||||
}
|
||||
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]
|
||||
|
||||
if getInventoryNewVersion() then
|
||||
return qbInventory:OpenInventory(src, id)
|
||||
end
|
||||
|
||||
TriggerClientEvent('community_bridge:client:qb-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 return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return qbInventory:HasItem(src, item, 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("qb-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
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 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.
|
||||
---@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
|
||||
end
|
||||
|
||||
--This will register a shop, if it already exists it will return true.
|
||||
---@param shopTitle string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
Inventory.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.")
|
||||
end
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,84 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qs-inventory') ~= 'started' 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 = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
local check = quasar:Search(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.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
local searchItem = quasar:Search(item)
|
||||
return searchItem or 0
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
local inventory = quasar:getUserInventory()
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param id any
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(id)
|
||||
quasar:RegisterStash(id, 50, 50000)
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,236 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qs-inventory') ~= 'started' 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
|
||||
---@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 quasar: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 quasar:AddItem(src, item, count, slot, metadata)
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return quasar:RemoveItem(src, item, count, slot, metadata)
|
||||
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.
|
||||
---@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}
|
||||
---@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 = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(src, item, metadata)
|
||||
return quasar:GetItemTotalAmount(src, item)
|
||||
end
|
||||
|
||||
---This wil return the players inventory.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
local playerItems = quasar:GetInventory(src)
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local playerItems = quasar:GetInventory(src)
|
||||
for _, item in pairs(playerItems) do
|
||||
if item.slot == slot then
|
||||
return {
|
||||
name = item.name,
|
||||
label = item.label,
|
||||
weight = item.weight,
|
||||
slot = slot,
|
||||
count = item.amount,
|
||||
metadata = item.info,
|
||||
stack = item.unique or false,
|
||||
description = item.description
|
||||
}
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
return quasar: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]
|
||||
TriggerEvent("inventory:server:OpenInventory", _type, id, tbl and { maxweight = tbl.weight, slots = tbl.slots })
|
||||
TriggerClientEvent("inventory:client:SetCurrentStash",src, id)
|
||||
end
|
||||
|
||||
---This will register a stash
|
||||
---@param id number|string
|
||||
---@param label string
|
||||
---@param slots number
|
||||
---@param weight number
|
||||
---@param owner string
|
||||
---@param groups table
|
||||
---@param coords table
|
||||
---@return boolean
|
||||
---@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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
local count = quasar:GetItemTotalAmount(src, item)
|
||||
if not count then return false end
|
||||
return count > 0
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return quasar:CanCarryItem(src, item, count)
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE inventory_trunk SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE inventory_glovebox 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
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,75 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('tgiann-inventory') ~= 'started' then return end
|
||||
local tgiann = exports["tgiann-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 itemData = tgiann:GetItemList()
|
||||
if not itemData[item] then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.unique or "false",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
return tgiann:HasItem(item)
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
local searchItem = tgiann:GetItemCount(item, nil, false)
|
||||
return searchItem or 0
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
|
||||
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
|
||||
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function()
|
||||
local items = {}
|
||||
local inventory = tgiann:GetPlayerItems()
|
||||
for _, v in pairs(inventory) do
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
---@param id any
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(id)
|
||||
tgiann:OpenInventory('stash', id, { maxweight = 400000, slots = 100 })
|
||||
end
|
||||
|
||||
return Inventory
|
|
@ -0,0 +1,232 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('tgiann-inventory') ~= 'started' 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)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return tgiann:AddItem(src, item, count, slot, metadata, false)
|
||||
end
|
||||
|
||||
---This will remove an item, and return true or false based on success
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean
|
||||
Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
|
||||
return tgiann:RemoveItem(src, item, count, slot, metadata)
|
||||
end
|
||||
|
||||
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemData = tgiann:GetItemList()
|
||||
if not itemData[item] then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.unique or "false",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---This will return the 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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@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.
|
||||
---@param src number
|
||||
---@return table
|
||||
Inventory.GetPlayerInventory = function(src)
|
||||
local inventory = tgiann:GetPlayerItems(src)
|
||||
local items = {}
|
||||
for _, v in pairs(inventory) do
|
||||
if tonumber(_) then
|
||||
table.insert(items, {name = v.name, label = v.name, weight = 0, description = v.description, slot = v.slot, count = v.amount, metadata = v.info})
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
---Returns the specified slot data as a table.
|
||||
---
|
||||
---format {weight, name, metadata, slot, label, count}
|
||||
---@param src number
|
||||
---@param slot number
|
||||
---@return table
|
||||
Inventory.GetItemBySlot = function(src, slot)
|
||||
local item = tgiann:GetItemBySlot(src, slot)
|
||||
if not item then return {} end
|
||||
return {
|
||||
name = item.name,
|
||||
label = item.label,
|
||||
weight = item.weight,
|
||||
slot = slot,
|
||||
count = item.amount,
|
||||
metadata = item.info,
|
||||
stack = item.unique or false,
|
||||
description = item.description
|
||||
}
|
||||
end
|
||||
|
||||
---This will set the metadata of an item in the inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return nil
|
||||
Inventory.SetMetadata = function(src, item, slot, metadata)
|
||||
tgiann:UpdateItemMetadata(src, item, 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]
|
||||
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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(src, item)
|
||||
return tgiann:HasItem(src, item, 1)
|
||||
end
|
||||
|
||||
---This is to get if there is available space in the inventory, will return boolean.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param count number
|
||||
---@return boolean
|
||||
Inventory.CanCarryItem = function(src, item, count)
|
||||
return tgiann:CanCarryItem(src, item, count)
|
||||
end
|
||||
|
||||
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
|
||||
---@param oldplate string
|
||||
---@param newplate string
|
||||
---@return boolean
|
||||
Inventory.UpdatePlate = function(oldplate, newplate)
|
||||
local queries = {
|
||||
'UPDATE tgiann_inventory_trunkitems SET plate = @newplate WHERE plate = @oldplate',
|
||||
'UPDATE tgiann_inventory_gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
|
||||
}
|
||||
local values = { newplate = newplate, oldplate = oldplate }
|
||||
MySQL.transaction.await(queries, values)
|
||||
tgiann:UpdateVehicle(oldplate, newplate)
|
||||
if GetResourceState('jg-mechanic') ~= 'started' then return true end
|
||||
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||
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
|
||||
for _, v in pairs(items) do
|
||||
tgiann:AddItemToSecondaryInventory("trunk", identifier, v.item, v.count, nil, 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
|
||||
tgiann:DeleteInventory(_type, id)
|
||||
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
|
||||
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
|
||||
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
|
||||
---UNUSED:
|
||||
---This will return generic item data from the specified inventory, with the items total count.
|
||||
---
|
||||
---format without metadata { count, stack, name, weight, label }
|
||||
---
|
||||
---fortmat with metadata { count, stack, name, weight, label, metadata }
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return table
|
||||
Inventory.GetItem = function(src, item, metadata)
|
||||
local item = tgiann:GetItemByName(src, item, metadata)
|
||||
item.count = item.amount
|
||||
item.metadata = item.info
|
||||
return item
|
||||
end
|
||||
|
||||
return Inventory
|
Loading…
Add table
Add a link
Reference in a new issue