You neet to iterate through all the inventory bags/storage, then if the id matches, then you add the number of items to the count
This is the code I use, I store the name and id of the items I want to track in nameIdMap.items and updateInventory iterates all the usage storage looking for the items and store them in gameinfo.inventory table.
When I need an item, I get it using get_item_count. Example of nameIdMap.items is
nameIdMap.items['shihei'] = 1179
Code
local function updateInventory()
gameinfo.inventory = {}
for name,id in pairs(nameIdMap.items) do
gameinfo.inventory[id] = 0
end
local bags = S{0,8,10,11,12,13,14,15,16}
for bag in bags:it() do
if (windower.ffxi.get_bag_info(bag).enabled) then
local inventory = windower.ffxi.get_items(bag) -- only items in inventory and wardrobe
for index = 1, inventory.max do
local item = inventory[index]
if gameinfo.inventory[item.id] ~= nil then
gameinfo.inventory[item.id] = gameinfo.inventory[item.id] + item.count
else
gameinfo.inventory[item.id] = item.count
end
end
end
end
gameinfo.update.inventory = false
end
local function get_item_count(name)
local nameLower = name:lower()
local id = nameIdMap.items[nameLower]
if not id then
return 0
end
if not gameinfo.inventory[id] then
return 0
end
return gameinfo.inventory[id]
end