Thread Tools Display Modes
12-01-14, 06:08 AM   #1
Sylen
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 50
Arena Trinket Script Skirmish Problem

Hey there. I am playing with default UI and mostly arenas. Since the blizz UI hasn't got an enemy trinket tracker implemented i am using a script i found on Arenajunkies.
Although it works fine there is a small annoying problem when playing skirmishes. After you finish a skirmish and queue directly for another one it seems the cooldown timer does not reset properly.
Code:
-- Arena trinkets tracker
trinkets = {}
local arenaFrame, trinket
for i = 1, 5 do
        arenaFrame = "ArenaEnemyFrame"..i
        trinket = CreateFrame("Cooldown", arenaFrame.."Trinket", ArenaEnemyFrames)
        trinket:SetPoint("TOPRIGHT", arenaFrame, 30, -6)
        trinket:SetSize(24, 24)
        trinket.icon = trinket:CreateTexture(nil, "BACKGROUND")
        trinket.icon:SetAllPoints()
        trinket.icon:SetTexture("Interface\\Icons\\inv_jewelry_trinketpvp_01")
        trinket:Hide()
        trinkets["arena"..i] = trinket
end

local events = CreateFrame("Frame")
function events:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
        if not trinkets[unitID] then
                return
        end
        if spellID == 59752 or spellID == 42292 then
                CooldownFrame_SetTimer(trinkets[unitID], GetTime(), 120, 1)
                SendChatMessage("Trinket used by: "..GetUnitName(unitID, true), "PARTY")
        end
end

function events:PLAYER_ENTERING_WORLD()
        local _, instanceType = IsInInstance()
        if instanceType == "arena" then
                self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
        elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
                self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
                for _, trinket in pairs(trinkets) do
                        trinket:SetCooldown(0, 0)
                        trinket:Hide()
                end
        end
end

 SLASH_TESTAEF1 = "/testaef"
 SlashCmdList["TESTAEF"] = function(msg, editBox)
     if not IsAddOnLoaded("Blizzard_ArenaUI") then
         LoadAddOn("Blizzard_ArenaUI")
     end
     ArenaEnemyFrames:Show()
	 for i=1,3 do _G["ArenaEnemyFrame"..i]:Show()_G["ArenaEnemyFrame"..i.."CastingBar"]:Show()end--_G["ArenaEnemyFrame"..i.."PetFrame"]:Show()end
     local arenaFrame
     for i = 1, 3 do
         arenaFrame = _G["ArenaEnemyFrame"..i]		
         arenaFrame.classPortrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
         arenaFrame.classPortrait:SetTexCoord(unpack(CLASS_ICON_TCOORDS["HUNTER"]))
         arenaFrame.name:SetText("Pewpewpew")
         arenaFrame:Show()        		
         CooldownFrame_SetTimer(trinkets["arena"..i], GetTime(), 120, 1)		
     end
 end
events:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
events:RegisterEvent("PLAYER_ENTERING_WORLD")
  Reply With Quote
12-01-14, 08:42 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem is here:
Code:
function events:PLAYER_ENTERING_WORLD()
        local _, instanceType = IsInInstance()
        if instanceType == "arena" then
                self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
        elseif self:IsEventRegistered("UNIT_SPELLCAST_SUCCEEDED") then
                self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
                for _, trinket in pairs(trinkets) do
                        trinket:SetCooldown(0, 0)
                        trinket:Hide()
                end
        end
end
It's only resetting if you go from arena --> not arena, not if you go from arena --> arena. Since you're probably not reloading your UI in the middle of arena matches, you can just reset every time the event fires:
Code:
function events:PLAYER_ENTERING_WORLD()
        local _, instanceType = IsInInstance()
        if instanceType == "arena" then
                self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
        else
                self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
        end
        for _, trinket in pairs(trinkets) do
                trinket:SetCooldown(0, 0)
                trinket:Hide()
        end
end
Apart from that, though, please put a "local" in front of the "trinkets = {}" line at the top. Otherwise you're putting the generically-named variable "trinkets" in the global namespace, where it's likely to collide with leaked globals from other addons or even the default UI.

If you need/want a global variable for some other purpose, still make "trinkets" local and add a global pointer to it with a more distinct name:
Code:
local trinkets = {} -- keep the generic name local
MyAddonName_Trinkets = trinkets -- export it to a specifically named global
__________________
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

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Arena Trinket Script Skirmish Problem


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