View Single Post
06-13-10, 09:52 AM   #1
Ingensu
A Fallenroot Satyr
 
Ingensu's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 22
Bizarre Bug in Nibelung Count Addon

*** RESOLVED. ***

Okay, here's the deal. I'm working on an addon for the purposes of tracking the Val'kyr spawns off of the Nibelung staff. It works perfectly so far...sometimes. It'll work consistently for a while, then (seemingly at random) break for a while. It's a little odd, to say the least, and I've been scratching my head trying to figure out the problem with it. I was hoping that someone here could take a look and see if they can see where I went wrong, but honestly, I have no idea.

The way it (is supposed to) works is it maintains a counter as to how many Val'kyr are currently up at any given point in time. Now, the Val'kyr in question are named "Val'kyr Guardian" and are summoned by a spell called "Summon Val'kyr Guardian", which is reported as a summon in a combat log event. They last 30 seconds, but are able to be killed, so the addon needs to make note of this as well. When they despawn, they fire no combat log event (as far as I can tell), so I track each Val'kyr with a non-indexed table. In this case, the keys are the GUIDs of each Val'kyr (which are gathered from the summoning event), and the values are the system time, in seconds, when it was summoned. At this point, all I need to do is remove these from the table when a Val'kyr either A) dies or B) has been up for at least 30 seconds, in which case it has despawned. To check to see if a Val'kyr has been up for 30 seconds, on every combat log event it goes through the table and compares the current system time for the one logged for each individual Val'kyr. If any of them have a 30 second difference with the current time, that Val'kyr is dropped from the table. The user's GUID is recorded to double-check that Val'kyr that are summoned actually belong to the user, rather than someone else's procs.

So far, this method has been precise enough that it registers a Val'kyr's despawn within a second or less, and a Val'kyr's death instantaneously. This is good enough for my purposes.

The issue is that the mod loads properly (with the "counter loaded" message displaying), but will occasionally not report, or count, any Val'kyr spawns, despawns, or deaths. If I check the values of the count variables or the table manually when they -should- be changing, they come up nil.

Code:
valktable={};
playerguid=nil;
valkcount=0;
function ValkyrLoad()
	DEFAULT_CHAT_FRAME:AddMessage("Val'kyr Counter Loaded.");
	ValkyrCountFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
	playerguid = UnitGUID("player");
end


function ValkyrOnEvent(self, event, ...)
	for i,v in pairs(valktable) do
	local comptime = GetTime();
		if(v+30<comptime) then
		valktable[i]=nil;
		valkcount=valkcount-1;
		DEFAULT_CHAT_FRAME:AddMessage("Val'kyr timed out. Count: " .. valkcount);

		end
	end


	if(event=="COMBAT_LOG_EVENT_UNFILTERED") then
	local timestamp, combatevent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = ...;

		if(combatevent=="UNIT_DIED") then
			for i,v in pairs(valktable) do
				if(destGUID==i) then
					valktable[i]=nil;
					valkcount=valkcount-1;
					DEFAULT_CHAT_FRAME:AddMessage("Val'kyr died. Count: " .. valkcount);
				end
			end
		end

		if (combatevent=="SPELL_SUMMON" and destName=="Val'kyr Guardian" and sourceGUID == playerguid) then
			local comptime = GetTime();
			valktable[destGUID]=comptime;
			valkcount=valkcount+1;
			DEFAULT_CHAT_FRAME:AddMessage("Val'kyr spawned. Count: " .. valkcount);

		end

	end



end
I suspect that it may be an issue with pulling the user's GUID. But I'm not sure why there would be a problem with the way I'm doing it.

Any help would be appreciated! I hope this was complete enough for you to understand what I'm trying to accomplish!
__________________
Devī - Level 85 Beast Mastery hunter.
Devikins - Level 85 Feral (Bear) druid.
Aetheriel - Level 85 Restoration shaman.
US - Stormrage
Goal: Level and gear one of every class. (2.5/10)

Last edited by Ingensu : 06-13-10 at 12:38 PM. Reason: Resolved.
  Reply With Quote