api: add itemcount function

This commit is contained in:
shagu
2017-07-29 21:17:28 +02:00
parent d98c368c38
commit 38686e56f9
+25
View File
@@ -98,6 +98,31 @@ function pfUI.api.GetItemLinkByName(name)
end
end
-- [ GetItemCount ]
-- Returns information about how many of a given item the player has.
-- 'itemName' [string] name of the item
-- returns: [int] the number of the given item
function pfUI.api.GetItemCount(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
-- [ Abbreviate ]
-- Abbreviates a number from 1234 to 1.23k
-- 'number' [number] the number that should be abbreviated