Jump to content
Alumian

[HELP] GameTooltip Event

Recommended Posts

Hi guys,

I'm on struggle street here. I'm trying to work out the event that is fired when you view an item tooltip (whether that be mousing over an item in your inventory/an item that is equipped/in the loot window, etc..., or even if you click a hyperlinked item in chat). I want to work that out so that I can call GetItemInfo() and use the args from that but I simply just cannot figure out what event that is.

Even if I do frame:RegisterAllEvents() and print out the results, it actually doesn't print out the result of mousing over an item or clicking the hyperlink. I figure the event is related to GameTooltip but I really just don't know.

 

Could someone give me a hand please?

Share this post


Link to post
Share on other sites

some actions dont have events (for example: temp. enchantments - poisons)

 

you can work with workarounds though :)

 

for example:

 

1. inspecting the frame with on OnUpdate function frame:IsVisible()

 

2. adding a script to the frame you want to hook: frame:SetScript("OnShow", function() end) - make sure there is no other OnShow script

 

3. adding an invisible frame and make it a child of the tooltip frame...now you can do the same as in 2. with the childframe

Edited by Renew

Share this post


Link to post
Share on other sites

Thanks for your response Renew :)

I'm not 100% sure howto inspect a frame with OnUpdate, but other than that I tried doing 2 and 3 but no avail :(

Here's my code at the moment:

tooltip = CreateFrame("GameTooltip", "CTT", nil, "GameTooltipTemplate")
 
tooltip:SetScript("OnShow", tooltip_Show)
tooltip:SetScript("OnHide", tooltip_Hide)
 
local function tooltip_Show(self, motions)
DEFAULT_CHAT_FRAME:AddMessage("Showing: " .. self:GetName()) --For debugging purposes
tooltip:Show()
end
 
local function tooltip_Hide(self, motion)
DEFAULT_CHAT_FRAME:AddMessage(self:GetName())
tooltip:Hide()
end

I just simply can't get the frame to show and it seems that the OnShow and OnHide events hooks aren't firing since I'm not even getting the message. Can you see what I'm doing wrong?

Edited by Alumian

Share this post


Link to post
Share on other sites

Hey!

Your events are not firing because you are using your own tooltip rather than the global GameTooltip that is used for most links.

I am not sure if there is an event, probably not. However as Renew said you can hook the Show function and check if it is an itemTooltip.

 

It will look like something along this lines:

local oldGTShow = GameTooltip.Show
function GameTooltip.Show()
   mySuperCoolHookFunction()
   oldGTShow()
end

Not sure if this is the correct hooking syntax but it should be something along those lines. Has been a while since I found time to code in lua^^

 

Be careful though. If you do a mistake you could prevent other addons from working and even crash the client very easily.

 

cheers!

Share this post


Link to post
Share on other sites
local oldGTShow = GameTooltip.Show
function GameTooltip.Show()
   mySuperCoolHookFunction()
   oldGTShow()
end

Not sure if this is the correct hooking syntax but it should be something along those lines. Has been a while since I found time to code in lua^^

 

Be careful though. If you do a mistake you could prevent other addons from working and even crash the client very easily.

 

cheers!

 

Thats the usuall way to securely hook a function, but syntax for the blizzard frames doesnt work in this "modern" style :)

 

All the blizzard function have their own global name and are not inside a table/frame, often the frame dont have any OnShow/OnHide functions, so you dont even have to hook them but just create a new one...like in this case:

local function ToolTipOnShow()
	DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnShow Event fired!")
end

GameTooltip:SetScript("OnShow", ToolTipOnShow)

is enough to fire the function ToolTipOnShow() each time the tooltip shows up!

 

source:

 

PAARwUr.png

Share this post


Link to post
Share on other sites

Hey guys thanks so much for the responses. Shino I tried your solution but I couldn't get it to work for me :( it only worked for things like attributes on the character window (i.e. resistances and stats) for some reason. Renew I just tried your solution and it's firing quite nicely thanks :)

I just have one last question. My addon is dependent on the details of the item. I see the function GameTooltip:GetItem() but it keeps throwing an exception for me (Error:  attempt to call method `GetItem' (a nil value)) where my code is:

local function ToolTipOnShow()
local _, link = GameTooltip:GetItem()
end
 
GameTooltip:SetScript("OnShow", ToolTipOnShow)

If I can get this part working then I can parse link on to GetItemInfo(link) to get the rest of the values I need.

 

Any ideas?

Edited by Alumian

Share this post


Link to post
Share on other sites

well, this is the part where you (as dev) have to think about how to solve this problem :)

 

but i give you a tip: attempt to call method `GetItem' (a nil value) means that the function GetItem does not exist (is nil) and therefore you cant use this function, welcome to vanilla wow :D

Share this post


Link to post
Share on other sites

Yep now comes the creative part:

The first thing you might notice. It will be possible to parse the rarity, name, stats etc. But one crucial think will be missing: The ID.

 

Vanilla is, needs you to think a little outside the box: 

Every tooltip is created before it is shown. Item Tooltips are a little complicated though. There are different functions that are being called: If you inspect someone and hover over the items, if you hover over the items in your bags or if you click on a link in the chat.

Depending on what you need there are several ways to go around this:

1. Look for similiar functions: 

-> GetContainerItemLink(a, B)

-> GetInventoryItemLink(a, B)

-> GetAuctionItemLink(a, B)

 

(http://wowwiki.wikia.com/wiki/ItemLink)

For the chat you might as well just parse it and look for itemlinks.

 

The itemlink does not give you info about stats. It will give you an info about enchantments and "type enchantments" (Something like "of the boar").

 

So now you can think about what you want to achieve and possible workaround to get there.

 

Sometimes attempts might not work, (mine didnt work as well that I suggested here. I used a similiar attempt to track absorbs and dispels properly with DPSMate, but I didnt hook the Show function but rather a function to fill the tooltip.) You can do the same to get the arguments you need in order to do whatever you want^^

 

Don't give up, trust me you can do pretty much anything in vanilla^^

 

Hope that helps you, I feel like Renew just threw you a little in the cold water : P

 

cheers!

 

Edit: 

As I understood it, you just wanted to have the item stats right?

I think the only way to get those is to parse the tooltip.

Edited by Shino

Share this post


Link to post
Share on other sites

Thanks heaps for the help guys :)

 

 

As I understood it, you just wanted to have the item stats right?
Not sure if this qualifies as an item stat, but I need the item level, rarity and the slot. Those are the only attributes I need.
 
Do you guys have any reliable resources that you use for LUA functionality in Classic? I've been using http://vanilla-wow.wikia.com/wiki/World_of_Warcraft_API but it seems that a lot of the functions listed there:
1) have no documentation and
2) just simply don't exist in vanilla (i.e. GameTooltip:GetItem()).
Edited by Alumian

Share this post


Link to post
Share on other sites

The only source that I have is the FrameXML tree that you can find for every patch. (I am on my laptop, so just google it^^)

 

Generally it is like this: You look for an function, try it: If it does not exist, you look if there has been a previous one, else just buid your own one. There is not a good documentation of the vanilla API that I know of, but using the current one is good enough.

 

Item level huh ?

I think that is viewable on the tooltip right? So you get this info from there.

You can get the rarity from the coloring of the item. The itemlink provides a unique color code for each rarity.

If you hook the GameTooltip fill function for inventory slot example you can get the information directly, else I am not sure if there is any function that gives you the info about this. Alternativly you can parse the tooltip again and look for something like head, cloak etc.

 

cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×