05-22-12, 11:35 AM | #1 |
interrupt lockout duration display
hi, i want to do a script that displays the lockout duration on target/focus when an interrupt hit them. as i am not too confident in my lua knowledge i deciede to make a post on this forums and hope to find some help.
my main problem is, i don't really know how to implement the arguments of COMBAT_LOG _EVENT_UNFILTERED properly for this purpose. as of now i use: Code:
t=CreateFrame("Frame") t:SetPoint("CENTER",0,-100) t:SetSize(40,40) t.c=CreateFrame("Cooldown","cd1") t.c:SetAllPoints(t) t.t=t:CreateTexture(nil,"BORDER") t.t:SetAllPoints() t.t:SetTexture("Interface\\Icons\\ability_kick") t:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") t:SetScript("OnEvent", function(...) local a,_,_,d = select(4, ...) if (a == "SPELL_INTERRUPT"and d == UnitName("Player")) then CooldownFrame_SetTimer(cd1,GetTime(),5,1)end end) the next step would be to take ANY interrupt spell into account and determining the different lockout duration depending on what interrupt hit the target/focus (ExtraSpellID argument i believe?) eg: "1766" = 5, -- Kick "2139"= 8, -- Counterspell and the final adjustment i'd like to do would be for the icon(s) to only show when they are actually counting down (is cooldown spiral shown = true or sth, really no clue sorry ) any help would be greatly appreciated, thank you for your patience with a lua noob in advance. Last edited by zin99 : 05-22-12 at 12:08 PM. |
|
05-23-12, 01:55 PM | #2 |
ok i got it in a working condition. im am sure the code is anything but pretty, but well it really is the third time im trying to do anything in lua. i basically have a lot of if/elseif stuff for any combination of SpellID und destUnit and its working so far.
now my question is: how can i hide the icon frame displaying the cooldown if it isn't actually counting, and have it pop only if an interrupt hits aka the cooldown spiral is shown on the icon. |
|
05-23-12, 06:03 PM | #3 | |
As has been stated hundreds of times in basically every thread on these forums: If you want help fixing, changing, cutting down, or adding to your code, post your code. |
||
05-24-12, 04:39 AM | #4 |
ok sorry phanx, here it is. i am ready to get laughed at for this code:
Code:
local addon, addonName = ... local frame = CreateFrame("Frame") local onEvent = function(self, event, ...) if event == "COMBAT_LOG_EVENT_UNFILTERED" then local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, spellSchool, extraSpellID, extraSpellName = ...; if (subevent == "SPELL_INTERRUPT") then interruptgo(destName, spellID) end end end frame:SetScript("OnEvent", onEvent) frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") target=CreateFrame("Frame") target:SetPoint("CENTER", TargetFrame, "CENTER",-130,0) target:SetSize(40,40) target.c=CreateFrame("Cooldown","cd1") target.c:SetAllPoints(target) target.t=target:CreateTexture(nil,"BORDER") target.t:SetAllPoints() target.t:SetTexture("Interface\\Icons\\ability_kick") focus=CreateFrame("Frame") focus:SetPoint("CENTER", FocusFrame, "CENTER",-130,0) focus:SetSize(40,40) focus.c=CreateFrame("Cooldown","cd2") focus.c:SetAllPoints(focus) focus.t=focus:CreateTexture(nil,"BORDER") focus.t:SetAllPoints() focus.t:SetTexture("Interface\\Icons\\ability_kick") function interruptgo(destName, spellID) if spellID == 1766 and destName == (UnitName("target")) then CooldownFrame_SetTimer(cd1,GetTime(),5,1) target.t:SetTexture("Interface\\Icons\\ability_kick") elseif spellID == 1766 and destName == (UnitName("focus")) then CooldownFrame_SetTimer(cd2,GetTime(),5,1) focus.t:SetTexture("Interface\\Icons\\ability_kick") elseif spellID == 1766 and destName == (UnitName("target")) then CooldownFrame_SetTimer(cd1,GetTime(),4,1) target.t:SetTexture("Interface\\Icons\\spell_holy_rebuke") elseif spellID == 1766 and destName == (UnitName("focus")) then CooldownFrame_SetTimer(cd2,GetTime(),4,1) focus.t:SetTexture("Interface\\Icons\\spell_holy_rebuke") -- and so on for all interrupt spells... end end but as is said, my main goal now is to not have the icons shown always but only if they are actually counting. is there a way to determine if there is actually an animation running on the CooldownFrame cd1 or cd2, or do i have to do it with an OnUpdate GetTime thingy. thanx for helping me! Last edited by zin99 : 05-24-12 at 04:41 AM. |
|
05-26-12, 04:32 AM | #5 |
First, some general suggestions for your code:
1. Don't create global variables. Not only are they slower to access than local variables, but they can easily be overwritten by other addons, especially when they have generic names like target. 2. Use a table for spell data instead of a long if-else chain. You already mentioned this; see below to see how to implement it. 3. Don't create one-use functions. In your code, the interruptgo function is only called once, from inside the onEvent function. Function closures cost memory, so it's more efficient to just move the contents of the interruptgo function into the onEvent function. If you were going to call the interruptgo function from different places (eg. more than one frame would call it from its event handler), then factoring out that code into its own function would be a good idea, but that's not the case here. 4. Use consistent, proper indentation. This will make your code much easier to read. Second, to hide the icon when it's not displaying anything, hook the cooldown object's :Hide() method. Here is your code with the above optimizations and changes applied, plus lots of comments to help you understand what's going on, and print statements to help you see what's going on in-game. You'll want to comment out the print statements once you know it's working. I've also attached a copy in Lua file form to this post, so you don't have to copy and paste (and deal with the extra blank lines that are inserted when you copy from highlighted code blocks on this forum). Lua Code:
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
05-26-12, 05:09 PM | #6 |
thank you so much phanx, especially for the explanations, really helps me a lot to understand lua better.
you should consider releasing this as an addon i guarantee a lot of people would appreciate it if they don't find or expect to find it in the forums. edit: maybe as a plugin for losecontrol, the two would be a perfect fit Last edited by zin99 : 05-26-12 at 05:12 PM. |
|
05-27-12, 10:19 PM | #7 |
I probably won't release an addon like this, since publishing an addon I don't personally use is just too much of a hassle to try to maintain and support. I will never notice when a patch breaks it, for example, or when something doesn't work right, or when something needs to be added.
However, you (or anyone else) are free to turn it into an addon or publish it. I absolutely don't care what anyone does with my code, either code I've posted on the forums, or code from my addons; the main restriction in the license I use for my addons is that you have to pick your own name for the addon (eg. if you copy code from my addon PhanxChat and use it in your own addon, you can't call your addon PhanxChatPlus). The reasons for this are that (a) I don't want anyone coming to me to get help with your addon, and (b) if your addon sucks, I don't want people thinking I had anything to do with it.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
WoWInterface » Developer Discussions » Lua/XML Help » interrupt lockout duration display |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|