Thread Tools Display Modes
10-08-12, 11:15 AM   #1
Mayoren
A Defias Bandit
Join Date: Oct 2012
Posts: 3
I have a coding question about my new addon.

I have a coding question about my new addon.

Basically, i'm trying to write an addon that tells you about your interrupt spells.

these three are what this addon supposed to do.


It pops up a message whenever you actually interrupt enemy's spells.

If you fail to interrupt enemy's spells (immune,absorb,etc), it pops up a failure message with cooldown duration of the spell you failed with.

If you cast an interrupt spell than is still on its cooldown, it pops up a message to show you the remaining cooldown duration of the spell.



and here is my code.

Lua Code:
  1. -- Spell List
  2.  
  3. local spellData = {
  4.  
  5.     -- Class Spells
  6.  
  7.     [2139] = { -- Counterspell
  8.         cooldown = 24,
  9.         --texture = "Interface\\Icons\\spell_frost_iceshock",
  10.     },
  11.     [1766] = { -- Kick
  12.         cooldown = 15,
  13.     },
  14.     [47528] = { -- Mind Freeze
  15.         cooldown = 15,
  16.     },
  17.     [6522] = { -- Pummel
  18.         cooldown = 15,
  19.     },
  20.     [96231] = { -- Rebuke
  21.         cooldown = 15,
  22.     },
  23.     [80964] = { -- Skull Bash (Bear Form)
  24.         cooldown = 15,
  25.     },
  26.     [80965] = { -- Skull Bash (Cat Form)
  27.         cooldown = 15,
  28.     },
  29.     [57994] = { -- Wind Shear
  30.         cooldown = 12,
  31.     },
  32.     [34490] = { -- Silencing Shot
  33.         cooldown = 20,
  34.     },
  35.     [15487] = { -- Silence (Priest)
  36.         cooldown = 45,
  37.     },
  38.     [47476] = { -- Strangulate
  39.         cooldown = 120,
  40.     },
  41.     --[108194] = { -- Asphyxiate
  42.     --  cooldown = 20,
  43.     --},
  44.     [116705] = { -- Spear Hand Strike
  45.         cooldown = 15,
  46.     },
  47.  
  48.     -- Racials
  49.  
  50.     [28730] = { -- Arcane Torrent (Mana)
  51.         cooldown = 120,
  52.     },
  53.     [50613] = { -- Arcane Torrent (Runic Power)
  54.         cooldown = 120,
  55.     },
  56.     [80483] = { -- Arcane Torrent (Focus)
  57.         cooldown = 120,
  58.     },
  59.     [129597] = { -- Arcane Torrent (Chi)
  60.         cooldown = 120,
  61.     },
  62.     [25046] = { -- Arcane Torrent (Energy)
  63.         cooldown = 120,
  64.     },
  65.     [69179] = { -- Arcane Torrent (Rage)
  66.         cooldown = 120,
  67.     },
  68. }
  69.  
  70.  
  71. local eventFrame = CreateFrame("Frame")
  72.  
  73. eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  74.  
  75. eventFrame:SetScript("OnEvent", function(self, event, timestap, combatEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, spellSchool, extraSpellID, extraSpellName, ...)
  76.    
  77.    
  78.     if sourceName ~= UnitName("Player") then
  79.         return
  80.     end
  81.  
  82. -- Messages
  83.    
  84.    
  85.     local fChat = GetSpellLink(spellID).." has failed to interrupt !!!  "..spell.cooldown.."s CD"
  86.     local sChat = GetSpellLink(spellID).." > "..destName.."'s "..GetSpellLink(extraSpellID)
  87.  
  88.    
  89.     if combatEvent == "SPELL_CAST_SUCCESS" then
  90.         local spell = spellData[spellID]
  91.         if not spell then
  92.             return
  93.         end
  94.  
  95.         if combatEvent == "SPELL_AURA_APPLIED" then
  96.         SendChatMessage(sChat,"Say")
  97.         end
  98.        
  99.         if combatEvent == "SPELL_INTERRUPT" then
  100.         SendChatMessage(sChat,"Say")
  101.         end
  102.        
  103.         SendChatMessage(fChat,"Say")
  104.     end
  105.            
  106.     if combatEvent == "SPELL_CAST_MISSED" then
  107.         local spell = spellData[spellID]
  108.             if not spell then
  109.         return
  110.         end
  111.         SendChatMessage(fChat,"Say")
  112.     end
  113.    
  114.    
  115. -- Remaining Time Message
  116.  
  117.     if combatEvent == "SPELL_CAST_FAILED" then
  118.         local spell = spellData[spellID]
  119.             if not spell then
  120.                 return
  121.             end
  122.         if IsSpellInRange(spellName,"Target") == 1 or spellName == "Arcane Torrent" then
  123.             local xt,yt,zt = GetSpellCooldown(spellID)
  124.             local cdt = (xt + yt) - GetTime()
  125.             if zt ~= 0 then
  126.             SendChatMessage(GetSpellLink(spellID).."'s CD has "..(ceil(cdt*10)/10).."s left","Say")
  127.             end
  128.         end
  129.     end
  130. end)


