WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How could this be written neater? (https://www.wowinterface.com/forums/showthread.php?t=55376)

syncrow 05-09-17 09:19 AM

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)

Layback_ 05-12-17 12:56 AM

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 :confused:

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.

lightspark 05-12-17 01:20 AM

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...

Quote:

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 :D Just use `break`s to stop the for-loop if you need...

Layback_ 05-12-17 02:30 AM

Quote:

Originally Posted by lightspark (Post 323339)
-- edit #1

I should get some coffee...



Do exactly that :D 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 :(

lightspark 05-12-17 03:48 AM

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

Quote:

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

Highly unlikely O_o

Quote:

Originally Posted by Layback_ (Post 323341)
(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...

Layback_ 05-13-17 03:02 AM

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 :confused:

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

lightspark 05-13-17 03:23 AM

Quote:

Originally Posted by Layback_ (Post 323360)
(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 :confused:

Just add other spellIDs to IDs table then o_O I don't see what's the problem...

Quote:

Originally Posted by Layback_ (Post 323360)
(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

Layback_ 05-13-17 03:49 AM

Quote:

Originally Posted by lightspark (Post 323361)
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 :banana:

Seerah 05-13-17 12:06 PM

http://wowprogramming.com/docs/api/UnitAura ;)

Layback_ 05-13-17 11:53 PM

Quote:

Originally Posted by Seerah (Post 323368)

Haha :)!!

Definitely didn't pay attention to word "Query" :p


All times are GMT -6. The time now is 10:34 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI