From 02c202d075320cec60ef762627f7878b80eeb14f Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 12:53:45 +0000 Subject: [PATCH 01/12] Version Bump - v1.0.3 --- fxmanifest.lua | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 6462f7c..7091819 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim_Bridge" author "Jimathy" -version "1.0.2" +version "1.0.3" description "Framework Bridge By Jimathy" fx_version "cerulean" game "gta5" diff --git a/version.txt b/version.txt index 6d7de6e..21e8796 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.2 +1.0.3 From e5316f45aaea7b8557f40a9772d6a128add230e1 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 13:00:50 +0000 Subject: [PATCH 02/12] Rewrite + Optimize hasItem() & stashhasItem() --- crafting.lua | 221 +++++++++++++++++---------------------------------- 1 file changed, 71 insertions(+), 150 deletions(-) diff --git a/crafting.lua b/crafting.lua index 5ccc6c9..a80c809 100644 --- a/crafting.lua +++ b/crafting.lua @@ -225,149 +225,66 @@ function openShop(data) end -- Client & Server side -function hasItem(items, amount, src) local amount, count = amount and amount or 1, 0 - if src then - if GetResourceState(OXInv):find("start") then - local item = exports[OXInv]:GetItem(src, items) - local amount = (amount or 1) - if item.count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..item.count.."^7/^3"..amount.." "..tostring(items)) end - return true - else if Config.System.Debug then - print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - elseif GetResourceState(QSInv):find("start") then - for _, itemData in pairs(exports[QSInv]:GetInventory(src)) do - if itemData and (itemData.name == items) then - --if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) - end - end - if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end - return true - else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - elseif GetResourceState(CoreInv):find("start") then - local item = exports[CoreInv]:getItems('primary-'..src, items) - - if item.amount >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..item.amount.."^7/^3"..amount.." "..tostring(items)) end - return true - else if Config.System.Debug then - print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - elseif GetResourceState(CodeMInv):find("start") then - local success = exports["codem-inventory"]:CheckItemValid(src, items, amount) - if success then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..amount.." "..tostring(items)) end - return true - end - - elseif GetResourceState(CodeMInv):find("start") then - for _, itemData in pairs(exports[CodeMInv]:GetUserInventory(src)) do - if itemData and (itemData.name == items) then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) - end - end - if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end - return true - else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - else - for _, itemData in pairs(Core.Functions.GetPlayer(src).PlayerData.items) do - if itemData and (itemData.name == items) then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) - end - end - if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end - return true - else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end +function hasItem(items, amount, src) local amount = amount and amount or 1 + local grabInv = nil + local foundInv = "" + if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end + if GetResourceState(OXInv):find("start") then + foundInv = OXInv + if src then grabInv = exports.ox_inventory:GetInventoryItems(src) + else grabInv = exports[OXInv]:GetPlayerItems() end + + elseif GetResourceState(QSInv):find("start") then + foundInv = QSInv + if src then grabInv = exports[QSInv]:GetInventory(src) + else grabInv = exports[QSInv]:getUserInventory() + 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())) + end + + elseif GetResourceState(CodeMInv):find("start") then + foundInv = CodeMInv + if src then grabInv = exports[CodeMInv]:GetUserInventory(src) + else grabInv = exports[CodeMInv]:GetClientPlayerInventory() + end + + elseif GetResourceState(QBInv):find("start") then + foundInv = QBInv + if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items + else grabInv = Core.Functions.GetPlayerData().items + end + else - if GetResourceState(OXInv):find("start") then - local count = tonumber(exports[OXInv]:Search('count', items)) - local amount = (amount or 1) - if count >= amount then if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end return true - else if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end return false end + print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") + end - elseif GetResourceState(QSInv):find("start") then - for _, itemData in pairs(exports[QSInv]:getUserInventory()) do - if itemData and (itemData.name == items) then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) + if grabInv then + local hasTable = {} + for item, amount in pairs(items) do + local count = 0 + for _, itemData in pairs(grabInv) do + if itemData and (itemData.name == item) then + --if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(item).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.count or itemData.amount).."^7)", foundInv) end + count += ((itemData.count or itemData.amount) or 1) end end if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end - return true + if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(item).."^7", foundInv) end + hasTable[item] = { hasItem = true, count = count, } else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - elseif GetResourceState(CoreInv):find("start") then - for _, itemData in pairs(exports[CoreInv]:getInventory('primary-'..GetPlayerServerId(PlayerPedId()))) do - if itemData and (itemData.name == items) then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) + if Config.System.Debug then + print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(item).." ^1NOT FOUND^7", foundInv) end + hasTable[item] = { hasItem = false, count = count, } end - if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) end - return true - else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") end - return false - end - - elseif GetResourceState(CodeMInv):find("start") then - local success = exports[CodeMInv]:CheckItemValid(items, amount) - if success then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..amount.." "..tostring(items)) end - return true - end - - elseif GetResourceState(QBInv):find("start") then - --if tonumber(GetResourceMetadata(QBInv, 'version')) <= 1.2 then - -- return exports[QBInv]:HasItem(items, amount) - --else - for _, itemData in pairs(Core.Functions.GetPlayerData().items) do - if itemData and (itemData.name == items) then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(items).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") end - count += (itemData.amount or 1) - end - end - if count >= amount then - if Config.System.Debug then - print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(items)) - end - return true - else - if Config.System.Debug then - print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(items).." ^1NOT FOUND^7") - end - return false - end - -- end end + for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end + return true, hasTable end end @@ -485,22 +402,26 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and end RegisterNetEvent(GetCurrentResourceName()..":server:stashRemoveItem", stashRemoveItem) -function stashhasItem(stashItems, item, amount) local amount, count = amount and amount or 1, 0 - for k, itemData in pairs(stashItems) do - if itemData and (itemData.name == item) then - --if Config.System.Debug then - -- print("^6Bridge^7: ^3stashHasItem^7: ^2Item^7: '^3"..tostring(item).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.amount).."^7)") - --end - count += (itemData.amount or 1) - end - end - if count >= amount then - if Config.System.Debug then - print("^6Bridge^7: ^3stashHasItem^7: ^2Items ^3"..item.." ^5FOUND^7 x^3"..count.."^7/^3"..amount.."^7") end - return - true - else - if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^2Items ^1NOT FOUND^7 "..json.encode(item)) end - return false +function stashhasItem(stashItems, items, amount) + local foundInv = "" + if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end + + local hasTable = {} + for item, amount in pairs(items) do + local count = 0 + for _, itemData in pairs(stashItems) do + if itemData and (itemData.name == k) then + count += (itemData.amount or 1) + end + end + if count >= amount then + if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^2Items ^3"..item.." ^5FOUND^7 x^3"..count.."^7/^3"..amount.."^7") end + hasTable[item] = { hasItem = true, count = count, } + else + if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^2Items ^1NOT FOUND^7 "..json.encode(item)) end + hasTable[item] = { hasItem = false, count = count, } + end end + for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end + return true, hasTable end \ No newline at end of file From dcf2018ec68d7325a996ffe53c02df4948d060ab Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 13:02:09 +0000 Subject: [PATCH 03/12] check for destroyProp if received any info --- functions.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/functions.lua b/functions.lua index 4efdb22..de5a59f 100644 --- a/functions.lua +++ b/functions.lua @@ -154,12 +154,14 @@ function lookEnt(entity) local ped = PlayerPedId() end function destroyProp(entity) - if Config.System.Debug then print("^6Bridge^7: ^2Destroying Prop^7: '^6"..entity.."^7'") end - if IsEntityAttachedToEntity(entity, PlayerPedId()) then - SetEntityAsMissionEntity(entity) - DetachEntity(entity, true, true) + if entity then + if Config.System.Debug then print("^6Bridge^7: ^2Destroying Prop^7: '^6"..entity.."^7'") end + if IsEntityAttachedToEntity(entity, PlayerPedId()) then + SetEntityAsMissionEntity(entity) + DetachEntity(entity, true, true) + end + DeleteObject(entity) end - DeleteObject(entity) end function pushVehicle(entity) From 725125a274cf2519eaf2c2c0d04178e79a1b378c Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 14:46:09 +0000 Subject: [PATCH 04/12] add debug prints to new ox setVehicleProperties call --- wrapper.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wrapper.lua b/wrapper.lua index ac3bd7e..8a5bc92 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -939,6 +939,7 @@ function setVehicleProperties(vehicle, props) if GetResourceState(OXLibExport):find("start") then TriggerServerEvent(GetCurrentResourceName()..":ox:setVehicleProperties", VehToNet(vehicle), props) elseif GetResourceState(QBExport):find("start") then + if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7'^3"..vehicle.."'^7 - '^3"..GetEntityModel(vehicle).."^7' - '^3"..props.plate.."^7") end Core.Functions.SetVehicleProperties(vehicle, props) end end @@ -953,6 +954,7 @@ AddStateBagChangeHandler(GetCurrentResourceName()..':setVehicleProperties', '', if not value or not GetEntityFromStateBagName then return end local entity = GetEntityFromStateBagName(bagName) local networked = not bagName:find('localEntity') + if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^3"..entity.."]^7 - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") end if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end From e2bb32d9de6555dbd981be5221714ab0e19c89ae Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 14:46:45 +0000 Subject: [PATCH 05/12] Optimize Crafting/Multicraft Menu + better hasItem prints --- crafting.lua | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/crafting.lua b/crafting.lua index a80c809..f468246 100644 --- a/crafting.lua +++ b/crafting.lua @@ -48,21 +48,17 @@ function craftingMenu(data) local hasjob = false end local setheader, settext = "", "" local disable = false - local checktable = {} if Recipes[i].job and hasjob == false then else + local itemTable = {} for l, b in pairs(Recipes[i][tostring(k)]) do - if not Items[l] then print("^3Error^7: ^2Script can't find ingredient item in Shared Items - ^1"..l.."^7") return end - settext = settext..(settext ~= "" and br or "")..Items[l].label..(b > 1 and " x"..b or "") - if data.stashName then checktable[l] = stashhasItem(stashItems, l, b) - else checktable[l] = hasItem(l, b) end + settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "") + itemTable[l] = b Wait(0) end - for _, v in pairs(checktable) do - if not v then - disable = true - break - end - 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 then disable = not stashhasItem(stashItems, itemTable) + else disable = not hasItem(itemTable) end + setheader = Items[tostring(k)].label..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") Menu[#Menu + 1] = { isMenuHeader = disable, @@ -97,17 +93,20 @@ function multiCraft(data) local Menu = {} } for k in pairsByKeys(success) do local settext = "" + local itemTable = {} for l, b in pairs(data.craft[data.item]) do - if data.stashName then - success[k] = stashhasItem(stashItems, l, (b * k)) - else - success[k] = hasItem(l, (b * k)) - end + itemTable[l] = (b * k) settext = settext..(settext ~= "" and br or "")..Items[l].label..(b*k > 1 and "- x"..b*k or "") Wait(0) end + local disable = false + if Config.System.Debug then print("^6Bridge^7: ^2Checking "..(data.stashName and "^7'^6"..data.stashName.."^7'" or "inventory").."^7x^5"..k.." ^2ingredients^7 - ^6"..data.item.."^7") end + if data.stashName then disable = not stashhasItem(stashItems, itemTable) + else disable = not hasItem(itemTable) end + Menu[#Menu + 1] = { - isMenuHeader = not success[k], + isMenuHeader = disable, + arrow = not disable, header = "Craft - x"..k * data.craft.amount, txt = settext, onSelect = function () @@ -266,6 +265,7 @@ function hasItem(items, amount, src) local amount = amount and amount or 1 if grabInv then local hasTable = {} for item, amount in pairs(items) do + if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end local count = 0 for _, itemData in pairs(grabInv) do if itemData and (itemData.name == item) then @@ -274,12 +274,10 @@ function hasItem(items, amount, src) local amount = amount and amount or 1 end end if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^5FOUND^7 ^3"..count.."^7/^3"..amount.." "..tostring(item).."^7", foundInv) end + if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^7[^6"..foundInv.."^7] ^5FOUND^7 '"..tostring(item).."' ^3"..count.."^7/^3"..amount.."^7") end hasTable[item] = { hasItem = true, count = count, } else - if Config.System.Debug then - print("^6Bridge^7: ^3HasItem^7: ^2"..tostring(item).." ^1NOT FOUND^7", foundInv) - end + if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^7[^6"..foundInv.."^7] ^1NOT FOUND^7 '"..tostring(item).."' ^1"..count.."^7/^3"..amount.."^7") end hasTable[item] = { hasItem = false, count = count, } end end @@ -415,10 +413,10 @@ function stashhasItem(stashItems, items, amount) end end if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^2Items ^3"..item.." ^5FOUND^7 x^3"..count.."^7/^3"..amount.."^7") end + 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: ^2Items ^1NOT FOUND^7 "..json.encode(item)) end + 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 end From 4cc001d2f075ca46591aec23ab613993d6b9aa90 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 18:10:05 +0000 Subject: [PATCH 06/12] fix typo in stashhasitem --- crafting.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crafting.lua b/crafting.lua index f468246..c4cfa6c 100644 --- a/crafting.lua +++ b/crafting.lua @@ -403,12 +403,11 @@ RegisterNetEvent(GetCurrentResourceName()..":server:stashRemoveItem", stashRemov function stashhasItem(stashItems, items, amount) local foundInv = "" if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end - local hasTable = {} for item, amount in pairs(items) do local count = 0 for _, itemData in pairs(stashItems) do - if itemData and (itemData.name == k) then + if itemData and (itemData.name == item) then count += (itemData.amount or 1) end end From df60f3b2b1b1459a8d3f674eaf9328887539af55 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 18:13:22 +0000 Subject: [PATCH 07/12] tidy prints for setVehicleProperties --- wrapper.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrapper.lua b/wrapper.lua index 8a5bc92..730aa74 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -939,7 +939,7 @@ function setVehicleProperties(vehicle, props) if GetResourceState(OXLibExport):find("start") then TriggerServerEvent(GetCurrentResourceName()..":ox:setVehicleProperties", VehToNet(vehicle), props) elseif GetResourceState(QBExport):find("start") then - if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7'^3"..vehicle.."'^7 - '^3"..GetEntityModel(vehicle).."^7' - '^3"..props.plate.."^7") end + if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7] - [^3"..props.plate.."^7]") end Core.Functions.SetVehicleProperties(vehicle, props) end end @@ -954,7 +954,7 @@ AddStateBagChangeHandler(GetCurrentResourceName()..':setVehicleProperties', '', if not value or not GetEntityFromStateBagName then return end local entity = GetEntityFromStateBagName(bagName) local networked = not bagName:find('localEntity') - if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^3"..entity.."]^7 - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") end + if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..entity.."]^7 - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") end if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end From ef2ba3ea7a1a92117823477f0a161facd4944223 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 20:24:25 +0000 Subject: [PATCH 08/12] tidy up new prints more --- crafting.lua | 4 ++-- functions.lua | 2 +- wrapper.lua | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crafting.lua b/crafting.lua index c4cfa6c..4e20ef1 100644 --- a/crafting.lua +++ b/crafting.lua @@ -274,10 +274,10 @@ function hasItem(items, amount, src) local amount = amount and amount or 1 end end if count >= amount then - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^7[^6"..foundInv.."^7] ^5FOUND^7 '"..tostring(item).."' ^3"..count.."^7/^3"..amount.."^7") end + if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount.." ^5FOUND^7") end hasTable[item] = { hasItem = true, count = count, } else - if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^7[^6"..foundInv.."^7] ^1NOT FOUND^7 '"..tostring(item).."' ^1"..count.."^7/^3"..amount.."^7") end + if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^1"..count.."^7/^3"..amount.." ^1NOT FOUND^7") end hasTable[item] = { hasItem = false, count = count, } end end diff --git a/functions.lua b/functions.lua index de5a59f..7ef5b38 100644 --- a/functions.lua +++ b/functions.lua @@ -11,7 +11,7 @@ end local time = 100 function loadModel(model) if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end - while not HasModelLoaded(model) do if time > 0 then time = time - 1 RequestModel(model) + while not HasModelLoaded(model) do if time > 0 then time -= 1 RequestModel(model) else time = 1000 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") break end Wait(10) end end diff --git a/wrapper.lua b/wrapper.lua index 730aa74..ca68ffa 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -954,7 +954,7 @@ AddStateBagChangeHandler(GetCurrentResourceName()..':setVehicleProperties', '', if not value or not GetEntityFromStateBagName then return end local entity = GetEntityFromStateBagName(bagName) local networked = not bagName:find('localEntity') - if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..entity.."]^7 - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") end + if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..entity.."^7] - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") end if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end From 23091c2e739ba34730a5791539baa7a526079a77 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 20:25:04 +0000 Subject: [PATCH 09/12] add spam free ensureNetToVeh() --- functions.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/functions.lua b/functions.lua index 7ef5b38..a9ba79d 100644 --- a/functions.lua +++ b/functions.lua @@ -190,6 +190,28 @@ function pushVehicle(entity) end end +function ensureNetToVeh(vehNetID) + if Config.System.Debug then print("^6Bridge^7: ^3ensureNetToVeh^7: ^2Requesting NetworkDoesNetworkIdExist^7(^6"..vehNetID.."^7)") end + local timeout = 100 + while not NetworkDoesNetworkIdExist(vehNetID) and timeout > 0 do + timeout -= 1 + Wait(10) + end + if not NetworkDoesNetworkIdExist(vehNetID) then + return 0 + end + timeout = 100 + local vehicle = NetToVeh(vehNetID) + while not DoesEntityExist(vehicle) and vehicle ~= 0 and timeout > 0 do + timeout -= 1 + Wait(10) + end + if not DoesEntityExist(vehicle) then + return 0 + end + return vehicle +end + function makeBlip(data) local blip = AddBlipForCoord(data.coords) SetBlipAsShortRange(blip, true) From b0b011ac56039ba02caf7d32c083bdeeca631fc9 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 20:25:44 +0000 Subject: [PATCH 10/12] update readme -main --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cf8b220..8ad3a0a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ But I want this script to grow with help of others who know more about other cor --- The installation of this script is simple +- REMOVE `-main` from the folder name, like any other github hosted script - it just needs to start before any script that requires it - it can start before core scripts if you want - for `qb-core` I personally place this script in `resources > [standalone]` From 7d0736bfc2c70d6c96039ef57529aaca8e811a48 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 22:33:35 +0000 Subject: [PATCH 11/12] Change how bridge decides what get/setvehicleproperties to use --- wrapper.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wrapper.lua b/wrapper.lua index ca68ffa..f32c36a 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -923,10 +923,10 @@ end function getVehicleProperties(vehicle) local properties = {} if vehicle == nil then return nil end - if GetResourceState(OXLibExport):find("start") then - properties = lib.getVehicleProperties(vehicle) - elseif GetResourceState(QBExport):find("start") then + if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then properties = Core.Functions.GetVehicleProperties(vehicle) + elseif GetResourceState(OXLibExport):find("start") then + properties = lib.getVehicleProperties(vehicle) end return properties end @@ -936,11 +936,11 @@ function setVehicleProperties(vehicle, props) print(("Unable to set vehicle properties for '%s' (entity does not exist)"): format(vehicle)) end - if GetResourceState(OXLibExport):find("start") then - TriggerServerEvent(GetCurrentResourceName()..":ox:setVehicleProperties", VehToNet(vehicle), props) - elseif GetResourceState(QBExport):find("start") then + if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then if Config.System.Debug then print("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7] - [^3"..props.plate.."^7]") end Core.Functions.SetVehicleProperties(vehicle, props) + else + TriggerServerEvent(GetCurrentResourceName()..":ox:setVehicleProperties", VehToNet(vehicle), props) end end From 85c3e069108efdb4e0d2e38685f0bba2904e5316 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 19 Jan 2024 23:57:22 +0000 Subject: [PATCH 12/12] update addItem/removeItem prints --- functions.lua | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/functions.lua b/functions.lua index a9ba79d..3ceddaf 100644 --- a/functions.lua +++ b/functions.lua @@ -573,8 +573,9 @@ end RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, item, amount, newsrc) local src = newsrc or source + local addremove = (tostring(give) == "true" and "addItem" or "removeItem") if Config.System.Debug then - print("^6Bridge^7: ^3toggleItem ^2triggered^7: ^6"..(tostring(give) == "true" and "addItem" or "removeItem").."^7 - ['^8"..tostring(item).."^7'] x"..(tostring(amount) or "1")) + print("^6Bridge^7: ^3toggleItem ^2triggered^7: ^6"..addremove.."^7 - '"..tostring(item).."' x"..(tostring(amount) or "1")) end local remamount = (amount and amount or 1) if item == nil then return end @@ -583,22 +584,22 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, if GetResourceState(OXInv):find("start") then local success = exports[OXInv]:RemoveItem(src, item, (amount and amount or 1), nil) if Config.System.Debug then - print("^6Bridge^7: ^1Removing ^2from Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) - '"..OXInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(QSInv):find("start") then local success = exports[QSInv]:RemoveItem(src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^1Removing ^2from Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) - '"..QSInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(CoreInv):find("start") then local success = exports[CoreInv]:removeItemExact('primary-'..src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^1Removing ^2from Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) - '"..CoreInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(CodeMInv):find("start") then local success = exports[CodeMInv]:RemoveItem(src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^1Removing ^2from Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) - '"..CodeMInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(QBInv):find("start") then while remamount > 0 do @@ -609,10 +610,10 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, TriggerClientEvent('inventory:client:ItemBox', src, Items[item], "remove", (amount and amount or 1)) end if Config.System.Debug then - print("^6Bridge^7: ^1Removing ^2from Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) - '"..QBInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..QBInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end else - print("^4Error^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") + print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") end else dupeWarn(src, item) -- if not boot the player @@ -622,22 +623,22 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, if GetResourceState(OXInv):find("start") then local success = exports[OXInv]:AddItem(src, item, amount or 1, nil) if Config.System.Debug then - print("^6Bridge^7: ^4Giving ^2Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) ^7"..OXInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(QSInv):find("start") then local success = exports[QSInv]:AddItem(src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^4Giving ^2Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) ^7"..QSInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(CoreInv):find("start") then local success = exports[CoreInv]:addItem('primary-'..src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^4Giving ^2Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) ^7"..CoreInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(CodeMInv):find("start") then local success = exports[CodeMInv]:AddItem(src, item, amount) if Config.System.Debug then - print("^6Bridge^7: ^4Giving ^2Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) ^7"..CodeMInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end elseif GetResourceState(QBInv):find("start") then if Core.Functions.GetPlayer(src).Functions.AddItem(item, amount or 1) then @@ -646,10 +647,10 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, --end end if Config.System.Debug then - print("^6Bridge^7: ^4Giving ^2Player^7(^2"..src.."^7) '^6"..Items[item].label.."^7(^2x^6"..((amount and amount or "1")).."^7) ^7"..QBInv) + print("^6Bridge^7: ^3"..addremove.."^7[^6"..QBInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") end else - print("^4Error^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") + print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") end end end)