ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Get ItemType from LootItemType (https://www.esoui.com/forums/showthread.php?t=6790)

Klingo 02/06/17 03:41 PM

Get ItemType from LootItemType
 
Hi

I was looking for a way to figure out what type of items are lootable from any given container.

With [EVENT_LOOT_UPDATED] I know exactly when the loot window opens and I can also loop through all lootable items. With "GetLootItemInfo()" I then can get the LootItemType, which for clothing materials etc. is always [LOOT_TYPE_ANY]. But what I actually would want to have is the real itemType, which in case for e.g. "Jute" would be [ITEMTYPE_CLOTHIER_RAW_MATERIAL].

Since "GetLootItemInfo()" was no success, I thought it might be possible to use the "GetItemLinkItemType()" method and then get the information via the itemLink from the lootItem... but this also just returns the LootItemType [LOOT_TYPE_ANY].

This is my code example:
Lua Code:
  1. local lootCount =  GetNumLootItems()
  2. for i = 0, lootCount - 1 do
  3.     local _, name, _, _, _, _, _, _, lootItemType = GetLootItemInfo(i)
  4.  
  5.     CHAT_SYSTEM:AddMessage("lootItemType = " .. lootItemType)
  6.  
  7.     local link = GetLootItemLink(i)
  8.     local itemType = GetItemLinkItemType(link)
  9.  
  10.     CHAT_SYSTEM:AddMessage("itemType = " .. itemType)
  11. end

Which generates the following chat output (for e.g. "Jute"):
Code:

lootItemType = 0
itemType = 0


Is it even possible to know what ItemType a lootable item is... before looting it?
I mean in a reasonable way and not with hundreds of lines of code to check for every possible name of the item (although that would work) :D

Klingo

merlight 02/06/17 07:48 PM

GetLootItemLink needs the lootId, not index:
Lua Code:
  1. local lootId, name = GetLootItemInfo(i)
  2. local link = GetLootItemLink(lootId)

Klingo 02/06/17 11:21 PM

Oops :O

You're absolutely right. If I use the lootId and change the for-loop to start at 1, it is working exactly as expected.
Thanks a lot for pointing that out!

Lua Code:
  1. local lootCount =  GetNumLootItems()
  2. for i = 1, lootCount do
  3.     local lootId, name, _, _, _, _, _, _, lootItemType = GetLootItemInfo(i)
  4.  
  5.     CHAT_SYSTEM:AddMessage("lootItemType = " .. lootItemType)
  6.  
  7.     local link = GetLootItemLink(lootId)
  8.     local itemType = GetItemLinkItemType(link)
  9.  
  10.     CHAT_SYSTEM:AddMessage("itemType = " .. itemType)
  11. end


All times are GMT -6. The time now is 04:14 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI