Thread Tools Display Modes
09-21-15, 03:16 AM   #1
Gryns
A Deviate Faerie Dragon
 
Gryns's Avatar
Join Date: Sep 2015
Posts: 11
Getting rid of realm suffixes

I have been trying to find a solution to something that has been bothering me for a while now. The realm names that you see behind a person's name have been bothering me to no end. i.e. Gryns-Aggrammar. They feel like clutter, and it has been my undying mission to get rid of them everywhere.

With the help of a wide variety of addons and scripts I have removed them from chat, raid frames, and now, thanks to TipTac -tooltips. And even though TipTac removes them from player tooltips, it leaves the realm names in a few other tooltips. Amongst which; in the tooltip for pets and companions (Gryns-Aggramar's Pet/Companion/Minion), and as a loot/dead body tooltip in a party/raid (belongs to Gryns-Aggramar).

Now I've kludged together a solution for the pet/companion tooltips (through hours of experimentation, because I know nothing about LUA code. But I can't find a solution for the loot/dead body tooltip.

Here are the parts of the code that I ruined so it serves my own purpose;

" -- Find NPC Title -- 09.08.22: Should now work with colorblind mode
if (first) and (not u.isPlayer) then
u.title = (isColorBlind and GameTooltipTextLeft3 or GameTooltipTextLeft2):GetText();
if (u.title) and (u.title:find(TT_LevelMatch)) or (u.title:find("-")) then
u.title = nil; "

This is for the pets, it changes the owner line to a class and level line, not ideal, but at least the damn realm name is gone.

" -- BattlePets
elseif (isPetWild or isPetCompanion) then
lineOne[#lineOne + 1] = reaction;
lineOne[#lineOne + 1] = name;
lineInfo[#lineInfo + 1] = " ";
lineInfo[#lineInfo + 1] = cfg.colRace;
local petType = UnitBattlePetType(unit) or 5;
lineInfo[#lineInfo + 1] = name;
if (isPetWild) then
lineInfo[#lineInfo + 1] = " ";
lineInfo[#lineInfo + 1] = UnitCreatureFamily(unit) or UnitCreatureType(unit);
else
if not (petLevelLineIndex) then
for i = 2, gtt:NumLines() do
local gttLineText = _G["GameTooltipTextLeft"..i]:GetText();
if (type(gttLineText) == "string") and (gttLineText:find("-")) then
petLevelLineIndex = i;
break;
end
end
end
lineInfoIndex = petLevelLineIndex or 2;
local expectedLine = 3 + (isColorBlind and 1 or 0);
if (lineInfoIndex > expectedLine) then
GameTooltipTextLeft2:SetFormattedText("%s%s",reaction,u.title);
end
end "

This is for companions and battle pets, again not ideal, because this changes the owner line to the level and name of the pet, and only works if the pet does not have a custom name. But at least the damn realm name is gone.

I was wondering if anyone could help me out with the code, I would like to remove the realm suffix from the pets and companions tooltips and the loot/dead body tooltip.

I don't mind just the player's name, I would just like to get the realm-suffix removed. If that's not possible, then lets remove the whole bloody line.

Thanks in advance,

Gryns.

PS.
There are also a few places where the suffixes still are but if they are possible to remove as well, then by all means, let's get them too. These are the current target floating name, and in chat whispers. These still contain the realm suffixes for some reason.
__________________
-- Live like a King, laugh like his Jester. --
  Reply With Quote
09-22-15, 02:10 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Possibly slightly overengineered, and not actually tested, but this should take care of pets, corpse loot** and any other unit tooltip line patterns you choose to add:
Code:
local ownerStrings = {
	["(%s)'s Companion"] = "%s's Companion",
	["(%s)'s Guardian"] = "%s's Companion",
	["(%s)'s Minion"] = "%s's Companion",
	["(%s)'s Pet"] = "%s's Companion",
	["(%s)'s Totem"] = "%s's Companion",
	-- ** for corpse loot, add the patterns here; I don't know what it looks like offhand
}

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)
This (also not tested) will take care of chat whispers (and all other linked player names in 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
Depending on what you mean by "current target floating name" that may not be possible. If it's the name that is attached to the actual unit model in the 3D game world, addons can't touch or even see that.
__________________
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
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
09-22-15, 08:06 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There's probably an error; I didn't test either in-game. Install Bugger and report back with the errors from each.
__________________
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
09-23-15, 09:26 AM   #5
Gryns
A Deviate Faerie Dragon
 
Gryns's Avatar
Join Date: Sep 2015
Posts: 11
Originally Posted by semlar View Post
Since this is from my addon NoRealm, I figured I'd chime in.

Unless you're running an addon that's interfering with it, or you're talking about battle net whispers (which I don't even think can contain a realm?), that should still be removing the realm name from the chat.

I know Prat was causing issues with the original pattern I was using because of all the junk they added to the player link (mostly class coloring), but that was fixed in the more recent version of the addon than what you posted here.
Hey Semlar, didn't know the script was from your addon, found it in a thread somewhere.

I use BasicChatMods, but even with that disabled it doesn't filter the suffix. Don't get me wrong though, it does remove it from the main chat window, just not when you type. To clarify, when I click on a name in trade chat for instance, it will show "Tell Semlar-Aggramar:" when you are typing in your message, but the conversation itself has the realm suffix removed. I would just like the realm suffix removed in the edit box as well as in the chat window. If that's at all possible, of course.

Originally Posted by Phanx View Post
There's probably an error; I didn't test either in-game. Install Bugger and report back with the errors from each.
I did, and here are the reports.

As for the tooltips. Variations of these showed when mousing over a pet/companion/bodyguard/etc:

Code:
95x TooltipHideRealm\code.lua:17: bad argument #1 to 'strmatch' (string expected, got nil)
[C]:: in function 'strmatch'
TooltipHideRealm\code.lua:17: in function <TooltipHideRealm\code.lua:15>
TooltipHideRealm\code.lua:34: in function <TooltipHideRealm\code.lua:28>
[C]:: ?
[C]:: ?
[C]:: ?

Locals:
t = <table>
k = "Minalla-Silvermoon's Companion"
(for generator) = <function> defined =[C]:-1
(for state) = <table> {
 (%s)'s Minion = "%s's Minion"
 (%s)'s Totem = "%s's Totem"
 (%s)'s Companion = "%s's Companion"
 Loot: (%s) = "Loot : %s"
 (%s)'s Pet = "%s's Pet"
 (%s)'s Guardian = "%s's Guardian"
}
(for control) = "(%s)'s Minion"
search = "(%s)'s Minion"
replace = "%s's Minion"
ownerStrings = <table> {
 (%s)'s Minion = "%s's Minion"
 (%s)'s Totem = "%s's Totem"
 (%s)'s Companion = "%s's Companion"
 Loot: (%s) = "Loot : %s"
 (%s)'s Pet = "%s's Pet"
 (%s)'s Guardian = "%s's Guardian"
}

And variations of these when you moused over a corpse that had loot assigned to a party/raid member:

Code:
82x TooltipHideRealm\code.lua:17: bad argument #1 to 'strmatch' (string expected, got table)
[C]:: in function 'strmatch'
TooltipHideRealm\code.lua:17: in function <TooltipHideRealm\code.lua:15>
TooltipHideRealm\code.lua:34: in function <TooltipHideRealm\code.lua:28>
[C]:: ?
[C]:: ?
[C]:: ?

Locals:
t = <table>
k = "Shadow Council"
(for generator) = <function> defined =[C]:-1
(for state) = <table> {
 (%s)'s Minion = "%s's Minion"
 (%s)'s Totem = "%s's Totem"
 (%s)'s Companion = "%s's Companion"
 Loot: (%s) = "Loot : %s"
 (%s)'s Pet = "%s's Pet"
 (%s)'s Guardian = "%s's Guardian"
}
(for control) = "(%s)'s Minion"
search = "(%s)'s Minion"
replace = "%s's Minion"
ownerStrings = <table> {
 (%s)'s Minion = "%s's Minion"
 (%s)'s Totem = "%s's Totem"
 (%s)'s Companion = "%s's Companion"
 Loot: (%s) = "Loot : %s"
 (%s)'s Pet = "%s's Pet"
 (%s)'s Guardian = "%s's Guardian"
}

And for chat:

Code:
1x ChatHideRealm\code.lua:14: unexpected symbol near ')'

Which if I had to guess, is this part of the script:

Code:
for i = 1, NUM_CHAT_WINDOWS do
	local f = _G["ChatFrame" .. i])
	orig_AddMessage[f] = f.AddMessage
	f.AddMessage = AddMessage
end
Thanks for the help, both of you.

Gryns
__________________
-- Live like a King, laugh like his Jester. --
  Reply With Quote
09-23-15, 01:56 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Gryns View Post
And for chat:

Code:
1x ChatHideRealm\code.lua:14: unexpected symbol near ')'

Which if I had to guess, is this part of the script:

Code:
for i = 1, NUM_CHAT_WINDOWS do
	local f = _G["ChatFrame" .. i])
	orig_AddMessage[f] = f.AddMessage
	f.AddMessage = AddMessage
end
The error is from 'local f = _G["ChatFrame" .. i])' having an extraneous parentheses at the end, but I don't think phanx's script is going to do anything mine didn't do for you, it's just a different way of doing more or less the same thing.

Originally Posted by Gryns View Post
I use BasicChatMods, but even with that disabled it doesn't filter the suffix. Don't get me wrong though, it does remove it from the main chat window, just not when you type. To clarify, when I click on a name in trade chat for instance, it will show "Tell Semlar-Aggramar:" when you are typing in your message, but the conversation itself has the realm suffix removed. I would just like the realm suffix removed in the edit box as well as in the chat window. If that's at all possible, of course.
If I'm understanding you correctly it's removing the realm from their name in the chat window when they send you a whisper, but you want it to also remove it from the left side of the chat box when you're sending a tell to someone.

Alright, I threw something together that I think should do what you're after.
Lua Code:
  1. hooksecurefunc('ChatEdit_UpdateHeader', function(editBox)
  2.     local header = _G[editBox:GetName() .. 'Header']
  3.     if editBox:GetAttribute('chatType') == 'WHISPER' and header then
  4.         _G[editBox:GetName() .. 'HeaderSuffix']:Hide()
  5.         header:SetWidth(0)
  6.         header:SetFormattedText(CHAT_WHISPER_SEND, (strsplit('-', editBox:GetAttribute('tellTarget'))))
  7.         editBox:SetTextInsets(15 + (header:GetRight() or 0) - (header:GetLeft() or 0), 13, 0, 0)
  8.     end
  9. end)

Last edited by semlar : 09-23-15 at 03:01 PM.
  Reply With Quote
09-24-15, 11:02 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Gryns View Post
As for the tooltips. Variations of these showed when mousing over a pet/companion/bodyguard/etc:
Change this line:
Code:
local owner = strmatch(text, search)
to this:
Code:
local owner = strmatch(k, search)
__________________
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
09-22-15, 10:10 PM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Gryns View Post
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
Since this is from my addon NoRealm, I figured I'd chime in.

Unless you're running an addon that's interfering with it, or you're talking about battle net whispers (which I don't even think can contain a realm?), that should still be removing the realm name from the chat.

I know Prat was causing issues with the original pattern I was using because of all the junk they added to the player link (mostly class coloring), but that was fixed in the more recent version of the addon than what you posted here.
  Reply With Quote
09-29-16, 04:14 PM   #9
Finuvar
A Defias Bandit
Join Date: Sep 2016
Posts: 2
This is great. I've been looking all over the place for this.

Is there a way you could prepare this so that anybody can install it easily? My knowledge on scripts and addons is very limited so I can't do it myself.

Big Thanks in advance!
  Reply With Quote
09-29-16, 09:13 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can use this page to turn any working code snippet into an addon ready for installation:

http://addon.bool.no/
__________________
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

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Getting rid of realm suffixes


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