View Single Post
03-01-14, 05:47 PM   #1
wiMp
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 10
:SetTexture() only works for abilities on actionbar.

I've been working on an AddOn that replaces the weapon icons temporary enchant frame to the icons of the weapon enchant.

The AddOn works fine, the only issue I've run into, is that I can only use the textures if I have the icons on my actionbar.

This is the code I've been working with:
Lua Code:
  1. local f = CreateFrame('GameTooltip', 'tempEnchantScanner', UIParent, 'GameTooltipTemplate')
  2. f:SetOwner(UIParent, 'ANCHOR_NONE')
  3.  
  4. local _, playerClass = UnitClass("player")
  5.  
  6. local tempEnchants
  7. if playerClass == "SHAMAN" then
  8.     tempEnchants = {
  9.         ["Earthliving"] = GetSpellTexture(51730),
  10.         ["Flametongue"] = GetSpellTexture(8024),
  11.         ["Frostbrand"]  = GetSpellTexture(8033),
  12.         ["Rockbiter"]   = GetSpellTexture(8017),
  13.         ["Windfury"]    = GetSpellTexture(8232),
  14.     }
  15. elseif playerClass == "ROGUE" then
  16.     tempEnchants = {
  17.         ["Mind-Numbing Poison"] = GetSpellTexture(5761),
  18.         ["Crippling Poison"]    = GetSpellTexture(3408),
  19.         ["Paralytic Poison"]    = GetSpellTexture(108215),
  20.         ["Leeching Poison"]     = GetSpellTexture(108211),
  21.         ["Deadly Poison"]       = GetSpellTexture(2823),
  22.         ["Wound Poison"]        = GetSpellTexture(8679),
  23.     }
  24. end
  25.  
  26.  
  27. local function getTempEnchantTextureOnSlotId(slotid)
  28.     local found
  29.     f:SetInventoryItem("player",slotid)
  30.     for i = 1,f:NumLines() do
  31.         local text = _G["tempEnchantScannerTextLeft"..i]:GetText()
  32.             for k,v in pairs(tempEnchants) do
  33.             if strmatch(text,k) then
  34.                 found = v
  35.             end
  36.         end
  37.     end
  38.     return found
  39. end
  40.  
  41.  
  42. hooksecurefunc('TemporaryEnchantFrame_Update', function(self,...)
  43.     local mh,_,_,oh = ...
  44.     local mhtexture = getTempEnchantTextureOnSlotId(16)
  45.     local ohtexture = getTempEnchantTextureOnSlotId(17)
  46.    
  47.     if mh and oh and mhtexture and ohtexture then
  48.         TempEnchant2Icon:SetTexture(mhtexture)
  49.         TempEnchant1Icon:SetTexture(ohtexture)
  50.     elseif mh and not oh and mhtexture then
  51.         TempEnchant1Icon:SetTexture(mhtexture)
  52.     elseif oh and not mh and ohtexture then
  53.         TempEnchant1Icon:SetTexture(ohtexture)
  54.     end
  55. end)

I'm relatively new at writing AddOns, so any tips or criticism is appreciated.
  Reply With Quote