feat(additemstotrunk & clearstash)

This is very wip, also a good bit of inventories dont support it at all. I have tested this in ox_inventory but not the others. uploading into repo as it does not break anything and may encourage collab
This commit is contained in:
MrNewb committed 2025-06-04 15:25:20 -04:00
1 parent 5efcc8ba23
commit 05c80d9d10
9 files changed
+248 -43

No files matched your search

+18 -6
View File
@@ -98,12 +98,6 @@ 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)
local stash = Inventory.Stashes[id]
@@ -155,6 +149,24 @@ Inventory.CanCarryItem = function(src, item, count)
return true
end
---This will add items to a trunk, and return true or false based on success
---If a trunk with the identifier does not exist, it will create one with default values.
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
return false, print("AddItemsToTrunk is not implemented in codem-inventory, because of this we dont have a way to add items to a trunk.")
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
return false, print("ClearInventory is not implemented in codem-inventory, because of this we dont have a way to clear a stash.")
end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string
---@param newplate string
@@ -200,6 +200,24 @@ Inventory.CanCarryItem = function(src, item, count)
return true
end
---This will add items to a trunk, and return true or false based on success
---If a trunk with the identifier does not exist, it will create one with default values.
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
return false, print("AddItemsToTrunk is not implemented in core_inventory, because of this we dont have a way to add items to a trunk.")
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
return false, print("ClearInventory is not implemented in core_inventory, because of this we dont have a way to clear a stash.")
end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string
---@param newplate string
+18 -8
View File
@@ -64,12 +64,6 @@ 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)
local stash = Inventory.Stashes[id]
@@ -77,8 +71,6 @@ Inventory.OpenStash = function(src, id)
TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots })
end
---This will register a stash
---@param id number||string
---@param label string
@@ -102,6 +94,24 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
return true
end
---This will add items to a trunk, and return true or false based on success
---If a trunk with the identifier does not exist, it will create one with default values.
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
return false, print("AddItemsToTrunk is not implemented in jpr-inventory, because of this we dont have a way to add items to a trunk.")
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
return false, print("ClearInventory is not implemented in jpr-inventory, because of this we dont have a way to clear a stash.")
end
---This will return a boolean if the player has the item.
---@param src number
---@param item string
@@ -30,6 +30,49 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return origin:removeItem(src, item, count, metadata, slot, true)
end
---This will add items to a trunk, and return true or false based on success
---@param identifier string
---@param items table
---@return boolean
Inventory.AddTrunkItems = function(identifier, items)
local id = "trunk_"..identifier
if type(items) ~= "table" then return false end
Inventory.RegisterStash(id, identifier, 20, 10000, nil, nil, nil)
local repack_items = {}
for _, v in pairs(items) do
table.insert(repack_items, {
name = v.item,
amount = v.count,
metadata = v.metadata or {}
})
end
if #repack_items == 0 then return false end
origin:addItems(id, repack_items)
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
local inventory = origin:getInventory(id, _type)
if not inventory then return false end
if _type == "trunk" then
id = "trunk_"..id
elseif _type == "glovebox" then
id = "glovebox_"..id
elseif _type == "stash" then
id = "stash_"..id
end
for _, v in pairs(inventory) do
if v.slot then
origin:removeItem(id, v.name, v.count)
end
end
return true
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
+26 -9
View File
@@ -6,6 +6,7 @@ local registeredShops = {}
Inventory = Inventory or {}
Inventory.Stashes = Inventory.Stashes or {}
---This will add an item, and return true or false based on success
---@param src number
---@param item string
@@ -30,6 +31,29 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return ox_inventory:RemoveItem(src, item, count, metadata, slot)
end
---This will add items to a trunk, and return true or false based on success
---@param identifier string
---@param items table
---@return boolean
Inventory.AddTrunkItems = function(identifier, items)
local id = "trunk"..identifier
if type(items) ~= "table" then return false end
Inventory.RegisterStash(id, identifier, 20, 10000, nil, nil, nil)
for _, v in pairs(items) do
ox_inventory:AddItem(id, v.item, v.count, v.metadata)
end
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
ox_inventory:ClearInventory(_type..id, nil)
return true
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
@@ -86,13 +110,7 @@ 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
---@param id number|string
---@return nil
Inventory.OpenStash = function(src, id)
assert(Inventory.Stashes[id], "Stash not found", id)
@@ -100,7 +118,7 @@ Inventory.OpenStash = function(src, id)
end
---This will register a stash
---@param id number||string
---@param id number|string
---@param label string
---@param slots number
---@param weight number
@@ -180,7 +198,6 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
end
---UNUSED:
---This will return generic item data from the specified inventory, with the items total count.
---
+22
View File
@@ -32,6 +32,28 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return sloth:RemoveItem(src, item, count, slot, 'community_bridge')
end
---This will add items to a trunk, and return true or false based on success
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
for k, v in pairs(items) do
local count = v.count or 1
local metadata = v.metadata or {}
sloth:AddToTrunk(identifier, nil, nil, v.item, count, metadata, nil)
end
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
return false, print("ClearInventory is not implemented in ps-inventory, because of this we dont have a way to clear a stash.")
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
+56 -20
View File
@@ -23,7 +23,7 @@ end
Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return exports['qb-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge')
return qbInventory:AddItem(src, item, count, slot, metadata, 'community_bridge')
end
---This will remove an item, and return true or false based on success
@@ -36,7 +36,49 @@ end
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')
return qbInventory:RemoveItem(src, item, count, slot, 'community_bridge')
end
---This will add items to a trunk, and return true or false based on success
---If a trunk with the identifier does not exist, it will create one with default values.
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
local fullTrunkId = "trunk-"..identifier
local repacked_items = {}
for _, item in pairs(items) do
table.insert(repacked_items, {
name = item.item,
amount = item.count,
info = item.metadata or {}
})
end
if getInventoryNewVersion() then
qbInventory:addTrunkItems(fullTrunkId, repacked_items)
else
if not qbInventory:GetInventory(fullTrunkId) then
qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId, slots = 20, maxweight = 10000 })
end
qbInventory:SetInventory(fullTrunkId, repacked_items, "Community Bridge Moving Items In Trunk")
end
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
if _type == "trunk" then
id = "trunk-"..id
elseif _type == "glovebox" then
id = "glovebox-"..id
end
qbInventory:ClearStash(id)
return true
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
@@ -78,20 +120,14 @@ 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
---@param id number|string
---@return nil
Inventory.OpenStash = function(src, id)
local stash = Inventory.Stashes[id]
assert(stash, "Stash not found", id)
if getInventoryNewVersion() then
return exports['qb-inventory']:OpenInventory(src, id)
return qbInventory:OpenInventory(src, id)
end
TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots})
@@ -154,16 +190,16 @@ end
Inventory.UpdatePlate = function(oldplate, newplate)
local newVersion = getInventoryNewVersion()
if newVersion then
local gloveboxInv = exports['qb-inventory']:GetInventory('glovebox-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
local gloveboxInv = qbInventory:GetInventory('glovebox-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
local storedGloveBox = Bridge.Tables.DeepClone(gloveboxInv, nil, nil)
local trunkInv = exports['qb-inventory']:GetInventory('trunk-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
local trunkInv = qbInventory:GetInventory('trunk-'..oldplate) or {slots = 5, maxweight = 10000, items = {}}
local storedTrunk = Bridge.Tables.DeepClone(trunkInv, nil, nil)
exports['qb-inventory']:ClearStash('glovebox-'..oldplate)
exports['qb-inventory']:ClearStash('trunk-'..oldplate)
exports['qb-inventory']:CreateInventory('glovebox-'..newplate, {label = 'glovebox-'..newplate, slots = storedGloveBox.slots, maxweight = storedGloveBox.maxweight})
exports['qb-inventory']:SetInventory('glovebox-'..newplate, storedGloveBox.items, "Community Bridge Moving Items In GloveBox")
exports['qb-inventory']:CreateInventory('trunk-'..newplate, {label = 'trunk-'..newplate, slots = storedTrunk.slots, maxweight = storedTrunk.maxweight})
exports['qb-inventory']:SetInventory('trunk-'..newplate, storedTrunk.items, "Community Bridge Moving Items In Trunk")
qbInventory:ClearStash('glovebox-'..oldplate)
qbInventory:ClearStash('trunk-'..oldplate)
qbInventory:CreateInventory('glovebox-'..newplate, {label = 'glovebox-'..newplate, slots = storedGloveBox.slots, maxweight = storedGloveBox.maxweight})
qbInventory:SetInventory('glovebox-'..newplate, storedGloveBox.items, "Community Bridge Moving Items In GloveBox")
qbInventory:CreateInventory('trunk-'..newplate, {label = 'trunk-'..newplate, slots = storedTrunk.slots, maxweight = storedTrunk.maxweight})
qbInventory:SetInventory('trunk-'..newplate, storedTrunk.items, "Community Bridge Moving Items In Trunk")
return true
else
local queries = {
@@ -183,7 +219,7 @@ end
Inventory.OpenShop = function(src, shopTitle)
local newVersion = getInventoryNewVersion()
if newVersion then
return exports['qb-inventory']:OpenShop(src, shopTitle)
return qbInventory:OpenShop(src, shopTitle)
else
local shopData = v1ShopData[shopTitle]
if not shopData then return false end
@@ -206,7 +242,7 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
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, })
qbInventory:CreateShop({ name = shopTitle, label = shopTitle, coords = shopCoords, items = repackedShopItems, })
return true
else
local shopData = { label = shopTitle, items = {}, slots = 0 }
+23
View File
@@ -31,6 +31,29 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return quasar:RemoveItem(src, item, count, slot, metadata)
end
---This will add items to a trunk, and return true or false based on success
---@param identifier string
---@param items table
---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items)
if type(items) ~= "table" then return false end
for k, v in pairs(items) do
local count = v.count or 1
local metadata = v.metadata or {}
quasar:AddToTrunk(identifier, nil, nil, v.item, count, metadata, nil)
end
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
quasar:ClearOtherInventory(_type, id)
return true
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
@@ -158,10 +158,34 @@ Inventory.UpdatePlate = function(oldplate, newplate)
}
local values = { newplate = newplate, oldplate = oldplate }
MySQL.transaction.await(queries, values)
tgiann:UpdateVehicle(oldplate, newplate)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
end
---This will add items to a trunk, and return true or false based on success
---@param identifier string
---@param items table
---@return boolean
Inventory.AddTrunkItems = function(identifier, items)
local id = "trunk"..identifier
if type(items) ~= "table" then return false end
Inventory.RegisterStash(identifier, identifier, 20, 10000, nil, nil, nil)
for _, v in pairs(items) do
tgiann:AddItemToSecondaryInventory("trunk", identifier, v.item, v.count, nil, v.metadata)
end
return true
end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string
---@return boolean
Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end
tgiann:DeleteInventory(_type, id)
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