Yeah scanning tooltips is a popular method for determining if a buff/debuff is "Magic", "Poison", etc. Scanning tooltips is basically these steps:
1. Make a custom tooltip: In your XML, make a custom tooltip like this:
<GameTooltip name="MyMod_TooltipScan" inherits="GameTooltipTemplate" parent="UIParent" hidden="true"/>
While this can go anywhere, I generally put it outside the normal "Frames" of my mod, where you define templates and stuff:
<Ui>
<Script file="MyMod.lua"/>
<GameTooltip name="MyMod_TooltipScan" inherits="GameTooltipTemplate" parent="UIParent" hidden="true"/>
<Frame name="MyMod_Frame">
<Size>
etc
2. Use a GameTooltip widget to write a tooltip to your custom one: You can see a list here:
http://www.wowwiki.com/Widget_API#GameTooltip All the GameTooltip:Set(something) constructs a tooltip. There's a lot of them as you can see. At the bottom are two you'd be interested in:
GameTooltip:SetUnitBuff("unit",buffIndex) - Shows the tooltip for a unit's buff.
GameTooltip:SetUnitDebuff("unit",buffIndex) - Shows the tooltip for a unit's debuff.
|
In your code, when you want to scan the tooltip:
MyMod_TooltipScan:SetUnitDebuff("player",1) -- create tooltip for first debuff on player
Now MyMod_TooltipScan is a hidden copy of the tooltip you'd see for that buff.
3. Read what's on the tooltip: GameTooltip (and any GameTooltips that inherit its template) have 30 rows and two columns:
GameTooltipTextLeft1 GameTooltipTextRight1
GameTooltipTextLeft2 GameTooltipTextRight2
GameTooltipTextLeft3 GameTooltipTextRight3
GameTooltipTextLeft4 GameTooltipTextRight4
etc
Replace GameTooltip with MyMod_TooltipScan:
MyMod_TooltipScanTextLeft1 MyMod_TooltipScanTextRight1
MyMod_TooltipScanTextLeft2 MyMod_TooltipScanTextRight2
MyMod_TooltipScanTextLeft3 MyMod_TooltipScanTextRight3
MyMod_TooltipScanTextLeft4 MyMod_TooltipScanTextRight4
etc
For debuffs I think the "magic"/"poison" is always TextRight2? Not certain. If so your mod can do:
local debuffType = MyMod_TooltipScanTextRight3:GetText()
and that's it. It sounds like a lot but it's not really. Define a custom tooltip in your xml, :SetUnitDebuff to the tooltip when you want to scan it, and then read the tooltip lines you're interested in.
It's probably worth noting that scanning tooltips is not lightning-fast if you plan to do hundreds of scans a second. I would avoid scanning all 30 lines for something that appears near the top for instance. But it's a great way to find out information about stuff and very commonly used so I wouldn't hesitate to play around with them.