From 1f4a2ee3d999e7754bfa6fea2ba45d9c588c1c56 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Mon, 5 May 2025 12:28:30 +0100 Subject: [PATCH] refactor `checkStashItem()` This'll probably break it, (it works for me) but refactored the stash item check, it was calling `stashHasItem()` for every ingredient check, now it sends the whole table of ingredients per item to craft and checks them together instead of separately Also removes a `Wait()`, as it shouldn't need it with this change..maybe --- shared/stashcontrol.lua | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/shared/stashcontrol.lua b/shared/stashcontrol.lua index a9da2ec..b2b2cb7 100644 --- a/shared/stashcontrol.lua +++ b/shared/stashcontrol.lua @@ -47,12 +47,12 @@ function GetStashTimeout(stashName, stop) stashCache[stashName] = { items = {}, timeout = 0 } stash = stashCache[stashName] else - debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache found^7") + debugPrint("^6Bridge^7: ^2Local Stash for ^7'^3"..stashName.."^7'^2 cache found^7") end -- If there are already items in cache, skip recheck. if countTable(stashCache[stashName].items) > 0 then - debugPrint("^6Bridge^7: '^3"..stashName.." ^2Items found in cache, skipping recheck") + debugPrint("^6Bridge^7: '^3"..stashName.."^7' ^2Items found in local cache, skipping server recheck") return true end @@ -90,20 +90,12 @@ function checkStashItem(stashes, itemTable) end if type(stashes) == "table" then - local successes = 0 - local itemCount = countTable(itemTable) + debugPrint("^6Bridge^7: ^2Checking multiple stashes for ingredients^7") -- Iterate over each provided stash name. for _, name in pairs(stashes) do - Wait(10) -- Delay to avoid multiple callbacks issues. GetStashTimeout(name) - for item, amount in pairs(itemTable) do - debugPrint("^6Bridge^7: ^2Checking "..(name and " '^3"..name.."^7'" or "").." ingredients - ^6"..item.."^7") - if stashhasItem(stashCache[name].items, item, amount) then - successes += 1 - if successes == itemCount then - return true, name - end - end + if stashhasItem(stashCache[name].items, itemTable, nil) then + return true, name end end else