Thread Tools Display Modes
05-09-17, 09:19 AM   #21
syncrow
A Flamescale Wyrmkin
 
syncrow's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 149
To prevent such annoyance, I wrote a complete a new debug module which only checks for annoyance of my own API:

Pretty much like c# try / catch <3

Everything else is third-party-addon stuff
(you are dismissed, foolish addon)
__________________
  Reply With Quote
05-12-17, 12:56 AM   #22
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Sorry for interrupting

I got a further question to MunkDev.

So, I was trying to apply same method to target's debuff and here I got some issue.

Lua Code:
  1. local auraIDList = {
  2.     233490,
  3.     233496,
  4.     233497,
  5.     233498,
  6.     233499,
  7. };
  8.  
  9. local function UpdateDebuff(self)
  10.     self:ReleaseAll();
  11.  
  12.     local prevButton;
  13.     for i, auraID in pairs(auraIDList) do
  14.         local spellName = GetSpellInfo(auraID);
  15.         local _, _, icon, count, _, duration, expires = UnitDebuff("target", spellName, nil, "PLAYER");
  16.  
  17.         if duration and duration >= 0 then
  18.             local button = self:Acquire();
  19.  
  20.             button.spellID = buffID;
  21.             button.cd:SetCooldown(expires - duration, duration);
  22.             button.icon:SetTexture(icon);
  23.             button.count:SetText((count and count > 1) and count or "");
  24.  
  25.             button:Show();
  26.  
  27.             if prevButton then
  28.                 button:SetPoint("LEFT", prevButton, "RIGHT", gap, 0);
  29.             else
  30.                 button:SetPoint("LEFT");
  31.             end
  32.  
  33.             prevButton = button;
  34.         end
  35.     end
  36.  
  37.     self:SetSize(self.numActiveObjects > 0 and ((size + gap) * self.numActiveObjects) - gap or 0, size);
  38. end

Those auraIDs are all "Unstable Affliction (UA)" of Affliction Warlock.

233490 / 233496 / 233497 / 233498 / 233499

The problem is since I am passing a spellName as an argument of UnitDebuff() function, casting UA once will generate five buttons at the same time as they all have same names, but different id

To track a specific UA debuff, I guess I should pass an index of an aura as an argument rather than a name, but looping through all debuffs sounds inefficient to me.
  Reply With Quote
05-12-17, 01:20 AM   #23
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Do it the other way around, cycle through all target debuffs that are applied by you and match their IDs against UAs' IDs o_O

IIRC, unit can have up to 40(?) debuffs, might be wrong here...

-- edit #1

I should get some coffee...

To track a specific UA debuff, I guess I should pass an index of an aura as an argument rather than a name, but looping through all debuffs sounds inefficient to me.
Do exactly that Just use `break`s to stop the for-loop if you need...
__________________

Last edited by lightspark : 05-12-17 at 01:25 AM.
  Reply With Quote
05-12-17, 02:30 AM   #24
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by lightspark View Post
-- edit #1

I should get some coffee...



Do exactly that Just use `break`s to stop the for-loop if you need...
Hi lightspark ,

I was considering something like...

Lua Code:
  1. function UpdateDebuff(self)
  2.     self:ReleaseAll();
  3.  
  4.     local prevButton;
  5.     for i, auraID in pairs(auraIDList) do
  6.         for j = 1, 40 do
  7.             local _, _, icon, count, _, duration, expires, _, _, _, spellID = UnitDebuff("target", j, "PLAYER");
  8.            
  9.             if auraID == spellID then
  10.                 -- blah blah blah
  11.  
  12.                 break;
  13.             end
  14.         end
  15.     end
  16. end

But...

(1) What if my spell doesn't get included within those 40 debuffs?

(2) Would there be a variable that stores number of unit's (not only target's, but for others' as well) buff/debuff?

I mean something like BUFF_ACTUAL_DISPLAY/DEBUFF_ACTUAL_DISPLAY for player.

(3) I tried to refer aura element of oUF, but.............. meh... guess it's too complex for me

Last edited by Layback_ : 05-12-17 at 04:01 AM.
  Reply With Quote
05-12-17, 03:48 AM   #25
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Drycoded, haven't tested anything...

Lua Code:
  1. local IDs = {
  2.     [233490] = true,
  3.     [233496] = true,
  4.     [233497] = true,
  5.     [233498] = true,
  6.     [233499] = true,
  7. }
  8.  
  9. local UAs = {}
  10.  
  11. local function UpdateDebuff(self)
  12.     self:ReleaseAll()
  13.  
  14.     for i = 1, 40 do
  15.         local _, _, icon, count, _, duration, expires, _, _, _, spellID = UnitDebuff("target", i, "PLAYER")
  16.  
  17.         -- if there's no spellID it means there's less than 40 auras
  18.         if not spellID then
  19.             break
  20.         end
  21.  
  22.         -- search for UAs
  23.         if IDs[spellID] and duration and duration >= 0 then
  24.             UAs[#UAs + 1] = {
  25.                 id = spellID,
  26.                 icon = icon,
  27.                 count = count or 1,
  28.                 start = expires - duration,
  29.                 duration = duration,
  30.             }
  31.         end
  32.     end
  33.  
  34.     -- do something w/ present auras
  35.     local prevButton
  36.  
  37.     for i = 1, #UAs do
  38.         local info = UAs[i]
  39.         local button = self:Acquire()
  40.  
  41.         button.spellID = info.id
  42.         button.cd:SetCooldown(info.start, info.duration)
  43.         button.icon:SetTexture(info.icon)
  44.         button.count:SetText(info.count > 1 and info.count or "")
  45.  
  46.         if prevButton then
  47.             button:SetPoint("LEFT", prevButton, "RIGHT", gap, 0)
  48.         else
  49.             button:SetPoint("LEFT")
  50.         end
  51.  
  52.         button:Show()
  53.  
  54.         prevButton = button
  55.  
  56.         UAs[i] = nil
  57.     end
  58.  
  59.     self:SetSize(self.numActiveObjects > 0 and ((size + gap) * self.numActiveObjects) - gap or 0, size)
  60. end

