So in one of my addons I need access to information on how often a DoT/HoT ticks on a unit.
One of the ways I'm experimenting with is pulling the hasted tick time from the tooltip itself on UNIT_AURA event.
My code:
Code:
addEvent(function(self, event, unit)
for i=1, 40 do
for _, spellbar in ipairs(ns.spellbars.active) do
if spellbar.spellConfig.debuff[1] > 0 then -- We have a debuff to look at
if unit == (type(spellbar.spellConfig.debuff[2]) == "string" and spellbar.spellConfig.debuff[2] or "target") then
local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitDebuff(unit, i)
if caster == "player" then
if spellbar.spellConfig.debuff[1] == spellID then -- Ooh, we found it on this spellbar.
ns.tooltip:SetUnitDebuff(unit, i)
local scanText = _G["EventHorizonScanTooltipTextLeft2"]:GetText()
local tickSpeed = tonumber(string.sub(scanText, string.find(scanText, "every ")+6, string.find(scanText, " sec")-1))
--tonumber returns nil if it can't be converted to a number
ns:addDebuff(spellbar, duration, tickSpeed)
end
end
end
end
end
end
end,
"UNIT_AURA")
A cursory inspection of wowhead seems to show that all DoTs/HoTs tooltips say "every x.xx sec".
I'm not versed in Lua pattern matching at all and I managed to get the x.xx information using what I have below, but on a non-matching string it returns garbage information. tonumber() luckily returns nil if the number can't be converted, but I'm sure that there's more efficient/robust ways of doing it using pattern matching.
Does anyone know of a pattern which would match only the x.xx portion of the string to make it more efficient? (Or any other changes to my above code to make it more efficient)
Thanks
-Brusalk
Code:
tonumber(string.sub(scanText, string.find(scanText, "every ")+6, string.find(scanText, " sec")-1))