From 0bcf1b7ed490338f2001dff9b824c5d0f3a3f39e Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 14 Aug 2025 13:34:55 +0100 Subject: [PATCH] Prefer export checks over QBInvNew Small changes for JPRInv too --- shared/itemcontrol.lua | 76 +++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/shared/itemcontrol.lua b/shared/itemcontrol.lua index 4b5c18f..1dfadc0 100644 --- a/shared/itemcontrol.lua +++ b/shared/itemcontrol.lua @@ -69,6 +69,9 @@ local InvFunc = { function(data) exports[OXInv]:openInventory('shop', { type = data.shop }) end, + serverOpenShop = function(shopName) + -- + end, registerShop = function(name, label, items, society) exports[OXInv]:RegisterShop(name, { @@ -168,6 +171,9 @@ local InvFunc = { function(data) TriggerServerEvent("inventory:server:OpenInventory", "shop", data.items.label, data.items) end, + serverOpenShop = function(shopName) + -- + end, registerShop = function(name, label, items, society) -- @@ -258,6 +264,10 @@ local InvFunc = { function(data) -- end, + serverOpenShop = + function(shopName) + -- + end, registerShop = function(name, label, items, society) -- @@ -344,6 +354,10 @@ local InvFunc = { function(data) -- end, + serverOpenShop = + function(shopName) + -- + end, registerShop = function(name, label, items, society) -- @@ -442,6 +456,10 @@ local InvFunc = { function(data) TriggerEvent("codem-inventory:openshop", data.shop) end, + serverOpenShop = + function(shopName) + -- + end, registerShop = function(name, label, items, society) -- @@ -537,6 +555,10 @@ local InvFunc = { function(data) TriggerServerEvent(getScript()..':server:openServerShop', data.shop) end, + serverOpenShop = + function(shopName) + exports[TgiannInv]:OpenShop(source, shopName) + end, registerShop = function(name, label, items, society) exports[TgiannInv]:RegisterShop(name, items) @@ -666,6 +688,12 @@ local InvFunc = { TriggerServerEvent(getScript()..':server:openServerShop', data.shop) TriggerServerEvent("inventory:server:OpenInventory", "shop", data.items.label, data.items) end, + serverOpenShop = + function(shopName) + if checkExportExists(JPRInv, "OpenShop") then + exports[JPRInv]:OpenShop(source, shopName) + end + end, registerShop = function(name, label, items, society) exports[JPRInv]:CreateShop({ @@ -701,11 +729,11 @@ local InvFunc = { end, getStash = function(stashName) - local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) - if result then - return json.decode(result) + if checkExportExists(JPRInv, "GetStashItems") then + return exports[JPRInv]:GetStashItems(stashName) or {} else - return {} + local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) + return result and json.decode(result) or {} end end, stashAddItem = @@ -778,7 +806,7 @@ local InvFunc = { canCarry = function(itemTable, src) local resultTable = {} - if QBInvNew then + if checkExportExists(QBInv, "CanAddItem") then for k, v in pairs(itemTable) do resultTable[k] = exports[QBInv]:CanAddItem(src, k, v) end @@ -827,6 +855,12 @@ local InvFunc = { TriggerServerEvent(getScript()..':server:openServerShop', data.shop) TriggerServerEvent("inventory:server:OpenInventory", "shop", data.items.label, data.items) end, + serverOpenShop = + function(shopName) + if checkExportExists(QBInv, "OpenShop") then + exports[QBInv]:OpenShop(source, shopName) + end + end, registerShop = function(name, label, items, society) if checkExportExists(QBInv, "CreateShop") then @@ -859,7 +893,7 @@ local InvFunc = { end, clearStash = function(stashId) - if QBInvNew then + if checkExportExists(QBInv, "ClearStash") then exports[QBInv]:ClearStash(stashId) else MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { @@ -888,7 +922,7 @@ local InvFunc = { end, stashRemoveItem = function(stashItems, stashName, items) - if QBInvNew then + if checkExportExists(QBInv, "RemoveItem") then for k, v in pairs(items) do exports[QBInv]:RemoveItem(stashName, k, v, false, 'crafting') debugPrint("^6Bridge^7: ^2Removing ^3"..QBInv.." ^2Stash item^7:", k, v) @@ -1011,6 +1045,12 @@ local InvFunc = { TriggerServerEvent(getScript()..':server:openServerShop', data.shop) TriggerServerEvent("inventory:server:OpenInventory", "shop", data.items.label, data.items) end, + serverOpenShop = + function(shopName) + if checkExportExists(PSInv, "OpenShop") then + exports[PSInv]:OpenShop(source, shopName) + end + end, registerShop = function(name, label, items, society) if checkExportExists(PSInv, "CreateShop") then @@ -1165,6 +1205,10 @@ local InvFunc = { function(data) TriggerServerEvent(getScript()..':server:openServerShop', data.shop) end, + serverOpenShop = + function(shopName) + exports[RSGInv]:OpenShop(source, shopName) + end, registerShop = function(name, label, items, society) exports[RSGInv]:CreateShop({ @@ -2508,18 +2552,12 @@ function openShop(data) end end -RegisterNetEvent(getScript()..':server:openServerShop', function(data) - if isStarted(QBInv) and checkExportExists(QBInv, "OpenShop") then - exports[QBInv]:OpenShop(source, data) - end - if isStarted(PSInv) and checkExportExists(PSInv, "OpenShop") then - exports[PSInv]:OpenShop(source, data) - end - if isStarted(TgiannInv) then - exports[TgiannInv]:OpenShop(source, data) - end - if isStarted(RSGInv) then - exports[RSGInv]:OpenShop(source, data) +RegisterNetEvent(getScript()..':server:openServerShop', function(shopName) + for _, inv in ipairs(InvFunc) do + if isStarted(inv.invName) then + inv.serverOpenShop(shopName) + break + end end end)