Thread Tools Display Modes
10-27-10, 12:43 PM   #1
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
Determine the player's role via their spec

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
  Reply With Quote
10-27-10, 01:53 PM   #2
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
well the only thing that seems off to me is that the priest instantly returns healer, there are shadowpriests

and warrior has 2 times where it can return tank?

other than that, seems alright to me

if you think the function is being called to often, after the first one you can call

self:UnregisterEvent("PLAYER_TALENT_UPDATE")

but if they have dual spec and respec, you'd need to be able to determine that.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-27-10, 02:04 PM   #3
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
Thanks for the tips mate. I've updated the code to reflect 4.0 and made the changes you pointed out. =)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Determine the player's role via their spec


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