Thread Tools Display Modes
08-19-14, 08:19 AM   #1
MaLarsson
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 13
Check if debuff exists in game

As the title says, I need help with error control.
The player types in the name of a debuff and if this debuff exists in the game then store it in the array debuffList. Code example follows:
Lua Code:
  1. local debuffList = {}
  2.  
  3. SLASH_CMD1 = '/cmd'
  4. function SlashCmdList.CMD(msg, editbox)
  5.     local command, rest = msg:match("^(%S*)%s*(.-)$")
  6.     if command == "add" then
  7.         if GetSpellInfo(rest) then -- GetSpellInfo() returns nil (false) if the spell does not exist.
  8.             table.insert(debuffList, rest)
  9.         else
  10.             print("Unknown spell")
  11.         end
  12.     end
  13. end
This code works fine in most cases but when the debuff does not share the same name as the spell this code does not work. For example; there is a debuff called weakened armor but it is applied using the spell sunder armor. If I want to add the debuff weakened armor it tells me that weakened armor is an unknow spell. Is there any way to check if a debuff exists in the game instead of checking if the spell exists in the game?
  Reply With Quote
08-19-14, 10:43 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
There is no distinction between spells and "debuffs". What's happening here is just that Sunder Armor triggers a different spell. In this case, supposedly due to the Weakened Armor effect being "normalised" these days and triggered by several abilities.
http://www.wowhead.com/spell=7386
http://www.wowhead.com/spell=113746
Also, GetSpellInfo only works with names if they are in your spellbook. If you use spell ID it will always work.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
08-19-14, 11:12 AM   #3
MaLarsson
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 13
ah, thanks for clarifying.
Is there any easy way to get spellID from the spellName if you do not have the spell in your spellbook?
  Reply With Quote
08-19-14, 11:18 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Well. You could do sth else. You could register UNIT_AURA to a specific event frame.

Each time UNIT_AURA triggers you can check
Lua Code:
  1. --get db via VARIABLES LOADED and saved variables
  2. local debuffList = DB.debuffList or {}
  3.  
  4. local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
  5.  
  6. local function SearchAuras(self,event,unit)
  7.   if not debuffList then return end
  8.   for i=1,40 do
  9.     name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitDebuff(unit,i)
  10.     if not name then break end
  11.     if not debuffList[spellId] then
  12.       debuffList[spellid] = {name = name, rank = rank, icon = icon, debuffType = debuffType, spellId = spellId}
  13.     end
  14.   end
  15. end
  16.  
  17. local auraCheck = CreateFrame("Frame")
  18. auraCheck:SetScript("OnEvent",SearchAuras)
  19. auraCheck:RegisterEvent("UNIT_AURA")

All spells are spells. Some spells are auras. Some less spells are debuffs.

UnitDebuff (aka. UnitAura, HARMFUL) may deliver even more values. You can check that by doing print(UnitDebuff(unit,i)).
http://wowprogramming.com/docs/api/UnitAura
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 08-19-14 at 11:28 AM.
  Reply With Quote
08-19-14, 02:52 PM   #5
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
I'm not sure if there's a performance benefit to declaring those local variables outside of the for loop, as they are reassigned each loop iteration anyway (although I could be wrong). There's also no need to explicitly initialize them to nil as this is the "default value" of a non-initialized variable anyway.
  Reply With Quote
08-19-14, 07:38 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There's no benefit. As a matter of good practice, you should limit variables to the lowest scope in which they are needed. If they're only used inside a loop, they should only exist inside that loop.
__________________
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
08-20-14, 02:13 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Did not know that. Thought there may be some sort of benefit of declaring the variables only once.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
08-20-14, 08:39 AM   #8
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
There's no benefit. As a matter of good practice, you should limit variables to the lowest scope in which they are needed. If they're only used inside a loop, they should only exist inside that loop.
It's not always true, keeping a local var inside the for loop:

- Create the variable
- Assign memory address to it.
- Allocate the memory for it.

- Then upvalue it with something.

However if you keep it outside the for loop, then the first 3 step is gonna run when you load the addon and only then, not recreating them at each loop, make the for loop run faster, since it only gonna overwrite whatever it can find the assigned memory address.
(Quick note with the current memory modules (DDR2-DDR3) overwriting a value is 30% faster then completely clear a memory block clean.)
However accessing a variable outside the loop also take some extra time.
You don't really make the whole code run faster, however you spread the workload into more modules, making the CPU/Memory peak usage lower.

More info in this thread:

http://www.wowinterface.com/forums/s...t=47694&page=3

Last edited by Resike : 08-20-14 at 09:19 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Check if debuff exists in game

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