Originally Posted by Layback_ View Post
(1) What if my spell doesn't get included within those 40 debuffs?
Highly unlikely O_o

Originally Posted by Layback_ View Post
(2) Would there be a variable that stores number of unit's (not only target's, but for others' as well) buff/debuff?

I mean something like BUFF_ACTUAL_DISPLAY/DEBUFF_ACTUAL_DISPLAY for player.
IIRC, nope...
__________________

Last edited by lightspark : 05-12-17 at 04:03 AM.
  Reply With Quote
05-13-17, 03:02 AM   #26
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Hi again,

(1) I guess the example slightly is limited (focused I mean) to Unstable Affliction (UA). Of course, I know that example is just an example and I should modify bits to make it generic, but, hm...... I don't know

(2) What if the a nth debuff on "target" is not "player's" while (n+1)th debuff is?

Last edited by Layback_ : 05-13-17 at 03:18 AM.
  Reply With Quote
05-13-17, 03:23 AM   #27
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by Layback_ View Post
(1) I guess the example is limited to Unstable Affliction (UA). Of course, I know that example is just an example and I should modify bits to make it generic, but, hm...... I don't know
Just add other spellIDs to IDs table then o_O I don't see what's the problem...

Originally Posted by Layback_ View Post
(2) What if the a nth debuff on "target" is not "player's" while (n+1)th debuff is?
Eh? You don't understand how UnitAura's (that includes UnitBuff/UnitDebuff) filter works...

Lua Code:
  1. UnitDebuff("target", i, "PLAYER")

W/ "PLAYER" as a filter you'll be getting ONLY debuffs that were applied by the player. It's a separate pre-filtered list of auras, there's no gaps, its indices aren't related to anything.

For example, this code:
Lua Code:
  1. /run for i = 1, 40 do print(i, UnitBuff("player", i, "PLAYER|RAID")) end

will return this on my paladin:
Lua Code:
  1. 1 Greater Blessing of Kings  135993 0 nil 3600 16015.356 player false false 203538 true false true false 1 89847 89848 0
  2. 2 Greater Blessing of Wisdom  135912 0 nil 3600 16016.726 player false false 203539 true false true false 1

whereas actual buff list look like this:
Lua Code:
  1. /run for i = 1, 40 do print(i, UnitBuff("player", i)) end

Lua Code:
  1. 1 Sign of the Warrior  1450455 0 nil 0 0 player false false 225787 false false true false 1
  2. 2 Fel Focus  134924 0 nil 4500.005 14209.837 player false false 242551 false false true false 1
  3. 3 Mana Divining Stone  134423 0 nil 0 0 player false false 227723 false false true false 1
  4. 4 Greater Blessing of Kings  135993 0 nil 3600 16015.414 player false false 203538 true false true false 1 89847 89848 0
  5. 5 Greater Blessing of Wisdom  135912 0 nil 3600 16016.726 player false false 203539 true false true false 1
  6. 6 Blessing of the Ashbringer  1109508 0 nil 0 0 player false false 242981 false false true false 1
  7. 7 March of the Highlord  589117 0 Magic 300 13282.648 nil false false 225455 false false false false 1
__________________

Last edited by lightspark : 05-13-17 at 03:30 AM.
  Reply With Quote
05-13-17, 03:49 AM   #28
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by lightspark View Post
Eh? You don't understand how UnitAura's (that includes UnitBuff/UnitDebuff) filter works...

Lua Code:
  1. UnitDebuff("target", i, "PLAYER")

W/ "PLAYER" as a filter you'll be getting ONLY debuffs that were applied by the player. It's a separate pre-filtered list of auras, there's no gaps, its indices aren't related to anything.
Holy.......................................

I thought giving a filter "PLAYER" lets the UnitAura to internally check if the caster was "player" or not.

Didn't realize that it would ignore all others from the scratch.

This makes more sense now +_+!!

It also cleared up the first point, so please ignore that

Last edited by Layback_ : 05-13-17 at 03:55 AM.
  Reply With Quote
05-13-17, 12:06 PM   #29
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://wowprogramming.com/docs/api/UnitAura
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-13-17, 11:53 PM   #30
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Seerah View Post
Haha !!

Definitely didn't pay attention to word "Query"

Last edited by Layback_ : 05-14-17 at 02:08 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How could this be written neater?

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