WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Displaying item level on item tooltip (https://www.wowinterface.com/forums/showthread.php?t=59763)

Eommus 01-15-24 03:57 AM

Displaying item level on item tooltip
 
Hi,

Some years ago, I used the following to display the item level on an item's tooltip (except armor and weapons and those already had item level info). But it seems it no longer works. I've been away from WoW and LUA coding for a long time, and I will appreciate any pointers to fix my code below.

Thanks!

Lua Code:
  1. local function Add_Item_Level(tooltip)
  2.     local itemLink = select(2, tooltip:GetItem())
  3.    
  4.     if itemLink ~= nil then
  5.         local itemLevel = select(4, GetItemInfo(itemLink))
  6.         local itemType = select(6, GetItemInfo(itemLink))
  7.  
  8.         if itemType ~= "Armor" and itemType ~= "Weapon" and itemLevel ~= nil then
  9.             tooltip:AppendText(" |cffffd100("..itemLevel..")")
  10.         end
  11.     end
  12. end
  13.  
  14. GameTooltip:HookScript("OnTooltipSetItem", Add_Item_Level)

EDIT 1: I learned that the API was changed. Replacing the last line with the following fixed it.

Lua Code:
  1. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, Add_Item_Level)

EDIT 2: But it now gives the following error for comparison item tooltips:

Lua Code:
  1. main.lua:2: attempt to call method 'GetItem' (a nil value)

I guess GetItem() was also removed but no idea what to use instead.

Codger 03-25-24 10:58 PM

Many of the item functions were moved to C_Item
 
Try C_Item.GetItem()

SDPhantom 03-26-24 02:39 PM

tooltip:GetItem() was replaced with TooltipUtil.GetDisplayedItem().


All times are GMT -6. The time now is 06:18 AM.

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