From 43e30e95bc5a2cdbc9aa6194e2fdaacbc7f7261a Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Wed, 24 Jan 2024 17:10:44 +0000 Subject: [PATCH 1/6] Tidy up and make ESX timeout longer --- crafting.lua | 4 ++-- wrapper.lua | 40 ++++++++++++++-------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/crafting.lua b/crafting.lua index 3422b30..6073624 100644 --- a/crafting.lua +++ b/crafting.lua @@ -53,7 +53,7 @@ function craftingMenu(data) end if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end if data.stashName ~= nil then disable = stashhasItem(stashItems, itemTable) else disable = hasItem(itemTable) end - setheader = Items[tostring(k)].label..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") + setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - "..tostring(k))..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") Menu[#Menu + 1] = { isMenuHeader = not disable, icon = invImg(tostring(k)), @@ -297,7 +297,7 @@ function getStash(stashName) local stashResource = "" stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv - stashItems = exports[OrigenInv]:GetStash(stashName) + stashItems = exports[OrigenInv]:GetStashItems(stashName) elseif GetResourceState(QBInv):find("start") then stashResource = QBInv local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) diff --git a/wrapper.lua b/wrapper.lua index 8b84b48..3f9ef34 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -27,8 +27,7 @@ for k, v in pairs(Exports) do end local loadItems = function() local itemResource = "" - if GetResourceState(OXInv):find("start") then - itemResource = OXInv + if GetResourceState(OXInv):find("start") then itemResource = OXInv Items = exports[OXInv]:Items() for k, v in pairs(Items) do if v.client and v.client.image then @@ -39,12 +38,10 @@ local loadItems = function() local itemResource = "" Items[k].hunger = v.client and v.client.hunger or nil Items[k].thirst = v.client and v.client.thirst or nil end - elseif GetResourceState(QBExport):find("start") then - itemResource = QBExport + elseif GetResourceState(QBExport):find("start") then itemResource = QBExport Core = Core or exports[QBExport]:GetCoreObject() Items = Core and Core.Shared.Items or nil - elseif GetResourceState(ESXExport):find("start") then - itemResource = ESXExport + elseif GetResourceState(ESXExport):find("start") then itemResource = ESXExport ESX = exports[ESXExport]:getSharedObject() Items = ESX and ESX.Items or nil end @@ -85,7 +82,7 @@ local loadVehicles = function() local vehResource = "" end end) end - local timeout = 1000 while not Vehicles and timeout > 0 do timeout -=1 Wait(0) end + local timeout = 5000 while not Vehicles and timeout > 0 do timeout -=1 Wait(0) end if not Vehicles then print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3exports^1.^2lua^7") else @@ -123,30 +120,25 @@ local loadJobs = function() local jobResource = "" elseif GetResourceState(ESXExport):find("start") then jobResource = ESXExport ESX = exports[ESXExport]:getSharedObject() - if IsDuplicityVersion() then - Jobs = ESX.GetJobs() - for k, v in pairs(Jobs) do - local count = countTable(Jobs[k].grades) - 1 - Jobs[k].grades[tostring(count)].isBoss = true - end - Gangs = Jobs - end CreateThread(function() while not ESX do Wait(0) end if IsDuplicityVersion() then - createCallback(GetCurrentResourceName()..":getJobs", function(source) - return Jobs - end) + Jobs = ESX.GetJobs() + for k, v in pairs(Jobs) do + local count = countTable(Jobs[k].grades) - 1 + Jobs[k].grades[tostring(count)].isBoss = true + end + Gangs = Jobs + createCallback(GetCurrentResourceName()..":getJobs", function(source) return Jobs end) else Jobs = triggerCallback(GetCurrentResourceName()..":getJobs") Gangs = Jobs end end) end - local timeout = 1000 while not Jobs and timeout > 0 do timeout -=1 Wait(0) end + local timeout = 5000 while not Jobs and timeout > 0 do timeout -=1 Wait(0) end if Jobs then - print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource) - print("^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) + print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, 0"^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) else print("^4ERROR^7: ^2No Job/Gang info detected ^7- ^2Check ^3exports^1.^2lua^7") end @@ -181,11 +173,7 @@ function createPoly(data) local Location = nil if Config.System.Debug then print("^6Bridge^7: ^2Creating new poly with ^7PolyZone "..data.name) end Location = PolyZone:Create(data.points, { name = data.name, debugPoly = data.debug }) Location:onPlayerInOut(function(isPointInside) - if isPointInside then - data.onEnter() - else - data.onExit() - end + if isPointInside then data.onEnter() else data.onExit() end end) else print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7") From 20509e5cc2bb35cd0809bc4a0f52cbaa674d43dc Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 24 Jan 2024 23:33:39 +0000 Subject: [PATCH 2/6] Fix Typo Update wrapper.lua - Fixed a typo on line 141 prevents this update from loading. --- wrapper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper.lua b/wrapper.lua index 3f9ef34..f252810 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -138,7 +138,7 @@ local loadJobs = function() local jobResource = "" end local timeout = 5000 while not Jobs and timeout > 0 do timeout -=1 Wait(0) end if Jobs then - print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, 0"^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) + print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, "^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) else print("^4ERROR^7: ^2No Job/Gang info detected ^7- ^2Check ^3exports^1.^2lua^7") end From c18932443aa8a312a695e6b190f17080964af8c7 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 25 Jan 2024 17:32:40 +0000 Subject: [PATCH 3/6] Testing fixing stashes --- crafting.lua | 8 ++++++-- fxmanifest.lua | 2 +- version.txt | 2 +- wrapper.lua | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crafting.lua b/crafting.lua index 6073624..b259046 100644 --- a/crafting.lua +++ b/crafting.lua @@ -303,12 +303,14 @@ function getStash(stashName) local stashResource = "" local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) if result then stashItems = json.decode(result) end end + if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource) end if stashItems then for _, item in pairs(stashItems) do local itemInfo = Items[item.name:lower()] if itemInfo then - items[#items+1] = { + local indexNum = #items+1 + items[(item.slot and item.slot) or #indexNum)] = { name = itemInfo.name or nil, amount = tonumber(item.amount) or tonumber(item.count), info = item.info or "", @@ -319,8 +321,9 @@ function getStash(stashName) local stashResource = "" unique = itemInfo.unique or nil, useable = itemInfo.useable or nil, image = itemInfo.image or nil, - slot = itemInfo.slot or nil, + slot = (item.slot and item.slot) or indexNum, } + print("TEST:", item.slot and ("slot info found: "..item.slot) or "reverting to indexnum "..indexNum) end end if Config.System.Debug then print("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7") end @@ -334,6 +337,7 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and exports[OXInv]:RemoveItem(stashName, k, v) 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 diff --git a/fxmanifest.lua b/fxmanifest.lua index 177aaaa..0eeb09f 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim_Bridge" author "Jimathy" -version "1.0.8" +version "1.0.9" description "Framework Bridge By Jimathy" fx_version "cerulean" game "gta5" diff --git a/version.txt b/version.txt index c7981f4..ab7e7da 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.8 +1.0.9 diff --git a/wrapper.lua b/wrapper.lua index f252810..a340bad 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -1248,13 +1248,13 @@ function invImg(item) if item ~= "" and Items[item] then if GetResourceState(OXInv):find("start") then imgLink = "nui://"..OXInv.."/web/images/"..(Items[item].image or "") - elseif GetResourceState(QSInv and QSInv or ""):find("start") then + elseif GetResourceState(QSInv):find("start") then imgLink = "nui://"..QSInv.."/html/images/"..(Items[item].image or "") - elseif GetResourceState(CoreInv and CoreInv or ""):find("start") then + elseif GetResourceState(CoreInv):find("start") then imgLink = "nui://"..CoreInv.."/html/img/"..(Items[item].image or "") - elseif GetResourceState(OrigenInv and OrigenInv or ""):find("start") then + elseif GetResourceState(OrigenInv):find("start") then imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "") - elseif GetResourceState(QBInv and QBInv or ""):find("start") then + elseif GetResourceState(QBInv):find("start") then imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "") else print("^4ERROR^7: ^2No Inventory detected for invImg ^7- ^2Check ^3exports^1.^2lua^7") From 1d102e94b4bec2b1e4048a13daa7ba5de49d13da Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 25 Jan 2024 18:31:00 +0000 Subject: [PATCH 4/6] Fix loading of ESX Core shared info --- wrapper.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wrapper.lua b/wrapper.lua index a340bad..51abe51 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -26,7 +26,8 @@ for k, v in pairs(Exports) do if GetResourceState(v):find("start") then print("^6Bridge^7: '^3"..v.."^7' ^2export found ^7") end end -local loadItems = function() local itemResource = "" +--local loadItems = function() + local itemResource = "" if GetResourceState(OXInv):find("start") then itemResource = OXInv Items = exports[OXInv]:Items() for k, v in pairs(Items) do @@ -43,6 +44,7 @@ local loadItems = function() local itemResource = "" Items = Core and Core.Shared.Items or nil elseif GetResourceState(ESXExport):find("start") then itemResource = ESXExport ESX = exports[ESXExport]:getSharedObject() + while not ESX do Wait(0) end Items = ESX and ESX.Items or nil end if not Items then @@ -50,9 +52,10 @@ local loadItems = function() local itemResource = "" else print("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource) end -end +--end -local loadVehicles = function() local vehResource = "" +--local loadVehicles = function() + local vehResource = "" if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then vehResource = QBExport Core = Core or exports[QBExport]:GetCoreObject() if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then @@ -67,6 +70,8 @@ local loadVehicles = function() local vehResource = "" Vehicles[k] = { model = k, price = v.price, name = v.name, brand = v.make } end elseif GetResourceState(ESXExport):find("start") then vehResource = ESXExport + ESX = exports[ESXExport]:getSharedObject() + while not ESX do Wait(0) end CreateThread(function() if IsDuplicityVersion() then createCallback(GetCurrentResourceName()..":getVehiclesPrices", function(source) @@ -88,9 +93,10 @@ local loadVehicles = function() local vehResource = "" else print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource) end -end +--end -local loadJobs = function() local jobResource = "" +--local loadJobs = function() + local jobResource = "" if GetResourceState(QBXExport):find("start") then jobResource = QBXExport Core = Core or exports[QBExport]:GetCoreObject() Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs() @@ -120,8 +126,8 @@ local loadJobs = function() local jobResource = "" elseif GetResourceState(ESXExport):find("start") then jobResource = ESXExport ESX = exports[ESXExport]:getSharedObject() + while not ESX do Wait(0) end CreateThread(function() - while not ESX do Wait(0) end if IsDuplicityVersion() then Jobs = ESX.GetJobs() for k, v in pairs(Jobs) do @@ -142,11 +148,11 @@ local loadJobs = function() local jobResource = "" else print("^4ERROR^7: ^2No Job/Gang info detected ^7- ^2Check ^3exports^1.^2lua^7") end -end +--end -loadItems() -loadVehicles() -loadJobs() +--loadItems() +--loadVehicles() +--loadJobs() function makeBossRoles(role) local boss = {} From dd356743079bb13636837ce91c06cec7dff07952 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 25 Jan 2024 18:31:34 +0000 Subject: [PATCH 5/6] i hate github --- wrapper.lua | 241 ++++++++++++++++++++++++++-------------------------- 1 file changed, 119 insertions(+), 122 deletions(-) diff --git a/wrapper.lua b/wrapper.lua index 51abe51..f7e6def 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -26,133 +26,130 @@ for k, v in pairs(Exports) do if GetResourceState(v):find("start") then print("^6Bridge^7: '^3"..v.."^7' ^2export found ^7") end end ---local loadItems = function() - local itemResource = "" - if GetResourceState(OXInv):find("start") then itemResource = OXInv - Items = exports[OXInv]:Items() - for k, v in pairs(Items) do - if v.client and v.client.image then - Items[k].image = (v.client.image):gsub("nui://"..OXInv.."/web/images/", "") - else - Items[k].image = k..".png" - end - Items[k].hunger = v.client and v.client.hunger or nil - Items[k].thirst = v.client and v.client.thirst or nil - end - elseif GetResourceState(QBExport):find("start") then itemResource = QBExport - Core = Core or exports[QBExport]:GetCoreObject() - Items = Core and Core.Shared.Items or nil - elseif GetResourceState(ESXExport):find("start") then itemResource = ESXExport - ESX = exports[ESXExport]:getSharedObject() - while not ESX do Wait(0) end - Items = ESX and ESX.Items or nil - end - if not Items then - print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7") - else - print("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource) - end ---end +local itemResource, vehResource, jobResource = "", "", "" ---local loadVehicles = function() - local vehResource = "" - if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then vehResource = QBExport - Core = Core or exports[QBExport]:GetCoreObject() - if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then - RegisterNetEvent('QBCore:Client:UpdateObject', function() - Core = Core or exports[QBExport]:GetCoreObject() +-- Load item lists +if GetResourceState(OXInv):find("start") then itemResource = OXInv + Items = exports[OXInv]:Items() + for k, v in pairs(Items) do + if v.client and v.client.image then + Items[k].image = (v.client.image):gsub("nui://"..OXInv.."/web/images/", "") + else + Items[k].image = k..".png" + end + Items[k].hunger = v.client and v.client.hunger or nil + Items[k].thirst = v.client and v.client.thirst or nil + end + +elseif GetResourceState(QBExport):find("start") then itemResource = QBExport + Core = Core or exports[QBExport]:GetCoreObject() + Items = Core and Core.Shared.Items or nil + +elseif GetResourceState(ESXExport):find("start") then itemResource = ESXExport + ESX = exports[ESXExport]:getSharedObject() + Items = ESX and ESX.Items or nil +end +if not Items then + print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7") +else + print("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource) +end + +-- Load Vehicles +if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then vehResource = QBExport + Core = Core or exports[QBExport]:GetCoreObject() + if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then + RegisterNetEvent('QBCore:Client:UpdateObject', function() + Core = Core or exports[QBExport]:GetCoreObject() + end) + end + Vehicles = Core and Core.Shared.Vehicles + print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..QBExport) +elseif GetResourceState(OXCoreExport):find("start") then + Vehicles = {} + for k, v in pairs(Ox.GetVehicleData()) do + Vehicles[k] = { model = k, price = v.price, name = v.name, brand = v.make } + end + print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..OXCoreExport) +elseif GetResourceState(ESXExport):find("start") then + print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..ESXExport) + --print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..ESXExport) + CreateThread(function() + if IsDuplicityVersion() then + createCallback(GetCurrentResourceName()..":getVehiclesPrices", function(source) + Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles') + print("^6Bridge^7: ^3Found ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..ESXExport) + return Vehicles end) end - Vehicles = Core and Core.Shared.Vehicles - elseif GetResourceState(OXCoreExport):find("start") then vehResource = OXCoreExport - Vehicles = {} - for k, v in pairs(Ox.GetVehicleData()) do - Vehicles[k] = { model = k, price = v.price, name = v.name, brand = v.make } + if not IsDuplicityVersion() then + local TempVehicles = triggerCallback(GetCurrentResourceName()..":getVehiclesPrices") + for _, v in pairs(TempVehicles) do + Vehicles = Vehicles or {} + Vehicles[v.model] = { model = v.model, price = v.price, name = v.name, brand = GetMakeNameFromVehicleModel(v.model):lower():gsub("^%l", string.upper) } + end end - elseif GetResourceState(ESXExport):find("start") then vehResource = ESXExport - ESX = exports[ESXExport]:getSharedObject() + end) +else + print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3exports^1.^2lua^7") +end + +-- Load Jobs +local jobResource = "" +if GetResourceState(QBXExport):find("start") then jobResource = QBXExport + Core = Core or exports[QBExport]:GetCoreObject() + Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs() + +elseif GetResourceState(OXCoreExport):find("start") then jobResource = OXExport + CreateThread(function() + if IsDuplicityVersion() then + createCallback(GetCurrentResourceName()..":getOxGroups", function(source) + Jobs = MySQL.query.await('SELECT * FROM `ox_groups`') return Jobs + end) + else + local TempJobs = triggerCallback(GetCurrentResourceName()..":getOxGroups") + Jobs = TempJobs and {} + for k, v in pairs(TempJobs) do + local grades = {} + for i = 1, #v.grades do grades[i] = { name = v.grades[i], isboss = (i == #v.grades)} end + Jobs[v.name] = { label = v.label, grades = grades } + end + Gangs = Jobs + end + end) + +elseif GetResourceState(QBExport):find("start") then jobResource = QBExport + Core = Core or Core or exports[QBExport]:GetCoreObject() + RegisterNetEvent('QBCore:Client:UpdateObject', function() Core = Core or exports[QBExport]:GetCoreObject() end) + Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs + +elseif GetResourceState(ESXExport):find("start") then + print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..ESXExport) + ESX = exports[ESXExport]:getSharedObject() + if IsDuplicityVersion() then + Jobs = ESX.GetJobs() + for k, v in pairs(Jobs) do + local count = countTable(Jobs[k].grades)-1 + Jobs[k].grades[tostring(count)].isBoss = true + end + Gangs = Jobs + end + CreateThread(function() while not ESX do Wait(0) end - CreateThread(function() - if IsDuplicityVersion() then - createCallback(GetCurrentResourceName()..":getVehiclesPrices", function(source) - Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles') - return Vehicles - end) - else - local TempVehicles = triggerCallback(GetCurrentResourceName()..":getVehiclesPrices") - for _, v in pairs(TempVehicles) do - Vehicles = Vehicles or {} - Vehicles[v.model] = { model = v.model, price = v.price, name = v.name, brand = GetMakeNameFromVehicleModel(v.model):lower():gsub("^%l", string.upper) } - end - end - end) - end - local timeout = 5000 while not Vehicles and timeout > 0 do timeout -=1 Wait(0) end - if not Vehicles then - print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3exports^1.^2lua^7") - else - print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource) - end ---end - ---local loadJobs = function() - local jobResource = "" - if GetResourceState(QBXExport):find("start") then jobResource = QBXExport - Core = Core or exports[QBExport]:GetCoreObject() - Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs() - - elseif GetResourceState(OXCoreExport):find("start") then jobResource = OXExport - CreateThread(function() - if IsDuplicityVersion() then - createCallback(GetCurrentResourceName()..":getOxGroups", function(source) - Jobs = MySQL.query.await('SELECT * FROM `ox_groups`') return Jobs - end) - else - local TempJobs = triggerCallback(GetCurrentResourceName()..":getOxGroups") - Jobs = TempJobs and {} - for k, v in pairs(TempJobs) do - local grades = {} - for i = 1, #v.grades do grades[i] = { name = v.grades[i], isboss = (i == #v.grades)} end - Jobs[v.name] = { label = v.label, grades = grades } - end - Gangs = Jobs - end - end) - - elseif GetResourceState(QBExport):find("start") then jobResource = QBExport - Core = Core or Core or exports[QBExport]:GetCoreObject() - RegisterNetEvent('QBCore:Client:UpdateObject', function() Core = Core or exports[QBExport]:GetCoreObject() end) - Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs - - elseif GetResourceState(ESXExport):find("start") then jobResource = ESXExport - ESX = exports[ESXExport]:getSharedObject() - while not ESX do Wait(0) end - CreateThread(function() - if IsDuplicityVersion() then - Jobs = ESX.GetJobs() - for k, v in pairs(Jobs) do - local count = countTable(Jobs[k].grades) - 1 - Jobs[k].grades[tostring(count)].isBoss = true - end - Gangs = Jobs - createCallback(GetCurrentResourceName()..":getJobs", function(source) return Jobs end) - else - Jobs = triggerCallback(GetCurrentResourceName()..":getJobs") - Gangs = Jobs - end - end) - end - local timeout = 5000 while not Jobs and timeout > 0 do timeout -=1 Wait(0) end - if Jobs then - print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, "^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) - else - print("^4ERROR^7: ^2No Job/Gang info detected ^7- ^2Check ^3exports^1.^2lua^7") - end ---end - ---loadItems() ---loadVehicles() ---loadJobs() + if IsDuplicityVersion() then + createCallback(GetCurrentResourceName()..":getJobs", function(source) + return Jobs + end) + end + if not IsDuplicityVersion() then + Jobs = triggerCallback(GetCurrentResourceName()..":getJobs") + Gangs = Jobs + end + end) +end +if not GetResourceState(ESXExport):find("start") and Jobs then + print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, "^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) +end function makeBossRoles(role) local boss = {} From 872cb3971594b947f70ac3c8b58fa74a10d07f6c Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 25 Jan 2024 18:40:42 +0000 Subject: [PATCH 6/6] Fix crafting from pockets and add debugs --- crafting.lua | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crafting.lua b/crafting.lua index b259046..11d494f 100644 --- a/crafting.lua +++ b/crafting.lua @@ -52,10 +52,11 @@ function craftingMenu(data) Wait(0) end if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end - if data.stashName ~= nil then disable = stashhasItem(stashItems, itemTable) else disable = hasItem(itemTable) end + if data.stashName then disable = not stashhasItem(stashItems, itemTable) + else disable = not hasItem(itemTable) end setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - "..tostring(k))..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") Menu[#Menu + 1] = { - isMenuHeader = not disable, + isMenuHeader = disable, icon = invImg(tostring(k)), header = setheader, txt = settext, onSelect = function() @@ -258,7 +259,8 @@ function hasItem(items, amount, src) local amount = amount and amount or 1 for _, itemData in pairs(grabInv) do if itemData and (itemData.name == item) then count += (itemData.count or itemData.amount or 1) end end - local foundMessage = "^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount + foundInv = foundInv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6") + local foundMessage = "^6Bridge^7: ^3hasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount if count >= amount then foundMessage = foundMessage.." ^5FOUND^7" else foundMessage = foundMessage .." ^1NOT FOUND^7" end if Config.System.Debug then print(foundMessage) end hasTable[item] = { hasItem = count >= amount, count = count } @@ -309,8 +311,8 @@ function getStash(stashName) local stashResource = "" for _, item in pairs(stashItems) do local itemInfo = Items[item.name:lower()] if itemInfo then - local indexNum = #items+1 - items[(item.slot and item.slot) or #indexNum)] = { + local indexNum = #items+1 -- Added to help recreate missing slot numbers + items[(item.slot and item.slot) or indexNum] = { name = itemInfo.name or nil, amount = tonumber(item.amount) or tonumber(item.count), info = item.info or "", @@ -323,7 +325,6 @@ function getStash(stashName) local stashResource = "" image = itemInfo.image or nil, slot = (item.slot and item.slot) or indexNum, } - print("TEST:", item.slot and ("slot info found: "..item.slot) or "reverting to indexnum "..indexNum) end end if Config.System.Debug then print("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7") end @@ -420,7 +421,15 @@ end RegisterNetEvent(GetCurrentResourceName()..":server:stashRemoveItem", stashRemoveItem) function stashhasItem(stashItems, items, amount) + local invs = {OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, QBInv} local foundInv = "" + for _, inv in ipairs(invs) do + if GetResourceState(inv):find("start") then + foundInv = inv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6") + break + end + end + if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end local hasTable = {} for item, amount in pairs(items) do @@ -430,13 +439,11 @@ function stashhasItem(stashItems, items, amount) count += (itemData.amount or 1) end end - if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^5FOUND '"..item.."' ^3"..count.."^7/^3"..amount.."^7") end - hasTable[item] = { hasItem = true, count = count, } - else - if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^1NOT FOUND^7 '"..item.."' ^1"..count.."^7/^3"..amount.."^7") end - hasTable[item] = { hasItem = false, count = count, } - end + + local debugMsg = string.format("^6Bridge^7: ^3stashHasItem^7[^6%s^7]: %s '%s' ^3%d^7/^3%d^7", foundInv, (count >= amount and "^5FOUND^7" or "^1NOT FOUND^7"), item, count, amount) + if Config.System.Debug then print(debugMsg) end + + hasTable[item] = { hasItem = (count >= amount), count = count } end for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end return true, hasTable