WoWInterface (
-   PTR API and Graphics Changes (
-   -   New Item API (

thomasjohnshannon 05-30-18 09:13 PM

New Item API
If any of you have had to deal with getting item info in the past you will love the new item api. I have a bag addon that I use (my version isn't public) and always had problems getting the correct item level since GetItemInfo hadn't been fixed to deal with scaling item level. The new API made it really easy all it took was a few lines.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  3. if ( item ) then
  4.     ilevel = item:GetCurrentItemLevel()
  5. end

I'm creating from the bagID and slotID because the code was already setup that way but you can also set it up from an item link, equipment slot, or the new item location mixin.

Lua Code:
  1. --[[static]] function Item:CreateFromItemLocation(itemLocation)
  2.     if type(itemLocation) ~= "table" or type(itemLocation.HasAnyLocation) ~= "function" or not itemLocation:HasAnyLocation() then
  3.         error("Usage: Item:CreateFromItemLocation(notEmptyItemLocation)", 2);
  4.     end
  5.     local item = CreateFromMixins(ItemMixin);
  6.     item:SetItemLocation(itemLocation);
  7.     return item;
  8. end
  10. --[[static]] function Item:CreateFromBagAndSlot(bagID, slotIndex)
  11.     if type(bagID) ~= "number" or type(slotIndex) ~= "number" then
  12.         error("Usage: Item:CreateFromBagAndSlot(bagID, slotIndex)", 2);
  13.     end
  14.     local item = CreateFromMixins(ItemMixin);
  15.     item:SetItemLocation(ItemLocation:CreateFromBagAndSlot(bagID, slotIndex));
  16.     return item;
  17. end
  19. --[[static]] function Item:CreateFromEquipmentSlot(equipmentSlotIndex)
  20.     if type(equipmentSlotIndex) ~= "number" then
  21.         error("Usage: Item:CreateFromEquipmentSlot(equipmentSlotIndex)", 2);
  22.     end
  23.     local item = CreateFromMixins(ItemMixin);
  24.     item:SetItemLocation(ItemLocation:CreateFromEquipmentSlot(equipmentSlotIndex));
  25.     return item;
  26. end
  28. --[[static]] function Item:CreateFromItemLink(itemLink)
  29.     if type(itemLink) ~= "string" then
  30.         error("Usage: Item:CreateFromItemLink(itemLinkString)", 2);
  31.     end
  32.     local item = CreateFromMixins(ItemMixin);
  33.     item:SetItemLink(itemLink);
  34.     return item;
  35. end

I'm still looking into the new api so that is probably just scratching the surface of what you can do with it. If you want the full details you can find them in ItemDocumentation.lua in the API folder and under Item.lua in FrameXML\ObjectAPI.

runamonk 05-31-18 02:08 AM

I scan the tooltip and pull the scaled item level from there, it works everytime.

This looks interesting. :D

thomasjohnshannon 05-31-18 03:28 AM


Originally Posted by runamonk (Post 328211)
I scan the tooltip and pull the scaled item level from there, it works everytime.

This looks interesting. :D

That is what I was using before but this is a lot easier. One side note is you may need to wrap the code in the following code if it is going to load at startup.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  2. item:ContinueOnItemLoad(function()
  3.   -- Do thing with the data here.
  4. end)

The way they have item and spell data it needs to make sure everything is loaded before when the player first logs in.


Oh and it also has a function to check if an item is soulbound or not.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  3. item:ContinueOnItemLoad(function()
  4.     local location = item:GetItemLocation()
  5.     local isSoulbound = C_Item.IsBound(location)
  7.     -- Do stuff here.
  8. end)

runamonk 05-31-18 03:33 AM

Cool deal, it will certainly be much more efficient than pulling back a tooltip data for every armor or weapon to get the level. :)

sezz 05-31-18 09:49 AM

doesn't seem to work well when using item links

sample link (random weapon from a random level 120 guy in orgrimmar, since my highest char in beta is only 111)

"|cffa335ee|Hitem:154416:3370:::::::111:63:512:11:2:4811:4815:120:::|h[Trogg Saurolisk-Breaker]|h|r"
new api returns 229, that's the item level of the weapon scaled down to level 111 (my level)

i'll try it again in a month :rolleyes:

edit: the problem is that the linkLevel in the itemString returned by GetInventoryItemLink() has to be adjusted, still faster than tooltip scanning

runamonk 09-04-18 12:44 AM

I think they might have fixed GetDetailedItemLevelInfo(). It appears to be returning the correct level information now.

Ammako 09-04-18 06:29 AM

Huh, that'd be interesting if they had fixed that already. I'm going to have to verify that later.

runamonk 09-04-18 08:44 AM

and surprising to say the least. I haven't tested scaling down yet. So that could still be borked.

Ammako 09-04-18 04:34 PM

False alarm, it's still borked in the same way sadly.

runamonk 09-05-18 05:12 AM

Yep..Scaled levels are still wacked out.

doofus 10-22-18 01:37 AM

An old thread, sorry.

I am trying to get the item level, and as far as I can tell, there are two, main API functions




and they are both currently not working properly, definitely for down-scaling.

Is there another API we can use? How does the item tooltip deduce the correct iLvl ?

Edit: to provide more information, parsing the tooltip is also wrong, I parse "Item Level 280" and on screen it shows as "Item Level 266".

runamonk 10-22-18 04:09 AM

You can parse the item level out of the tooltip, that is accurate. That's what we're all doing at this point.

Lua Code:
  1. function mnkDurability.GetItemLevel(slotID)
  2.     local tip = CreateFrame("GameTooltip", "scanTip", UIParent, "GameTooltipTemplate")
  3.     tip:ClearLines()
  4.     tip:SetOwner(UIParent,"ANCHOR_NONE")
  5.     tip:SetInventoryItem("player", slotID)
  6.     for i=1, 5 do
  7.         local l = _G["scanTipTextLeft"..i]:GetText()
  8.         if l and l:find('Item Level') then
  9.             local _, i = string.find(l, 'Item Level%s%d')
  10.             -- check for boosted levels ie Chromeie scenarios.
  11.             local _, x = string.find(l, " (", 1, true)
  12.             --print(t, ' ', x)
  13.             if x then
  14.                 return string.sub(l, i, x-2) or '-'
  15.             end
  16.             return string.sub(l, i) or -'-'            
  17.         end
  18.     end
  20.     return '-'
  21. end

doofus 10-22-18 07:41 AM

I already parse the tooltip, and instead of using GameTooltip:SetInventoryItem as you have suggested, I use GameTooltip:SetHyperlink which allows me to inquire about items not in my bags.

But your comment made me look deeper and I have found one bug (at least) with GetCursorInfo. Imagine Green item, BoE, in guild bank, level = 120 and ilvl = 266.

When the item is in the guild bank and I pick it up, I get something like
"Sandscout Tunic" ilvl = 280. When the item is in my inventory I get something like "Sandscout tunic of the quickblade" ilvl = 266.

runamonk 10-22-18 07:42 AM

Yeah that method is from a durability addon I wrote so I can see all my gear I'm wearing. It tracks the items, durability and item levels blah blah blah hehe.. I use a similar but different routine for my bags and bank addon.

Hopefully they'll fix the actual methods and we won't have to jump through these silly hoops.

Becareful how much tooltip scanning you do, I ran into a situation were I was doing too much and it was causing my UI to randomly go totally blank lol. It was good stuff. :D

All times are GMT -6. The time now is 09:08 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI