View Single Post
03-12-14, 09:39 AM   #16
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
UnitGUID can return nil so you need to account for that:
Code:
local function UnitIsPet(unit)
    local GUID = UnitGUID(unit)
    return GUID and tonumber(GUID:sub(5, 5), 16) % 8 == 4
end
UnitGUID returns nil when the game first loads so probably best to wait for a PLAYER_ENTERING_WORLD event to use it. If that's not an option you could do something more generic:
Code:
local function UnitIsPet(unit)
    return UnitPlayerControlled(unit) and not UnitIsPlayer(unit)
end
Your code:
Code:
if UnitCreatureType("beast") or UnitCreatureType("demon") or UnitCreatureType("elemental") then
    self.name:SetTextColor(1, 1, 1)
else
    self.name:SetTextColor(color.r, color.g, color.b)
end
doesn't work because UnitCreatureType takes unitIDs like 'target' and returns string like 'Beast' or 'Demon'. It wouldn't work the way you want anyway since it would return 'Beast' for a druid in bear or cat form.
  Reply With Quote