Thread Tools Display Modes
08-19-14, 04:39 PM   #1
plopek
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Aug 2014
Posts: 18
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!
  Reply With Quote
08-20-14, 01:47 AM   #2
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
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)

Last edited by Clamsoda : 08-20-14 at 01:57 AM.
  Reply With Quote
08-20-14, 03:01 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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)
__________________
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, 03:07 AM   #4
plopek
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Aug 2014
Posts: 18
Thanks a lot for replies, however only Phanx method works

Last edited by plopek : 08-20-14 at 03:48 AM.
  Reply With Quote
08-20-14, 03:23 PM   #5
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Thanks Phanx <3
  Reply With Quote
08-20-14, 07:28 PM   #6
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
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)
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SpellSteal script for rogue

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