Quantcast Need help with my debuff tracker - WoWInterface
Thread Tools Display Modes
10-23-12, 10:50 AM   #1
Hallur
A Murloc Raider
Join Date: May 2012
Posts: 4
Need help with my debuff tracker

I'm trying to make a simple AddOn that keeps track of Flame Shock on my target. I know that I could just download another AddOn such as TellMeWhen or NeedToKnow etc. but I'm doing this for learning purposes. Anyway, any suggestions how I would do this? This is what I've got so far, but it doesn't work the way I want it to. It displays the remaining time of the debuff every time it ticks, but it doesn't tick at exactly every second, so for example it might display: 24.00001, 22.0003, 19.458... or something like that.

Code:
function RegisterEvents (self)
	self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

function EventHandler (self, event, ...)
	if event == "COMBAT_LOG_EVENT_UNFILTERED" then
		local playerGUID = UnitGUID("player")
		local targetGUID = UnitGUID("target")
		local timestamp, spellEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2 = ...

		if sourceGUID == playerGUID and destGUID == targetGUID and (spellEvent == "SPELL_AURA_APPLIED" or spellEvent == "SPELL_PERIODIC_DAMAGE") then
			local expirationTime = select(7, UnitAura("target", "Flame Shock", nil, "PLAYER|HARMFUL"))

			if expirationTime then
				FST_Main_FontString:SetText(expirationTime - GetTime())
			else
				FST_Main_FontString:SetText()
			end
		end
	end
end
TL; DR: How do I make a timer that tracks Flame Shock and ticks every 1 second?

PS: English is not my native language so if I'm not making myself clear then don't hesitate to ask, I won't take offense.
  Reply With Quote
10-23-12, 06:44 PM   #2
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
If you want to "do" something on an exact regular interval, it's going to be significantly more difficult than you might expect.

I'm not sure if this is all your code, or if you have an OnUpdate script somewhere. But basically, due to factors like lag, latency and frame rates, even the most frequent and regular events may creep in one direction or the other when it comes to when they fire.

The key is to assume the numbers you get from functions like UnitAura are correct, but to smooth the transitions between updates yourself. After you call UnitAura once here due to your event firing, don't rely on waiting for another COMBAT_LOG_EVENT_UNFILTERED event that shows up exactly 1.0000 seconds later, because it probably won't arrive exactly on time. Instead, set up your frame to update itself regularly using the information that you DO have. Here you might want to save the return values of that UnitAura call, and set an OnUpdate script on your Flame Shock frame that updates it either every frame or every 0.25 seconds or whatever with how much time has passed since you made that call. This will also mean rounding your numbers in some way since you won't get OnUpdate calls happening at exact 1.0000 second intervals either. When another combat log event does fire, you can use those values as your new base and just continue updating as usual again.

In this particular case I'd also say it's probably actually a good idea to use a regular non-combat log check, or else a UNIT_AURA event, to check for your spell application as well as, or instead of, your combat log event. The reason for that is that your Flame Shock might be dispelled or immuned away. There's also issues with multiple targets that are more complicated when using the combat log like this.
  Reply With Quote
10-23-12, 06:52 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I already replied to this on Wowace, with several suggestions, and lots of annotated code:
http://forums.wowace.com/showthread....680#post323680
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help with my debuff tracker

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