HasItem + partial support for shops
This commit is contained in:
1 parent
f28e511de6
commit
dee14600ba
14 files changed
+220
-7
No files matched your search
@@ -60,6 +60,15 @@ Framework.GetItemCount = function(src, item, _)
|
|||||||
return xPlayer.getInventoryItem(item).count
|
return xPlayer.getInventoryItem(item).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Framework.HasItem = function(src, item)
|
||||||
|
local getCount = Framework.GetItemCount(src, item, nil)
|
||||||
|
return getCount > 0
|
||||||
|
end
|
||||||
|
|
||||||
-- Framework.GetPlayerInventory(src)
|
-- Framework.GetPlayerInventory(src)
|
||||||
-- Returns the entire inventory of the player as a table.
|
-- Returns the entire inventory of the player as a table.
|
||||||
-- returns {name = v.name, count = v.amount, _, _}
|
-- returns {name = v.name, count = v.amount, _, _}
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ Framework.GetItemCount = function(src, item, metadata)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Framework.HasItem = function(src, item)
|
||||||
|
local getCount = Framework.GetItemCount(src, item, nil)
|
||||||
|
return getCount > 0
|
||||||
|
end
|
||||||
|
|
||||||
-- Framework.GetPlayerInventory(src)
|
-- Framework.GetPlayerInventory(src)
|
||||||
-- Returns the entire inventory of the player as a table.
|
-- Returns the entire inventory of the player as a table.
|
||||||
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||||
|
|||||||
@@ -70,6 +70,15 @@ Framework.GetItemCount = function(src, item, metadata)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Framework.HasItem = function(src, item)
|
||||||
|
local getCount = Framework.GetItemCount(src, item, nil)
|
||||||
|
return getCount > 0
|
||||||
|
end
|
||||||
|
|
||||||
-- Framework.GetPlayerInventory(src)
|
-- Framework.GetPlayerInventory(src)
|
||||||
-- Returns the entire inventory of the player as a table.
|
-- Returns the entire inventory of the player as a table.
|
||||||
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||||
|
|||||||
@@ -60,6 +60,14 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
|
|||||||
return codem:SetItemMetadata(src, slot, metadata)
|
return codem:SetItemMetadata(src, slot, metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Inventory.HasItem = function(src, item)
|
||||||
|
return codem:HasItem(src, item, 1)
|
||||||
|
end
|
||||||
|
|
||||||
Inventory.GetItemBySlot = function(src, slot)
|
Inventory.GetItemBySlot = function(src, slot)
|
||||||
local slotData = codem:GetItemBySlot(src, slot)
|
local slotData = codem:GetItemBySlot(src, slot)
|
||||||
if not slotData then return {} end
|
if not slotData then return {} end
|
||||||
@@ -81,4 +89,5 @@ Inventory.GetImagePath = function(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))
|
||||||
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
|
||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -17,6 +17,14 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Inventory.HasItem = function(src, item)
|
||||||
|
return jpr:HasItem(src, item, 1)
|
||||||
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param id string||number
|
---@param id string||number
|
||||||
@@ -64,4 +72,27 @@ Inventory.UpdatePlate = function(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)
|
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local registeredShops = {}
|
||||||
|
|
||||||
|
Inventory.OpenShop = function(src, shopTitle)
|
||||||
|
return jpr:OpenShop(src, shopTitle)
|
||||||
|
end
|
||||||
|
|
||||||
|
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
|
||||||
|
if not shopTitle or not shopInventory or not shopCoords then return end
|
||||||
|
if registeredShops[shopTitle] then return true end
|
||||||
|
|
||||||
|
local repackItems = {}
|
||||||
|
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
|
||||||
|
for k, v in pairs(shopInventory) do
|
||||||
|
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
|
||||||
|
end
|
||||||
|
|
||||||
|
jpr:CreateShop(repackedShopItems)
|
||||||
|
registeredShops[shopTitle] = true
|
||||||
|
--Inventory.OpenShop(src, shopTitle)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
@@ -14,6 +14,15 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
|
|||||||
return origen_inventory:removeItem(src, item, count, metadata, slot, true)
|
return origen_inventory:removeItem(src, item, count, metadata, slot, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Inventory.HasItem = function(src, item)
|
||||||
|
local count = origen_inventory:getItemCount(src , item)
|
||||||
|
return count > 0
|
||||||
|
end
|
||||||
|
|
||||||
Inventory.GetItemInfo = function(item)
|
Inventory.GetItemInfo = function(item)
|
||||||
local itemData = origen_inventory:Items(item)
|
local itemData = origen_inventory:Items(item)
|
||||||
local repackedTable = {
|
local repackedTable = {
|
||||||
|
|||||||
@@ -44,4 +44,8 @@ Inventory.GetPlayerInventory = function()
|
|||||||
return exports.ox_inventory:GetPlayerItems()
|
return exports.ox_inventory:GetPlayerItems()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Inventory.OpenShop = function(shopTitle, shopInventory)
|
||||||
|
ox_inventory:openInventory("shop", { type = shopTitle, id = 1 })
|
||||||
|
end
|
||||||
|
|
||||||
--Bridge.RegisterModule("Inventory", Inventory)
|
--Bridge.RegisterModule("Inventory", Inventory)
|
||||||
@@ -54,6 +54,15 @@ 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
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param src number
|
---@param src number
|
||||||
---@return table
|
---@return table
|
||||||
@@ -142,4 +151,18 @@ Inventory.GetImagePath = function(item)
|
|||||||
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
|
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
|
||||||
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
|
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
|
||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
|
end
|
||||||
|
|
||||||
|
local registeredShops = {}
|
||||||
|
|
||||||
|
Inventory.OpenShop = function(src, shopTitle)
|
||||||
|
TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle})
|
||||||
|
end
|
||||||
|
|
||||||
|
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||||
|
if registeredShops[shopTitle] then return true end
|
||||||
|
registeredShops[shopTitle] = true
|
||||||
|
ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, })
|
||||||
|
--return Inventory.OpenShop(src, shopTitle)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
@@ -41,6 +41,14 @@ Inventory.GetImagePath = function(item)
|
|||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Inventory.HasItem = function(src, item)
|
||||||
|
return sloth:HasItem(src, item, 1)
|
||||||
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param slot number
|
---@param slot number
|
||||||
@@ -61,7 +69,7 @@ end
|
|||||||
Inventory.AddItem = function(src, item, amount, slot, metadata)
|
Inventory.AddItem = function(src, item, amount, slot, metadata)
|
||||||
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
|
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
|
||||||
return exports['ps-inventory']:AddItem(src, item, amount, slot, metadata, 'community_bridge')
|
return sloth:AddItem(src, item, amount, slot, metadata, 'community_bridge')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -75,7 +83,7 @@ end
|
|||||||
Inventory.RemoveItem = function(src, item, amount, slot, metadata)
|
Inventory.RemoveItem = function(src, item, amount, slot, metadata)
|
||||||
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove')
|
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove')
|
||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
|
||||||
return exports['ps-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge')
|
return sloth:RemoveItem(src, item, amount, slot, 'community_bridge')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -93,4 +101,26 @@ Inventory.UpdatePlate = function(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)
|
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local registeredShops = {}
|
||||||
|
|
||||||
|
Inventory.OpenShop = function(src, shopTitle)
|
||||||
|
return sloth:OpenShop(src, shopTitle)
|
||||||
|
end
|
||||||
|
|
||||||
|
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
|
||||||
|
if not shopTitle or not shopInventory or not shopCoords then return end
|
||||||
|
if registeredShops[shopTitle] then return true end
|
||||||
|
|
||||||
|
local repackItems = {}
|
||||||
|
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
|
||||||
|
for k, v in pairs(shopInventory) do
|
||||||
|
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
|
||||||
|
end
|
||||||
|
|
||||||
|
sloth:CreateShop(repackedShopItems)
|
||||||
|
registeredShops[shopTitle] = true
|
||||||
|
--Inventory.OpenShop(src, shopTitle)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
@@ -10,14 +10,14 @@ RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id,
|
|||||||
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---comment
|
---This will return a boolean if the player has the item in their inventory
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
Inventory.HasItem = function(item)
|
Inventory.HasItem = function(item)
|
||||||
return qb:HasItem(item)
|
return qb:HasItem(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---This will return a string of the image path for the item
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return string
|
---@return string
|
||||||
Inventory.GetImagePath = function(item)
|
Inventory.GetImagePath = function(item)
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ Inventory.GetImagePath = function(item)
|
|||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param src number
|
||||||
|
---@param item string
|
||||||
|
---@return boolean
|
||||||
|
Inventory.HasItem = function(src, item)
|
||||||
|
return qbInventory:HasItem(src, item, 1)
|
||||||
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param src number
|
---@param src number
|
||||||
@@ -112,3 +119,36 @@ Inventory.RemoveItem = function(src, item, amount, slot, metadata)
|
|||||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
|
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')
|
return exports['qb-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local registeredShops = {}
|
||||||
|
|
||||||
|
Inventory.OpenShop = function(src, shopTitle)
|
||||||
|
return exports['qb-inventory']:OpenShop(src, shopTitle)
|
||||||
|
end
|
||||||
|
|
||||||
|
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
|
||||||
|
if not shopTitle or not shopInventory or not shopCoords then return end
|
||||||
|
local newVersion = getInventoryNewVersion()
|
||||||
|
if newVersion then
|
||||||
|
if registeredShops[shopTitle] then return true end
|
||||||
|
registeredShops[shopTitle] = true
|
||||||
|
local repackedShopItems = {}
|
||||||
|
for _, v in pairs(shopInventory) do
|
||||||
|
table.insert(repackedShopItems, {name = v.name, price = v.price, amount = v.count or 1000})
|
||||||
|
end
|
||||||
|
exports['qb-inventory']:CreateShop({ name = shopTitle, label = shopTitle, coords = shopCoords, items = repackedShopItems, })
|
||||||
|
--exports['qb-inventory']:OpenShop(src, shopTitle)
|
||||||
|
--return Inventory.OpenShop(src, shopTitle)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
local shopData = { label = shopTitle, items = {}, slots = 0 }
|
||||||
|
|
||||||
|
for _, v in pairs(shopInventory) do
|
||||||
|
table.insert(shopData.items, { name = v.name, price = v.price, amount = v.count or 1000, info = {}, type = 'item' })
|
||||||
|
end
|
||||||
|
|
||||||
|
shopData.slots = #shopData.items
|
||||||
|
TriggerClientEvent("inventory:client:OpenInventory", src, "shop", shopTitle, shopData)
|
||||||
|
print("QB-INVENTORY: You are using an outdated version of qb-inventory, please update to the latest version. Stuff will still work but you are using litterally the most exploitable inventory in fivem.")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,6 +4,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
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -16,6 +17,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
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -27,6 +29,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
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param metadata table
|
---@param metadata table
|
||||||
@@ -35,6 +38,7 @@ Inventory.GetItemCount = function(src, item, metadata)
|
|||||||
return quasar:GetItemTotalAmount(src, item)
|
return quasar:GetItemTotalAmount(src, item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This will return the player inventory in a table following ox_inventory format
|
||||||
---@param src number
|
---@param src number
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.GetPlayerInventory = function(src)
|
Inventory.GetPlayerInventory = function(src)
|
||||||
@@ -51,6 +55,17 @@ Inventory.GetPlayerInventory = function(src)
|
|||||||
return repackedTable
|
return repackedTable
|
||||||
end
|
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 src number
|
||||||
---@param slot number
|
---@param slot number
|
||||||
---@return table | nil
|
---@return table | nil
|
||||||
@@ -73,6 +88,7 @@ Inventory.GetItemBySlot = function(src, slot)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This will return a boolean if the player can carry the item
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -107,6 +123,7 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo
|
|||||||
TriggerClientEvent("inventory:client:SetCurrentStash",src, id)
|
TriggerClientEvent("inventory:client:SetCurrentStash",src, id)
|
||||||
end
|
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)
|
||||||
@@ -123,6 +140,7 @@ Inventory.GetItemInfo = function(item)
|
|||||||
return repackedTable
|
return repackedTable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param slot number
|
---@param slot number
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ Inventory.GetItemInfo = function(item)
|
|||||||
return repackedTable
|
return repackedTable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This will return a boolean if the player has the item in the inventory
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
Inventory.HasItem = function(item)
|
Inventory.HasItem = function(item)
|
||||||
return tgiann:HasItem(item)
|
return tgiann:HasItem(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- This will return the image path, it is incredibley useful for menus etc
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return string
|
---@return string
|
||||||
Inventory.GetImagePath = function(item)
|
Inventory.GetImagePath = function(item)
|
||||||
@@ -40,6 +42,7 @@ Inventory.GetImagePath = function(item)
|
|||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This will return the player inventory in a table
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.GetPlayerInventory = function()
|
Inventory.GetPlayerInventory = function()
|
||||||
local items = {}
|
local items = {}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ local tgiann = exports["tgiann-inventory"]
|
|||||||
|
|
||||||
Inventory = Inventory or {}
|
Inventory = Inventory or {}
|
||||||
|
|
||||||
|
---This Will add the item if found and return boolean on success
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -16,6 +17,7 @@ Inventory.AddItem = function(src, item, count, slot, 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
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -27,6 +29,7 @@ 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
|
||||||
|
|
||||||
|
--
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param metadata table
|
---@param metadata table
|
||||||
@@ -38,6 +41,15 @@ Inventory.GetItem = function(src, item, metadata)
|
|||||||
return item
|
return item
|
||||||
end
|
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 src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param metadata optional table
|
---@param metadata optional table
|
||||||
@@ -47,6 +59,7 @@ Inventory.GetItemCount = function(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
|
||||||
---@param src number
|
---@param src number
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.GetPlayerInventory = function(src)
|
Inventory.GetPlayerInventory = function(src)
|
||||||
@@ -60,7 +73,7 @@ Inventory.GetPlayerInventory = function(src)
|
|||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---This will return a boolean if the player can carry the item
|
||||||
---@param src number
|
---@param src number
|
||||||
---@param item string
|
---@param item string
|
||||||
---@param count number
|
---@param count number
|
||||||
@@ -68,6 +81,7 @@ end
|
|||||||
Inventory.CanCarryItem = function(src, item, count)
|
Inventory.CanCarryItem = function(src, item, count)
|
||||||
return tgiann:CanCarryItem(src, item, count)
|
return tgiann:CanCarryItem(src, item, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param id string or number
|
---@param id string or number
|
||||||
---@param label string
|
---@param label string
|
||||||
@@ -79,7 +93,7 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner)
|
|||||||
return tgiann:CreateCustomStashWithItem(id, {})
|
return tgiann:CreateCustomStashWithItem(id, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---comment
|
---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
|
||||||
@@ -89,6 +103,7 @@ Inventory.GetItemBySlot = function(src, slot)
|
|||||||
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}
|
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
|
||||||
|
|
||||||
|
---This will return a table of the item data including the image (very useful for menus etc)
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return table
|
---@return table
|
||||||
Inventory.GetItemInfo = function(item)
|
Inventory.GetItemInfo = function(item)
|
||||||
@@ -105,6 +120,8 @@ Inventory.GetItemInfo = function(item)
|
|||||||
return repackedTable
|
return repackedTable
|
||||||
end
|
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
|
||||||
@@ -114,6 +131,7 @@ 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
|
||||||
---@param item string
|
---@param item string
|
||||||
---@return string
|
---@return string
|
||||||
Inventory.GetImagePath = function(item)
|
Inventory.GetImagePath = function(item)
|
||||||
@@ -123,6 +141,7 @@ Inventory.GetImagePath = function(item)
|
|||||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---This will update the plate to a vehicle in the inventory
|
||||||
---@param oldplate string
|
---@param oldplate string
|
||||||
---@param newplate string
|
---@param newplate string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
|
|||||||
Reference in new issue
Block a user