Thread Tools Display Modes
04-02-15, 10:30 AM   #1
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Misunderstandings with COMBAT_LOG_EVENT

My intention:
I wrote this script to track the internal cooldown of my trinket. So it's basically in it's functioning way a liteweight version of ExtraCD.

What i want the script to do:

Create an icon above my PlayerFrame and when my trinket procs, the ICD should be displayed.

What works right now:
The icon shows up and it also shows the ICD of 45 sec.

Whats wrong:
The CD display starts/resets whenever i use an ability or autoattack regardless which ability is used.

What i think is the problem:

I think the script fails when its checking if the trinket buff was applied to my character or not. It seems just to fire everytime SPELL_AURA_APPLIED is happening which causes the instant reset on the ICD display. But it should only fire for the trinket of course.

Code:
--create the event frame & register events
local eventFrame = CreateFrame("Frame")
	eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")	

--create cooldown frame & texture it	
local proc = CreateFrame("Cooldown","ProcTrinket",eventFrame,"CooldownFrameTemplate")
	proc:ClearAllPoints()
	proc:SetPoint("TOPRIGHT",PlayerFrame,-2,15)
	proc:SetSize(30,30)
	proc.icon = proc:CreateTexture(nil,"BACKGROUND")
	proc.icon:SetAllPoints()
	proc.icon:SetTexture("Interface\\Icons\\inv_60pvp_trinket3c")

--let the magic happen here	
eventFrame:SetScript("OnEvent",function(self,...)
	local _,event,_,_,sourceName,_,_,_,_,_,_,spellId,_,_,_,_ = select(2,...)	
	
		if event == "SPELL_AURA_APPLIED" or "SPELL_AURA_REFRESH" and sourceName == UnitName("player") and spellId == 126707 then
			CooldownFrame_SetTimer(proc,GetTime(),45,1)
		end
end)

Here is the way i figured out he COMBAT_LOG_EVENT stuff. I guess i misunderstood something here. I got the information from wowwiki, wowpedia and wowprogramming.
Code:
PARAMETER
  1. timestamp
  2. event
  3. hideCaster
  4. sourceGUID
  5. sourceName
  6. sourceFlags
  7. sourceRaidFlags
  8. destGUID
  9. destName
  10. destFlags
  11. destRaidFlags
  12. spellId
  13. spellName
  14. spellSchool
  15. auraType
  16. amount
  Reply With Quote
04-02-15, 10:47 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Lua Code:
  1. if event == "SPELL_AURA_APPLIED" or "SPELL_AURA_REFRESH" and sourceName == UnitName("player") and spellId == 126707 then
This means if the event is SPELL_AURA_APPLIED it's going to ignore the other conditions because you have "or" after it and it's short-circuiting.

Lua Code:
  1. if event == "SPELL_AURA_APPLIED" or "SPELL_AURA_REFRESH"
Also, this doesn't mean "if event == 'SPELL_AURA_APPLIED' or event == 'SPELL_AURA_REFRESH'", it's going to evaluate the string "SPELL_AURA_REFRESH" as an expression which is always going to be "true".

You can write it like this, although you should use the GUID of the player instead of their name which isn't necessarily unique, and you don't really need to query their name/GUID every time this is run, it would be better to store it in a variable when they log in.
Lua Code:
  1. if spellId == 126707 and sourceName == UnitName("player") and (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH") then

There's also no point in using select here, you may as well write your event handler like this..
Lua Code:
  1. eventFrame:SetScript("OnEvent", function(self, eventName, ...)
  2. local _, event, _, _, sourceName, _, _, _, _, _, _, spellId = ...

Last edited by semlar : 04-02-15 at 10:50 AM.
  Reply With Quote
04-02-15, 11:16 AM   #3
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Works like a charm now and i learned a bit more about LUA. Thank you
  Reply With Quote
04-02-15, 08:05 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Sylen View Post
Works like a charm now and i learned a bit more about LUA. Thank you
You can learn something else about Lua, rather than LUA: http://en.wikipedia.org/wiki/Lua_%28...ng_language%29

Happy trails!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Misunderstandings with COMBAT_LOG_EVENT


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