Thread Tools Display Modes
12-31-20, 07:29 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
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?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
12-31-20, 07:47 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
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
  Reply With Quote
01-01-21, 05:26 AM   #3
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi Vrul

That worked perfectly.

Thanks for your help.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get ItemID on hover

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