From 94738bab45fe37b5a24885e79c0f2a2d9d7d023b Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 4 Sep 2020 08:14:55 +0200 Subject: [PATCH] api: add api call to find item in bags --- api/api.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/api.lua b/api/api.lua index 26318ddf..d6d1e3fe 100644 --- a/api/api.lua +++ b/api/api.lua @@ -266,6 +266,28 @@ function pfUI.api.GetItemCount(itemName) return count end +-- [ FindItem ] +-- Returns the bag and slot position of an item based on the name. +-- 'item' [string] name of the item +-- returns: [int] bag +-- [int] slot +function pfUI.api.FindItem(item) + for bag = 4, 0, -1 do + for slot = 1, GetContainerNumSlots(bag) do + local itemLink = GetContainerItemLink(bag,slot) + if itemLink then + local _, _, parse = strfind(itemLink, "(%d+):") + local query = GetItemInfo(parse) + if query and query ~= "" and query == item then + return bag, slot + end + end + end + end + + return nil +end + -- [ GetBagFamily ] -- Returns information about the type of a bag such as Soul Bags or Quivers. -- Available bagtypes are "BAG", "KEYRING", "SOULBAG", "QUIVER" and "SPECIAL"