View Single Post
09-22-15, 04:40 AM   #3
Gryns
A Deviate Faerie Dragon
 
Gryns's Avatar
Join Date: Sep 2015
Posts: 11
Hey Phanx, thanks for the quick reply.

Tried both your scripts, but both failed to work. I put them both in separate addons, and added the corpse loot pattern to your first script.

Here's what I used for the tooltips.

Code:
 local ownerStrings = {
	["(%s)'s Companion"] = "%s's Companion",
	["(%s)'s Guardian"] = "%s's Guardian",
	["(%s)'s Minion"] = "%s's Minion",
	["(%s)'s Pet"] = "%s's Pet",
	["(%s)'s Totem"] = "%s's Totem",
  	["Loot: (%s)"] = "Loot: %s",
}

local shortVersions = setmetatable({}, {
	__mode = "kv",
	__index = function(t, k)
		for search, replace in pairs(ownerStrings) do
			local owner = strmatch(text, search)
			if owner then
				local v = format(replace, (gsub(owner, "%-.+", "")))
				t[k] = v
				return v
			end
		end
		t[k] = false
	end
})

GameTooltip:HookScript("OnTooltipSetUnit", function(tooltip)
	local _, unit = tooltip:GetUnit()
	if UnitIsBattlePet(unit)
	or (UnitIsDead(unit) and not UnitPlayerControlled(unit)) then
		for i = 2, tooltip:NumLines() do -- no need to check line 1, it's always the unit's name
			local line = _G["GameTooltipTextLeft"..i]
			local text = shortVersions[line:GetText() or ""]
			if text then
				line:SetText(text)
			end
		end
	end
end)
And this is what I used for the chat.

Code:
 local orig_AddMessage = {}

local AddMessage = function(frame, message, ...)
	if type(message) == "string" then
		message = gsub("|Hplayer:(.-)|h%[([^%-]+)%-[^|]+([^%]]*)%]|h", "|Hplayer:%1|h[%2%3]|h")
		return orig_AddMessage(frame, message, ...)
	end
end

for i = 1, NUM_CHAT_WINDOWS do
	local f = _G["ChatFrame" .. i])
	orig_AddMessage[f] = f.AddMessage
	f.AddMessage = AddMessage
end

local orig_FCF_OpenTemporaryWindow = FCF_OpenTemporaryWindow
FCF_OpenTemporaryWindow = function(...)
	local f = orig_FCF_OpenTemporaryWindow(...)
	orig_addMessage[f] = f.AddMessage
	f.AddMessage = AddMessage
	return f
end
I didn't edit this one at all.

This is what I used for chat before, which removed the suffixes from the chat channels, but not from the whispers.

Code:
 local a = getmetatable(DEFAULT_CHAT_FRAME).__index.AddMessage
getmetatable(DEFAULT_CHAT_FRAME).__index.AddMessage = function(s,t,...)
	return a(s,t:gsub("|Hplayer:(.-)|h%[([^-]+).-%]","|Hplayer:%1|h[%2]"),...)	
end
I used http://addon.bool.no/ to convert both scripts to addons. Is there anything I forgot or did wrong?

Thanks again,

Gryns
__________________
-- Live like a King, laugh like his Jester. --
  Reply With Quote