WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   how to track a weapon enchant proc with a tag (https://www.wowinterface.com/forums/showthread.php?t=46225)

Dawn 04-09-13 01:23 PM

how to track a weapon enchant proc with a tag
 
As the title suggest I'm trying to track weapon enchant procs (like Dancing Steel, Colossus, ...) with a tag.

I'm using this code to track all kinds of other "normal" buffs.

for instance, this one tracks the PvP strength trinket proc. The same code also works for things like Sacred Shield, Renew, ...
Code:

oUF.Tags.Methods['GhostSoVTime'] = function(u) -- PvP Trinket Strength Proc
local name, _,_,_,_,_, expirationTime, fromwho = UnitAura(u, GetSpellInfo(126700) or "Surge of Victory")
    if(fromwho == "player") then
        local spellTimer = (expirationTime-GetTime())
                local TimeLeft = format("%.0f", spellTimer)
                        return "|cfffaaaab"..TimeLeft.."|r"
    end
end
oUF.Tags.Events['GhostSoVTime'] = "UNIT_AURA"

When I'm using said code to track, let's say, Dancing Steel. It shows nothing.

I suppose it's because "fromwho" fails to return anything for weapon enchant procs? Since the "casterID" (aka fromwho) can only be player, but even if I use "if fromwho == "none"" or just "if fromwho then". It still returns nothing.

So how do I have to adapt the code to track weapon enchant procs? :)



Edit: Found a way ... just checking for the name instead of owner. :rolleyes:

Code:

oUF.Tags.Methods['GhostDSTime'] = function(u) -- Dancing Steel Enchant Proc id 120032 or 118335
local name, _,_,_,_,_, expirationTime, fromwho = UnitAura(u, GetSpellInfo(120032) or "Dancing Steel")
    if (name == "Dancing Steel") then
        local spellTimer = (expirationTime-GetTime())
                local TimeLeft = format("%.0f", spellTimer)
                        return "|cff6670FF"..TimeLeft.."|r"
    end
end
oUF.Tags.Events['GhostDSTime'] = "UNIT_AURA"


Phanx 04-09-13 03:04 PM

You should avoid doing a GetSpellInfo lookup on every UNIT_AURA event. You can also avoid the cost of the string concatenation by including the color codes directly in your format pattern.

Code:

local DANCING_STEEL = GetSpellInfo(120032)
oUF.Tags.Events["GhostSDTime"] = "UNIT_AURA"
oUF.Tags.Methods["GhostDSTime"] = function(u)
    local _, _, _, _, _, _, expirationTime = UnitAura(u, DANCING_STEEL)
    if expirationTime then
        return format("|cff6670ff%.0f|r", expirationTime - GetTime())
    end
end


Dawn 04-11-13 07:33 AM

Problem was, if I didn't check for casterID (fromwho), I kept getting an error on "expirationTime".

I'll try the code, will stick with your formatting, it's cleaner. Thanks. :)


E: Works nicely, thanks again Phanx.

Phanx 04-11-13 08:52 PM

It's usually best to just check the most directly related thing -- in this case, the data you actually want to work with is the expiration time, so just check if that has a value. If it does, you're good to go. Checking other things like the buff name or caster unit may work, but is really just superfluous and doesn't necessarily guarantee that the data you want is there.

It's similar to browser sniffing vs. feature detection in JavaScript, if you do any web development -- you should always just check to see if the feature you want to use exists, instead of trying to figure out which version of which browser is running your code and make assumptions about which features that version of that browser supports. Unfortunately, a lot of sites use browser sniffing, which leads to the endless "site X doesn't work in browser Y" problems.


All times are GMT -6. The time now is 05:25 PM.

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