How to tell if a unit is a 'tank'?

UI and Macro
Post Limit:
Is there a way to tell (from a lua script) if a unit is a tank? I am currently just checking their max health, but that's not always 100%. Is there a way to do a UnitGetSpec() or something like that?

Thanks
http://www.wowpedia.org/API_UnitGroupRolesAssigned

or

http://www.wowpedia.org/API_GetInspectSpecialization
http://www.wowpedia.org/API_GetSpecializationRoleByID
Hmm well roled assigned only works IF a player has selected a rold. And for some reason getinspectspec is always returning 0 when I use it on myself (with a unit of "player")... is it bugged?
Can anyone else confirm that 'GetInspectSpecialization("player")' always returns 0? On wowpedia it says "This function may return 0 if the server hasn't sent the requested inspect information needed yet.". Zuh?

I just wanna know if a party/raid member is a tank :(
GetInspectSpecialization is for getting a spec on a unit that's been inspected with InspectUnit or NotifyInspect.

The sentence means "If the results from an inspection aren't available, this will return 0."

So your addon would register for INSPECT_READY, inspect a unit, and in response to INSPECT_READY you can GetInspectSpecialization(unit). And then inspect the next unit if you wanted to check everyone.

Remember that you can't inspect anyone unless they're in range. You can use CheckInteractDistance(unit) to see if they're close enough.
This will go through every group member (in inspect range) and print their spec.
local f=InS or CreateFrame("Frame","InS")
local specs={
-- from very helpful table at http://www.wowpedia.org/API_GetInspectSpecialization
[250]="Blood", [251]="Frost", [252]="Unholy", [102]="Balance", [103]="Feral",
[104]="Guardian", [105]="Restoration", [253]="Beast Mastery", [254]="Marksmanship",
[255]="Survival", [62]="Arcane", [63]="Fire", [64]="Frost", [268]="Brewmaster",
[270]="Mistweaver", [269]="Windwalker", [65]="Holy", [66]="Protection",
[67]="Retribution", [256]="Discipline", [257]="Holy", [258]="Shadow",
[259]="Assassination", [260]="Combat", [261]="Subtlety", [262]="Elemental",
[263]="Enhancement", [264]="Restoration", [265]="Affliction", [266]="Demonology",
[267]="Destruction", [71]="Arms", [72]="Fury", [73]="Protection",
[0]="Unknown Spec"
}
-- returns a unit from a number 0=player 1-40=raid1-40 or party1-4 (well, 1-5)
local function actualUnit(unitNumber)
if unitNumber==0 then
return "player"
elseif UnitInRaid("player") then
return "raid"..unitNumber
else
return "party"..unitNumber
end
end
f:SetScript("OnEvent",function(self,...)
local unit = actualUnit(f.unit)
print(UnitName(unit),"is a",specs[GetInspectSpecialization(unit)],(UnitClass(unit)))
repeat
-- some units may be out of inspect range, which would never trigger an
-- INSPECT_READY. Increment unit counter until we find someone in range
f.unit = f.unit+1
unit = actualUnit(f.unit)
if CheckInteractDistance(unit,1) then
NotifyInspect(unit) -- and inspect them
return
end
until f.unit>GetNumGroupMembers()
self:UnregisterEvent("INSPECT_READY")
end)
f:RegisterEvent("INSPECT_READY")
f.unit = 0 -- arbitrary unit counter, starting at 0 for "player"
NotifyInspect(actualUnit(f.unit))

Join the Conversation