From c2cb97bf241dc872a2977b8b5672659197eaafb7 Mon Sep 17 00:00:00 2001 From: shagu Date: Wed, 30 Apr 2025 18:38:54 +0200 Subject: [PATCH] helpers: add function to get item count --- helpers.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/helpers.lua b/helpers.lua index bb75dd6..a1cfdca 100644 --- a/helpers.lua +++ b/helpers.lua @@ -171,7 +171,6 @@ ShaguTweaks.cmatch = function(str, pat) return ra, rb, rc, rd, re end - local timer ShaguTweaks.QueueFunction = function(a1,a2,a3,a4,a5,a6,a7,a8,a9) if not timer then @@ -338,3 +337,24 @@ end ShaguTweaks.spairs = function(t) return orderedNext, t, nil end + +ShaguTweaks.GetItemCount = function(itemName) + local count = 0 + for bag = 4, 0, -1 do + for slot = 1, GetContainerNumSlots(bag) do + local _, itemCount = GetContainerItemInfo(bag, slot) + if itemCount then + local itemLink = GetContainerItemLink(bag,slot) + local _, _, itemParse = strfind(itemLink, "(%d+):") + local queryName = GetItemInfo(itemParse) + if queryName and queryName ~= "" then + if queryName == itemName then + count = count + itemCount + end + end + end + end + end + + return count +end