View Single Post
06-13-10, 01:22 PM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Taking what you posted and cleaning it up:
Code:
local frame, numValks, timer, valks, playerGUID = CreateFrame('Frame'), 0, 0, { }
frame:Hide()

frame:SetScript('OnUpdate', function(self, elapsed)
	timer = timer + elapsed
	if timer < 0.5 then return end
	timer = 0
	local count, now = numValks, time()
	for guid, timeOut in pairs(valks) do
		if timeOut <= now then
			valks[guid] = nil
			numValks = numValks - 1
		end
	end
	if numValks ~= count then
		print("Val'kyr timed out. Count: " .. numValks)
		if numValks == 0 then
			self:Hide()
		end
	end
end)

local function OnEvent(self, event, timeStamp, combatEvent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags)
	if combatEvent == 'SPELL_SUMMON' then
		if destName == "Val'kyr Guardian" and sourceGUID == playerGUID then
			valks[destGUID] = time() + 30
			numValks = numValks + 1
			if numValks == 1 then
				self:Show()
			end
			print("Val'kyr spawned. Count: " .. numValks)
		end
	elseif combatEvent == 'UNIT_DIED' and valks[destGUID] then
		valks[destGUID] = nil
		numValks = numValks - 1
		if numValks == 0 then
			timer = 0
			self:Hide()
		end
		print("Val'kyr died. Count: " .. numValks)
	end
end

frame:SetScript('OnEvent', function(self)
	self:UnregisterEvent('PLAYER_ENTERING_WORLD')
	playerGUID = UnitGUID('player')
	self:SetScript('OnEvent', OnEvent)
	self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
	print("Val'kyr Counter Loaded.")
end)
frame:RegisterEvent('PLAYER_ENTERING_WORLD')
That will do basically the same as what you posted and is completely stand alone. I'm not sure why anyone would want this though. Maybe if instead of spamming text you had an icon with a counter that is only shown when you have Val'kyr active.
  Reply With Quote