WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Get ItemID on hover (https://www.wowinterface.com/forums/showthread.php?t=58510)

Walkerbo 12-31-20 07:29 PM

Get ItemID on hover
 
Hi all
I would like to find a way to get an itemID from an item that I am currently hovering over using a keybind.

So far I have been able to get this working by hooking the "OnTooltipSetItem" function as follows;

Lua Code:
  1. local tableOfItems, itemLink, itemID = {}, "", ""
  2.  
  3. GameTooltip:HookScript(
  4.     "OnTooltipSetItem",
  5.     function(self)
  6.         _, itemLink = self:GetItem()
  7.         if itemLink == "" or itemLink == nil then
  8.             return
  9.         else
  10.             itemID = tonumber(strmatch(itemLink, "item:(%d+):"))
  11.         end
  12.     end
  13. )
  14.  
  15. function ADDITEMTOLISTFUNCTION()
  16.     if itemLink == "" then
  17.         print("no item found")
  18.     else
  19.         addItemToList(tableOfItems, itemID)
  20.         print(itemLink, "added to list")
  21.     end
  22.     itemLink = ""
  23.     itemID = ""
  24. end

Though this does work it will pick up any item when I mouse over my bags no matter how fast I move even while not pressing the player set keybinding.

Is there a better way to get the itemID only whilst pressing the keybind?

Vrul 12-31-20 07:47 PM

Lua Code:
  1. function ADDITEMTOLISTFUNCTION()
  2.     if GameTooltip:IsShown() then
  3.         local _, itemLink = GameTooltip:GetItem()
  4.         if itemLink then
  5.             local itemID = GetItemInfoFromHyperlink(itemLink)
  6.             if itemID then
  7.                 addItemToList(tableOfItems, itemID)
  8.                 print(itemLink, "added to list")
  9.             end
  10.         end
  11.     end
  12. end

Walkerbo 01-01-21 05:26 AM

Hi Vrul

That worked perfectly.

Thanks for your help.


All times are GMT -6. The time now is 09:42 PM.

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