WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Need help with a text display for Talents (https://www.wowinterface.com/forums/showthread.php?t=42070)

Wimpface 12-10-11 09:29 PM

Need help with a text display for Talents
 
I want this to show my talent spec (i.e 'Elemental', 'Holy' etc) but it won't! So I figured I ****ed up somewhere. This leads me here! :rolleyes:

Code:

--[[
        Based on LynStats
--]]

local addon = CreateFrame("Frame", nil, UIParent)

-- CONFIG --
-- frame
local frame_anchor = "BOTTOM"
local frame_x = 0
local frame_y = 5
-- text
local text_anchor = "BOTTOM"
local font = "Fonts\\ARIALN.TTF"
local size = 12
local classcolors = true -- true or false

if classcolors == true then
        color = CUSTOM_CLASS_COLORS[select(2, UnitClass("player"))]
else
        color = { r=0, g=0.8, b=1 } -- own textcolor
end

-- END OF CONFIG --

local text = addon:CreateFontString(nil, 'OVERLAY')
for i = 1, GetNumTalentTabs() do
        local _, talent = GetTalentTabInfo(i)
end

function addon:event()
        if (event == 'PLAYER_ENTERING_WORLD') then
                text:SetText(talent)
        elseif (event == 'ACTIVE_TALENT_GROUP_CHANGED') then
                text:SetText(talent)
        end
end

text:SetPoint(frame_anchor, frame_x, frame_y)
text:SetFont(font, size)
text:SetTextColor(color.r, color.g, color.b)

See anything wrong? I've gone over it a few times and I see nothing wrong at all.

Taryble 12-10-11 10:18 PM

From the looks of it, your script always returns the highest talent tab's info (1 if you haven't bought dual-spec, 2 if you have).

You may want to use GetActiveTalentGroup() to find out WHICH talents are active, and then query GetTalentTabInfo() with the result from it.

Wimpface 12-10-11 10:29 PM

Quote:

Originally Posted by Taryble (Post 249127)
From the looks of it, your script always returns the highest talent tab's info (1 if you haven't bought dual-spec, 2 if you have).

You may want to use GetActiveTalentGroup() to find out WHICH talents are active, and then query GetTalentTabInfo() with the result from it.

Like this?
Code:

if GetActiveTalentGroup() == 1 then
        for i = 1, GetNumTalentTabs() do
                local _, name = GetTalentTabInfo(i)
        end
        GetTalentTabInfo(1, name)
elseif GetActiveTalentGroup() == 2 then
        for i = 1, GetNumTalentTabs() do
                local _, name = GetTalentTabInfo(i)
        end
        GetTalentTabInfo(2,  name)
end


Seerah 12-10-11 11:02 PM

You're using GetTalentTabInfo incorrectly. The argument it takes is a talent tab number (back when they were tabs, now it's just left to right). Also, in your original script, you were just rewriting the variable name each time through your loop. GetNumTalentTabs always returns 3 (though it will return 4 for druids in 5.0) since we have 3 talent trees.

In addition, your variable name is nil when you try to use it in GetTalentTabInfo() since you made it a variable local only to the scope of your loop. (Sidenote: when doing this, it creates a brand new local variable called name 3 times the loop runs.)

Finally, you're not actually checking your talents when your events fire. Just resetting the text. Use "PLAYER_LOGIN" rather than "PLAYER_ENTERING_WORLD". It only fires once, whereas PEW fires on each loading screen.

As Taryble said, you need to call GetActiveTalentGroup() to see if you are in your primary spec or secondary spec (if dual specced). Then you need to pass that information to GetPrimaryTalentTree() to see which tab/tree you have selected as your 'spec' (ie, 2 if you're Marksman for a hunter). Since this is the tab/tree number, you pass *that* to GetTalentTabInfo() for its name. (Sidenote: if down the road you also want to see how many points are spent in this tree, you will need to tell it which spec you are looking at. You'd probably want to save the return of GetActiveTalentGroup() to a variable at this point.)

This can be done all at once, rather than cluttering your code with variables (unless you need these variables later for something else).

I'm going to assume that what you have in the OP is not the entirety of your code, so I'll just post the relevant bits.

lua Code:
  1. local function CheckTalents()
  2.     local _, talents = GetTalentTabInfo(GetPrimaryTalentTree(false, false, GetActiveTalentGroup()))
  3.     return talents
  4. end
  5.  
  6. function addon:event()
  7.     text:SetText(CheckTalents())
  8. end


/edit: removed the local variables from the main chunk, since I make the CheckTalents() function just return the result to the :SetText() call directly.

Wimpface 12-10-11 11:05 PM

Interesting. Thank you so much! :)<3

Wimpface 12-10-11 11:47 PM

A new problem arises!

It works as it's supposed to except for when you log in, I assume it's because the information isn't available when PLAYER_LOGIN fires, PLAYER_ENTERING_WORLD doesn't work either. It works after the first reload, but not before that.

Full code:
Code:

--[[
        Based on LynStats
--]]

local addon = CreateFrame("Frame", nil, UIParent)
addon:RegisterEvent('PLAYER_LOGIN')
addon:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')

-- CONFIG --
-- frame
local frame_anchor = "BOTTOM"
local frame_x = 0
local frame_y = 5
-- text
local text_anchor = "BOTTOM"
local font = "Fonts\\ARIALN.TTF"
local size = 12
local classcolors = true -- true or false
local color = CUSTOM_CLASS_COLORS[select(2, UnitClass("player"))]

-- END OF CONFIG --
function addon:new()
        -- frame position
        self:SetPoint(frame_anchor, UIParent, frame_anchor, frame_x, frame_y)
        self:SetWidth(50)
        self:SetHeight(13)
        -- create fontstring
        text = self:CreateFontString(nil, "OVERLAY")
        -- text style
        text:SetFont(font, size)
        text:SetTextColor(color.r, color.g, color.b)
        text:SetShadowOffset(1, -1)
       
        text:SetPoint(text_anchor, self)
       
        self:RegisterEvent('PLAYER_LOGIN')
        self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
       
        -- update
        self:SetScript("OnEvent", self.event)
end

local talents, _
local function CheckTalents()
    _, talents = GetTalentTabInfo(GetPrimaryTalentTree(false, false, GetActiveTalentGroup()))
    return talents
end
 
function addon:event()
        text:SetText(CheckTalents())
end

addon:new()


Seerah 12-11-11 12:35 AM

See if PLAYER_TALENT_UPDATE fires when that info is ready...

Wimpface 12-11-11 12:39 AM

Quote:

Originally Posted by Seerah (Post 249136)
See if PLAYER_TALENT_UPDATE fires when that info is ready...

Yup, works. Thanks again. All is well! :D


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

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