diff --git a/crafting.lua b/crafting.lua index 3422b30..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 - setheader = Items[tostring(k)].label..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") + 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 } @@ -297,18 +299,20 @@ 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 }) 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 -- 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 "", @@ -319,7 +323,7 @@ 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, } end end @@ -334,6 +338,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 @@ -416,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 @@ -426,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 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 8b84b48..f7e6def 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -26,135 +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 +local itemResource, vehResource, jobResource = "", "", "" + +-- 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 - 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) + 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 -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 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 } - end - elseif GetResourceState(ESXExport):find("start") then vehResource = ESXExport - 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 + 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) - end - local timeout = 1000 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 + end) +else + print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3exports^1.^2lua^7") 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() +-- 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 jobResource = ESXExport - ESX = exports[ESXExport]:getSharedObject() +elseif GetResourceState(OXCoreExport):find("start") then jobResource = OXExport + 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 + 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 - CreateThread(function() - while not ESX do Wait(0) end - if IsDuplicityVersion() then - 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 - 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) - else - print("^4ERROR^7: ^2No Job/Gang info detected ^7- ^2Check ^3exports^1.^2lua^7") - end -end + end) -loadItems() -loadVehicles() -loadJobs() +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 + 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 = {} @@ -181,11 +176,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") @@ -1260,13 +1251,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")