View Single Post
04-09-14, 06:49 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Now ignores NPCs and enemy players/pets, and won't error on partially-loaded units (eg. players in the process of joining your group). Let me know if you're actually seeing "UNKNOWN" on frames and, if so, under what circumstances.

Code:
local CUSTOM_PLAYER_TEXT = "谷歌"
local CUSTOM_PET_TEXT = "PET"

local function SetCustomName(unit, fontString)
	if UnitIsUnit(unit, "player") then
		fontString:SetText(CUSTOM_PLAYER_TEXT)
	elseif UnitIsPlayer(unit) then
		fontString:SetText(strupper(UnitClass(unit) or UNKNOWN))
	else
		fontString:SetText(CUSTOM_PET_TEXT)
	end
end

hooksecurefunc("UnitFrame_Update", function(frame, isParty)
	if frame.name then
		local unit = frame.overrideName or frame.unit
		if UnitPlayerControlled(unit) and UnitIsFriend(unit, "player") then
			SetCustomName(unit, frame.name)
		end
	end
end)

hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	SetCustomName(frame.unit, frame.name)
end)
Added/changed parts highlighted in green.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote