Thread Tools Display Modes
02/06/17, 03:41 PM   #1
Klingo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
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)

Klingo
  Reply With Quote
02/06/17, 07:48 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
GetLootItemLink needs the lootId, not index:
Lua Code:
  1. local lootId, name = GetLootItemInfo(i)
  2. local link = GetLootItemLink(lootId)
  Reply With Quote
02/06/17, 11:21 PM   #3
Klingo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
Thumbs up

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
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Get ItemType from LootItemType

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off