I noticed that when you are supposed to only get a message for either spell_aura_applied or spell_interrupt, you also get a spell_cast_success message
like,

[Kick] has failed to interrupt !!! 15s CD
[Kick] > Mage's [Frost Bolt]



I want to know if you can ignore the cast_success message whenever you get either aura_applied or cast_interrupt message.

Also, if there is a way to fix this addon to make it work better, please help me to do so. I am a newb and this is my very first addon
  Reply With Quote
10-08-12, 01:15 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Mayoren View Post
Code:
if combatEvent == "SPELL_CAST_SUCCESS" then
	local spell = spellData[spellID]
	if not spell then
		return
	end

	if combatEvent == "SPELL_AURA_APPLIED" then
		SendChatMessage(sChat,"Say")
	end

	if combatEvent == "SPELL_INTERRUPT" then
		SendChatMessage(sChat,"Say")
	end

	SendChatMessage(fChat,"Say")
end
This structure makes it so the success messages would never show since a variable can't have two values at once. Honestly, the SPELL_CAST_SUCCESS handling doesn't make sense since the spell finishing casting isn't related to whether or not it actually hit. I would get rid of that check and the fail message at the end of it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-08-12, 03:05 PM   #3
Mayoren
A Defias Bandit
Join Date: Oct 2012
Posts: 3
Originally Posted by SDPhantom View Post
This structure makes it so the success messages would never show since a variable can't have two values at once. Honestly, the SPELL_CAST_SUCCESS handling doesn't make sense since the spell finishing casting isn't related to whether or not it actually hit. I would get rid of that check and the fail message at the end of it.
I posted the wrong one I think. That part is actually from the other copy of file that I tried to fix last night and haven't tested

This is the actual code that gives me double message,

Lua Code:
  1. if combatEvent == "SPELL_CAST_SUCCESS" then
  2.         local spell = spellData[spellID]
  3.             if not spell then
  4.         return
  5.         end
  6.         SendChatMessage(GetSpellLink(spellID).." has failed to interrupt !!!  "..cd.."s CD","Say")
  7.     end
  8.    
  9.    
  10.     if combatEvent == "SPELL_AURA_APPLIED" then
  11.         local spell = spellData[spellID]
  12.             if not spell then
  13.         return
  14.         end
  15.         SendChatMessage(GetSpellLink(spellID).." > "..destName.."'s "..cd,"Say")
  16.     end    
  17.    
  18.    
  19.     if combatEvent == "SPELL_INTERRUPT" then
  20.         local spell = spellData[spellID]
  21.             if not spell then
  22.         return
  23.         end
  24.         SendChatMessage(GetSpellLink(spellID).." has failed to interrupt !!!  "..cd.."s CD","Say")
  25.     end

Is there a way to stop print CAST_SUCCESS message when you print either AURA_APPLIED or INTERRUPT message?

Last edited by Mayoren : 10-08-12 at 03:10 PM.
  Reply With Quote
10-08-12, 04:03 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
In that case, just remove that entire SPELL_CAST_SUCCESS block. That event fires when the spell finishes casting, no matter if it took effect on the target or not. I would also suggest havint the spell check before the other conditionals since no matter what event type is triggered, you'd want to exit if it's a spell you want to exclude.

