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