WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SpellSteal script for rogue (https://www.wowinterface.com/forums/showthread.php?t=49750)

plopek 08-19-14 04:39 PM

SpellSteal script for rogue
 
Hello dear community:)

I have a question about how to modify script below to show flashy icons only on those spellIDs
(49016,52610,5229,34692,19574,18499)

Code:

if UnitClass("player")=="Rogue"then
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
        for i = 1, MAX_TARGET_BUFFS do
                _, _, ic, _, dT = UnitBuff(s.unit, i)
                if(ic and (not s.maxBuffs or i<=s.maxBuffs)) then
                        fS=_G[s:GetName()..'Buff'..i..'Stealable']
                        if(UnitIsEnemy(PlayerFrame.unit, s.unit) and dT=='Magic') then
                                fS:Show()
                        else
                                fS:Hide()
                        end
                end
        end
end)
end

Thanks you for any help!

Clamsoda 08-20-14 01:47 AM

Dry coded, untested. I am not sure what the arguments are for TargetFrame_UpdateAuras, they could help in optimizing the code; I am also unsure as to how "not s.maxBuffs or i<=s.maxBuffs" was intended to help, it seems a bit useless, but I left it.

Lua Code:
  1. local _, playerClass = UnitClass("player")
  2. if (not playerClass == "ROGUE") then return end
  3.  
  4. local spellIDs = {
  5.     49016 = true,
  6.     52610 = true,
  7.     5229  = true,
  8.     34692 = true,
  9.     19574 = true,
  10.     18499 = true
  11. }
  12.  
  13. hooksecurefunc("TargetFrame_UpdateAuras", function(self)
  14.     for i = 1, MAX_TARGET_BUFFS do
  15.         local _, _, icon, _, debuffType, _, _, _, _, _, spellID = UnitBuiff(self.unit, i)
  16.  
  17.         if (icon) and (not self.maxBuffs or i <= self.maxBuffs) and (spellIDs[spellID]) then
  18.             local stealableBorder = _G[self:GetName().."Buff"..i.."Stealable"]
  19.  
  20.             if UnitIsEnemy("player", "target") and (debuffType == "Magic") then
  21.                 stealableBorder:Show()
  22.             else
  23.                 stealableBorder:Hide()
  24.             end
  25.         end
  26.     end
  27. end)

Phanx 08-20-14 03:01 AM

I didn't test it either, but some observations
  • You need to enclose those spell IDs in brackets to use them as table keys.
  • Instead of "if not A == B then" you can just do "if A ~= B then".
  • Since the enemy status of a unit won't change in the middle of scanning their buffs, and you only want to add the borders on enemies, just check UnitIsEnemy first, and don't bother scanning the buffs if the target isn't an enemy.
  • The maxBuffs check is sort of required (since the target can have more debuffs on them than are displayed) but it's simpler to just check whether the stealable texture object exists.
Here's how I'd do it:
Code:

local _, playerClass = UnitClass("player")
if playerClass ~= "ROGUE" then return end

local spellIDs = {
        [49016] = true,
        [52610] = true,
        [5229]  = true,
        [34692] = true,
        [19574] = true,
        [18499] = true
}

hooksecurefunc("TargetFrame_UpdateAuras", function(self)
        local unit = self.unit
        if not UnitIsEnemy(unit, "player") then return end

        local name = self:GetName()
        for i = 1, MAX_TARGET_BUFFS do
                local _, _, _, debuffType, _, _, _, _, _, id = UnitBuff(unit, i)
                if not id then return end

                local stealable = _G[name.."Buff"..i.."Stealable"]
                if not stealable then return end

                stealable:SetShown(debuffType == "Magic" and spellIDs[id])
        end
end)


plopek 08-20-14 03:07 AM

Thanks a lot for replies, however only Phanx method works:D

Clamsoda 08-20-14 03:23 PM

Thanks Phanx <3

jeruku 08-20-14 07:28 PM

If you want you can use the fact that the UpdateAuraPositions(at tail-end of UpdateAuras) loops through the buffs as well. Works great for hiding or repositioning those squirmy target de/buffs and adding timers.

Code:

hooksecurefunc('TargetFrame_UpdateBuffAnchor', function(self, name, index, ...)
        if name == 'TargetFrameBuff' then
                local _, _, _, debuffType, _, _, _, _, _, id = UnitBuff(unit, index)
                if not id then return end

                local stealable = _G[name .. "Buff" .. index .."Stealable"]
                if not stealable then return end

                stealable:SetShown(debuffType == "Magic" and spellIDs[id])
        end
end)



All times are GMT -6. The time now is 10:30 PM.

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