Hey all!
I'm trying to determine the best method to determine the players current role based upon their specs. Below is the code I'm currently using, which needs to be updated for 4.0, but I'm curious if there is a better way to do this? What I'm doing now seems... bulky, especially since this function is ran quite a bit while the user is playing (I do make an attempt to save a global variable so it's ran as little as possible).
Code:
local _, class = UnitClass("player")
Pandorum_SPEC = nil
local f = CreateFrame("Frame", "TalentSpecUpdate")
f:RegisterEvent("PLAYER_TALENT_UPDATE")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript('OnEvent', function() Pandorum_SPEC = Pandorum:ReadTalentSpec() end)
function Pandorum:ReadTalentSpec()
if class == "DEATHKNIGHT" then
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(1, 3)
if currentRank > 0 then return "tank" else return "melee" end
elseif class == "DRUID" then
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(2, 5)
if currentRank > 0 then return "tank" end
name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(2, 4)
if currentRank > 0 then return "melee" end
name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(1, 1)
if currentRank > 0 then return "spell_dps" end
return "healer"
elseif class == "HUNTER" then
return "ranged"
elseif class == "PRIEST" then
return "healer"
elseif class == "WARLOCK" or class == "MAGE" then
return "spell_dps"
elseif class == "PALADIN" then
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(2, 2)
if currentRank > 0 then return "tank" end
name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(3, 2)
if currentRank > 0 then return "melee" end
return "healer"
elseif class == "ROGUE" then
return "melee"
elseif class == "SHAMAN" then
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(2, 1)
if currentRank > 0 then return "melee" end
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(1, 2)
if currentRank > 0 then return "spell_dps" end
return "healer"
elseif class == "WARRIOR" then
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(3, 2)
if currentRank > 0 then return "tank" end
local name, iconPath, tier, column, currentRank, maxRank, isExceptional, meetsPrereq = GetTalentInfo(3, 5)
if currentRank > 0 then return "tank" end
return "melee"
end
end