Thread Tools Display Modes
03-31-10, 11:34 AM   #1
ascesis
A Defias Bandit
Join Date: Jan 2010
Posts: 3
Best Practice for "Throttling" CombatEvents?

So, I have a small mod I wrote to track "failures" and related events for Vengeful Shades on H. Deathwhisper. Anyways, I have it setup at the moment to announce when people get melee by the ghosts (which corresponds to being too close), when they are summoned, and when people take damage. For the latter two events, I wanted to condense them because they have multiple combat log events (multiple shades and multiple people taking damage).

I'm not sure what the "best practice" is for throttling such events, or if it would have to be a simple time delay. I'm sorry if this code is a travesty, I'm not a programmer by trade or hobby.

Code:
function WWH:OnCombatEvent(event, timestamp, eventType, srcGuid, srcName, srcFlags, dstGuid, dstName, dstFlags, ...)
	
	local pName = dstName or "wat"
	local colorpName = self:GetClassColor(pName) .. pName	
	local hour, minute = GetGameTime()
	local ts = "[" .. hour .. ":" .. minute .. "] "
	
	-- Spirit Summon 
	if ( eventType == "SPELL_SUMMON" ) then
		local spellID, spellName, spellSchool = select(1, ...)
	
		if ( spellName == "Summon Spirit" ) then
			local summonEntry = ts .. ": |cffFCD116Spirits Summoned"
			table.insert(WWH.historyBuffer, summonEntry)
		
			WWH.Summoned = WWH.Summoned + 1
	
		end
	end
	
	-- Failure
	if ( eventType == "SWING_DAMAGE" or "SWING_MISSED" ) and ( srcName == "Vengeful Shade" ) then

		local failEntry = ts .. colorpName .. ": |cff00FF00failed at Vengeful Spirits|r" 
		local ChannelDump = ts .. pName .. ": failed at Vengeful Spirits"
		table.insert(WWH.historyBuffer, failEntry)
		
		if (self.db.global.LiveReport) then
			self:Print(failEntry)
		end
		
		if (self.db.global.RaidAnnounce) then
			local msg = pName .. " FAILED at Ghosts"
			SendChatMessage(msg, "RAID_WARNING")
		end
		
		if (self.db.global.ChannelDump) then
			SendChatMessage(ChannelDump, db.ChannelDumpOutput)
		end		

	
	end
	
	-- Damage Taken from Explosion
	if ( eventType == "SPELL_DAMAGE" and srcName == "Vengeful Shade" ) then

		local dmgEntry = ts .. colorpName .. ": |cff008000took damage from ghosts"
		table.insert(WWH.historyBuffer, dmgEntry)
		
		
		-- used for compressed dmg taken raid announcing
		WWH.lasteventwasghostdmg = true
		if (WWH.whotookdmg == "") then 
			WWH.whotookdmg = pName 
		else 
			WWH.whotookdmg = WWH.whotookdmg .. ", " .. pName
		end
		
		
	end

	-- Reduce who took raid damage spam
	if ( WWH.lasteventwasghostdmg == true and eventType ~= "SPELL_DAMAGE" and srcName ~= "Vengeful Shade" ) then
		if (self.db.global.RaidAnnounce) then
			local msg = WWH.whotookdmg .. " took damage from ghosts"
			SendChatMessage(msg, "RAID")
		end
		
		if (self.db.global.ChannelDump) then
			local ChannelDump = ts .. WWH.whotookdmg .. " took damage from ghosts"
			SendChatMessage(ChannelDump, db.ChannelDumpOutput)
		end		
		
		if (self.db.global.LiveReport) then
			self:Print(WWH.whotookdmg .. " took damage from ghosts")
		end
			
		WWH.lasteventwasghostdmg = false
		WWH.whotookdmg = ""
		
	end
	
	-- only use summon warning once
	if ( eventType ~= "SPELL_SUMMON" and WWH.Summoned > 1 ) then
		WWH.Summoned = 0 
	end
	
	if ( WWH.Summoned == 1 ) then
		if (self.db.global.RaidAnnounce) then
			SendChatMessage("INCOMING GHOSTS!", "RAID_WARNING")
		end
		if (self.db.global.LiveReport) then
			local summonEntry = ts .. ": |cffFCD116Spirits Summoned"	
			self:Print(summonEntry)
		end
	end

		
end
  Reply With Quote
03-31-10, 11:52 AM   #2
lilsparky
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 117
what you could do is run an OnUpdate script that handles the messaging.

have your combat log event only collect the data.

your OnUpdate script would be set up to do something like this:

Code:
local myTimer = 5
local function myOnUpdate(frame, elapsed)
    myTimer = myTimer - elapsed

    if myTimer < 0 then
        myTimer = 5 -- seconds till next spam, 5 is probably too long, but it's just an example
        
       spamTheRaid()
    end
end

spamTheRaid() would check your collected data and spam the raid with the warnings, then reset all those variables so that it doesn't keep spamming the same stuff over and over.
  Reply With Quote
03-31-10, 12:37 PM   #3
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Code:
local lastAnnounce = 0
if lastAnnounce + 1 < GetTime() then -- 1 second throttle
     -- throttled code
     lastAnnounce = GetTime()
end
You can just wrap it around your CLEU. You might be able to use the timestamp argument (and if so it would probably be faster than a TON of GetTime() calls), but I don't know the format of timestamp.
  Reply With Quote
03-31-10, 02:59 PM   #4
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Code:
local lastAnnounce = 0
if lastAnnounce + 1 < GetTime() then -- 1 second throttle
     -- throttled code
     lastAnnounce = GetTime()
end
I would move the math so that the check does not need to
do it every time.

Code:
local lastAnnounce = 0
if lastAnnounce < GetTime() then -- 1 second throttle
     -- throttled code
     lastAnnounce = GetTime() + 1
end
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
03-31-10, 03:14 PM   #5
Shadowed
...
Premium Member
Featured
Join Date: Feb 2006
Posts: 387
You want lilsparky's solution, his is bucketing which is what you want when you're trying to consolidate multiple events into one. Waverian's is a pure throttle, which while it works when you only want to do something once every X seconds, it doesn't work when you need data on multiple events, but you want them merged.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Best Practice for "Throttling" CombatEvents?


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