mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-26 05:50:50 +00:00
api: add itemcount function
This commit is contained in:
+25
@@ -98,6 +98,31 @@ function pfUI.api.GetItemLinkByName(name)
|
|||||||
end
|
end
|
||||||
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 ]
|
-- [ Abbreviate ]
|
||||||
-- Abbreviates a number from 1234 to 1.23k
|
-- Abbreviates a number from 1234 to 1.23k
|
||||||
-- 'number' [number] the number that should be abbreviated
|
-- 'number' [number] the number that should be abbreviated
|
||||||
|
|||||||
Reference in New Issue
Block a user