This is what I have in mind:
Lua Code:
  1. --  Spell List
  2. local spellData = {
  3.  
  4. --  Class Spells
  5.  
  6.     [2139] = { -- Counterspell
  7.         cooldown = 24,
  8. --      texture = "Interface\\Icons\\spell_frost_iceshock",
  9.     },
  10.     [1766] = { -- Kick
  11.         cooldown = 15,
  12.     },
  13.     [47528] = { -- Mind Freeze
  14.         cooldown = 15,
  15.     },
  16.     [6522] = { -- Pummel
  17.         cooldown = 15,
  18.     },
  19.     [96231] = { -- Rebuke
  20.         cooldown = 15,
  21.     },
  22.     [80964] = { -- Skull Bash (Bear Form)
  23.         cooldown = 15,
  24.     },
  25.     [80965] = { -- Skull Bash (Cat Form)
  26.         cooldown = 15,
  27.     },
  28.     [57994] = { -- Wind Shear
  29.         cooldown = 12,
  30.     },
  31.     [34490] = { -- Silencing Shot
  32.         cooldown = 20,
  33.     },
  34.     [15487] = { -- Silence (Priest)
  35.         cooldown = 45,
  36.     },
  37.     [47476] = { -- Strangulate
  38.         cooldown = 120,
  39.     },
  40. --  [108194] = { -- Asphyxiate
  41. --      cooldown = 20,
  42. --  },
  43.     [116705] = { -- Spear Hand Strike
  44.         cooldown = 15,
  45.     },
  46.  
  47. --  Racials
  48.  
  49.     [28730] = { -- Arcane Torrent (Mana)
  50.         cooldown = 120,
  51.     },
  52.     [50613] = { -- Arcane Torrent (Runic Power)
  53.         cooldown = 120,
  54.     },
  55.     [80483] = { -- Arcane Torrent (Focus)
  56.         cooldown = 120,
  57.     },
  58.     [129597] = { -- Arcane Torrent (Chi)
  59.         cooldown = 120,
  60.     },
  61.     [25046] = { -- Arcane Torrent (Energy)
  62.         cooldown = 120,
  63.     },
  64.     [69179] = { -- Arcane Torrent (Rage)
  65.         cooldown = 120,
  66.     },
  67. }
  68.  
  69. local eventFrame = CreateFrame("Frame")
  70. eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  71. eventFrame:SetScript("OnEvent", function(self,event, _, combatEvent, _, sourceGUID, _, _, _, _, destName, _, _, spellID, spellName, _, extraSpellID)
  72.  
  73. --  Only allow player and specific spells we handle
  74.     local spell=spellData[spellID]
  75.     if sourceGUID ~= UnitGUID("Player") or not spell then
  76.         return
  77.     end
  78.  
  79. --  Success/Fail Messages
  80.     if combatEvent == "SPELL_INTERRUPT" then
  81.         SendChatMessage(format("%s > %s's %s",GetSpellLink(spellID),destName,GetSpellLink(extraSpellID)),"Say")
  82.     elseif combatEvent == "SPELL_CAST_MISSED" then
  83.         SendChatMessage(format("%s has failed to interrupt !!!  %.0fs CD",GetSpellLink(spellID),spell.cooldown),"Say")
  84.     elseif combatEvent == "SPELL_CAST_FAILED" then
  85. --      Remaining Time Message
  86.         local start, duration, enabled = GetSpellCooldown(spellID)
  87.         if enabled==1 and duration>0 then
  88.             SendChatMessage(format("%s's CD has %0.1fs left", GetSpellLink(spellID), (start + duration) - GetTime()), "Say")
  89.         end
  90.     end
  91. end)

Note, I shortened the code a bit, renamed the variables receiving GetSpellCooldown()'s returns to conform with Blizzard's Add-On Development Policy regarding obfuscation, and cleaned up the event handler's parameters. The unused handler parameters have been renamed to the variable _ , which even though it's considered in Lua as just another variable, it's commonly used for this and is easier to distinguish as a value that isn't important.

EDIT: Removed the condition for SPELL_AURA_APPLIED since in some cases, it may cause spaming when using an AoE ability like Arcane Torrent. This will also fix some cases of success messages sending twice.

Note, SPELL_CAST_FAILED should also be considered for possible spam as some players may "mash" the ability when trying to cast it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-08-12 at 04:13 PM.
  Reply With Quote
10-08-12, 04:26 PM   #5
Mayoren
A Defias Bandit
Join Date: Oct 2012
Posts: 3
I noticed that when you cast spells like rogue's Kick to a non-casting target, it only returns SPELL_CAST_SUCCESS to the combatlog.

It is a success casting but it didn't actually interrupt spells so it should be considered as a failure in this addon and should print the message.

Also I had to put AURA_APPLIED part because spells like Silencing Shot and Strangulate apply silence aura before or instead of the interrupt. I should just remove arcane torrent from the spell list if the spamming is gonna be the issue

and thank you very much for all these help
  Reply With Quote
10-08-12, 05:39 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I'll have to look again, but last I saw, silence effects do trigger an interrupt if the target is in the process of casting. This may fire another event like UNIT_SPELLCAST_INTERRUPTED. If you insist on sending a message on SPELL_CAST_SUCCESS, I'd suggest using a different message saying along the lines of "X used on Y, CD in Z seconds." This would at least make the message more relevant to the event firing. It's also good practice to limit how much you send through public chat channels as messages being sent too often is frowned upon by the player base and Blizzard themselves.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-08-12 at 05:42 PM.
  Reply With Quote
10-08-12, 07:00 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by SDPhantom View Post
I ... renamed the variables receiving GetSpellCooldown()'s returns to conform with Blizzard's Add-On Development Policy regarding obfuscation...
That doesn't really seem necessary. The original code was not even remotely approaching anything I'd call obfuscated. It's simply not wasting time typing a long variable name when you're only using that variable one time, on the very next line. There's a big difference between that, and addons with no line breaks or whitespace anywhere in the code, where every single variable is given a random one-letter name, and everything is upvalued to random one-letter variables to intentionally make the code unreadable.
__________________
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.
  Reply With Quote
10-09-12, 09:55 AM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Whitespace is just a minor inconvenience, but variable names that offer no information as to what values are put in them is the real meaning of obfuscation.



The code block in question was this.
Code:
local xt,yt,zt = GetSpellCooldown(spellID)
local cdt = (xt + yt) - GetTime()
Even though it's a couple lines, the point is still there.
If speed is your concern, it would be quicker to type and more meaningful to use local s,d,e.


References on the word obfuscation:
http://dictionary.reference.com/browse/obfuscation
http://wiki.answers.com/Q/What_is_ob...fuscation_used
http://sawaal.ibibo.com/computers-an...on-140331.html
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-09-12 at 10:46 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I have a coding question about my new addon.

Thread Tools
Display Modes

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