Merge pull request #13 from jimathy/1.0.6

1.0.6
This commit is contained in:
Jim Shield
2024-01-23 00:37:55 +00:00
committed by GitHub
6 changed files with 138 additions and 41 deletions

View File

@@ -242,10 +242,29 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
else grabInv = exports[QSInv]:getUserInventory()
end
elseif GetResourceState(OrigenInv):find("start") then
foundInv = OrigenInv
if src then
grabInv = exports[OrigenInv]:getPlayerInventory(src)
else
grabInv = exports[OrigenInv]:getPlayerInventory()
end
elseif GetResourceState(CoreInv):find("start") then
foundInv = CoreInv
if src then grabInv = exports['core_inventory']:getInventory('primary-'..src)
else grabInv = exports[CoreInv]:getInventory('primary-'..GetPlayerServerId(PlayerPedId()))
if src then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
elseif GetResourceState(ESXExport):find("start") then
local Player = ESX.GetPlayerFromId(src)
grabInv = Player.getInventory(false)
end
else
local p = promise.new()
Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end)
local result = Citizen.Await(p)
if type(result) == "string" then result = json.decode(result) end
grabInv = result
end
elseif GetResourceState(CodeMInv):find("start") then
@@ -305,16 +324,27 @@ end
function getStash(stashName)
local stashItems, items = {}, {}
if GetResourceState(OXInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7ox_inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OXInv) end
stashItems = exports[OXInv]:Inventory(stashName).items
elseif GetResourceState(QSInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QSInv) end
stashItems = exports[QSInv]:GetStashItems(stashName)
elseif GetResourceState(CoreInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CoreInv) end
stashItems = exports[CoreInv]:getInventory(stashName)
elseif GetResourceState(CodeMInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CodeMInv) end
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
elseif GetResourceState(OrigenInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OrigenInv) end
stashItems = exports[OrigenInv]:GetStash(stashName)
elseif GetResourceState(QBInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qb-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QBInv) end
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end
end
@@ -322,18 +352,18 @@ function getStash(stashName)
for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()]
if itemInfo then
items[item.slot] = {
name = itemInfo["name"],
items[#items+1] = {
name = itemInfo["name"] ~= nil and itemInfo["slot"] or nil,
amount = tonumber(item.amount) or tonumber(item.count),
info = item.info ~= nil and item.info or "",
label = itemInfo["label"],
label = itemInfo["label"] ~= nil and itemInfo["slot"] or nil,
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
weight = itemInfo["weight"] ~= nil and itemInfo["slot"] or nil,
type = itemInfo["type"] ~= nil and itemInfo["slot"] or nil,
unique = itemInfo["unique"] ~= nil and itemInfo["slot"] or nil,
useable = itemInfo["useable"] ~= nil and itemInfo["slot"] or nil,
image = itemInfo["image"] ~= nil and itemInfo["slot"] or nil,
slot = itemInfo["slot"] ~= nil and itemInfo["slot"] or nil,
}
end
end
@@ -349,23 +379,30 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end
end
elseif GetResourceState(QSInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
for k, v in pairs(items) do
for l in pairs(stashItems) do
if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
end
end
elseif GetResourceState(CoreInv):find("start") then
for k, v in pairs(items) do
exports[CoreInv]:removeItemExact(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CoreInv, k, v) end
end
elseif GetResourceState(CodeMInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
@@ -387,6 +424,13 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then
print("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
end
elseif GetResourceState(OrigenInv):find("start") then
for k, v in pairs(items) do
exports[OrigenInv]:RemoveItem(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OrigenInv, k, v) end
end
elseif GetResourceState(QBInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do