Thread Tools Display Modes
04-07-14, 04:17 PM   #1
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
[Addon/Script]party name to class name

Hey, if any of you here know how can I do sth like that:

I would be grateful

any kind of help appreciated

EDIT:
If this should be in AddOn Search/Requests, then sorry and if a moderator could move this topic there

Last edited by r3FLeX : 04-07-14 at 04:20 PM.
  Reply With Quote
04-07-14, 05:32 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There's a lot going on in that screenshot, but based on the thread title, I'm going to guess you're talking about the compact (grid-like) raid/party frmes, and that you want to replace the player names with class names, in which case this should work:

Code:
hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	frame.name:SetText(UnitClass(frame.unit))
end)
If you need help turning the above code into an addon, copy and paste it into this page:
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
04-08-14, 01:54 PM   #3
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
Originally Posted by Phanx View Post
There's a lot going on in that screenshot, but based on the thread title, I'm going to guess you're talking about the compact (grid-like) raid/party frmes, and that you want to replace the player names with class names, in which case this should work:

Code:
hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	frame.name:SetText(UnitClass(frame.unit))
end)
If you need help turning the above code into an addon, copy and paste it into this page:
http://addon.bool.no/
Awesome, that's what I was looking for! Thanks.
Just if you could help me with few more things.
I'm using this script to change my display name, it also changes it if I target myself or focus.
Lua Code:
  1. -- name  change script
  2.     local frame = CreateFrame("FRAME", "NameChangeScripts")
  3.     frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  4.     local function eventHandler(self, event, ...)
  5.  
  6. -- EDIT THIS LINE BELOW TO CHANGE YOUR NAME
  7.     NewName = "谷歌"
  8.     PN = GetUnitName("player")
  9.  
  10. -- Change Player UnitFrame Name
  11.     PFNC = CreateFrame("Frame", "PlayerFrameNameChange")
  12.     local function ChangePlayerName(self)
  13.     PlayerFrame.name:SetText(NewName)
  14.     end
  15.     PFNC:SetScript("OnUpdate", ChangePlayerName)
  16.  
  17. -- Change Target UnitFrame Name
  18.     TFNC = CreateFrame("Frame", "TargetFrameNameChange")
  19.     local function ChangeTargetName(self)
  20.     local TN = GetUnitName("target")
  21.     if PN == TN then
  22.     TargetFrame.name:SetText(NewName)
  23.     end
  24.     end
  25.     TFNC:SetScript("OnUpdate", ChangeTargetName)
  26.  
  27. -- Change Target's Target UnitFrame Name
  28.     TFTNC = CreateFrame("Frame", "TargetFrameTargetNameChange")
  29.     local function ChangeTargetofTargetName(self)
  30.     local TTN = GetUnitName("targettarget")
  31.     if PN == TTN then
  32.     TargetFrameToT.name:SetText(NewName)
  33.     end
  34.     end
  35.     TFTNC:SetScript("OnUpdate", ChangeTargetofTargetName)
  36.  
  37. -- Change Focus UnitFrame Name
  38.     FFNC = CreateFrame("Frame", "FocusFrameNameChange")
  39.     local function ChangeFocusName(self)
  40.     local FN = GetUnitName("focus")
  41.     if PN == FN then
  42.     FocusFrame.name:SetText(NewName)
  43.     end
  44.     end
  45.     FFNC:SetScript("OnUpdate", ChangeFocusName)
  46.  
  47. -- Change Focus' Target UnitFrame Name
  48.     FFTNC = CreateFrame("Frame", "FocusFrameTargetNameChange")
  49.     local function ChangeFocusTargetName(self)
  50.     local FTN = GetUnitName("focustarget")
  51.     if PN == FTN then
  52.     FocusFrameToT.name:SetText(NewName)
  53.     end
  54.     end
  55.     FFTNC:SetScript("OnUpdate", ChangeFocusTargetName)
  56.  
  57.     end
  58.     frame:SetScript("OnEvent", eventHandler)
Could you edit that code above, that it will change also name on RaidFrames (Instead of Mage)?

One more, that code you posted; can you display names uppercased? And can you change names in standard party frames (not Raid-styled)?

Thanks again and sorry if you had to guess what I meant.
  Reply With Quote
04-08-14, 06:33 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That code is extremely horrible, with tons of leaked globals, duplicate frames and functions created over and over, etc. I can only assume you got it from the ArenaJunkies forums. No code from there is ever good.

Here is a revised version that doesn't create any unnecessary frames, doesn't leak globals, and doesn't make me want to club a whole pile of baby seals. It will work for both raid frames and normal unit frames (including party frames) and shows the class name in all-caps. For units that are not players (eg. pets) the text "PET" is shown, since those don't have real classes.

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)))
	else
		fontString:SetText(CUSTOM_PET_TEXT)
	end
end

hooksecurefunc("UnitFrame_Update", function(frame, isParty)
	if frame.name then
		SetCustomName(frame.overrideName or frame.unit, frame.name)
	end
end)

hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	SetCustomName(frame.unit, frame.name)
end)
__________________
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
04-09-14, 09:36 AM   #5
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
Originally Posted by Phanx View Post
That code is extremely horrible, with tons of leaked globals, duplicate frames and functions created over and over, etc. I can only assume you got it from the ArenaJunkies forums. No code from there is ever good.
Yea, you're right. I'll get some lua books soon and start to learn it myself, but for now I 'm dependent on you

Originally Posted by Phanx View Post
Here is a revised version that doesn't create any unnecessary frames, doesn't leak globals, and doesn't make me want to club a whole pile of baby seals. It will work for both raid frames and normal unit frames (including party frames) and shows the class name in all-caps. For units that are not players (eg. pets) the text "PET" is shown, since those don't have real classes.

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)))
	else
		fontString:SetText(CUSTOM_PET_TEXT)
	end
end

hooksecurefunc("UnitFrame_Update", function(frame, isParty)
	if frame.name then
		SetCustomName(frame.overrideName or frame.unit, frame.name)
	end
end)

hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	SetCustomName(frame.unit, frame.name)
end)
All great just if you could add that Friendly/Enemy NPC keep their original name instead of PET and also enemy players keep their original name instead of class. Also changing pets names isn't so important, so if that will help to do things I mentioned above you can remove it.

Big thanks man, stay awesome

EDIT:
Getting this errors while new players joining raid http://pastebin.com/r4m5BYBJ

Last edited by r3FLeX : 04-09-14 at 12:27 PM.
  Reply With Quote
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
04-09-14, 07:03 PM   #7
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I apologize if I am mistaken, but I believe UNKNOWN needs to be "UNKNOWN", else you'll get an error.
  Reply With Quote
04-10-14, 12:40 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
No. UNKNOWN is a Blizzard global string, containing the appropriately translated version of the word "Unknown" for the user's current locale.
__________________
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
04-10-14, 07:10 AM   #9
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Oh, I see. Thank you for the information!
  Reply With Quote
04-10-14, 01:56 PM   #10
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
Originally Posted by Phanx View Post
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.
Almost all works as it should be, just it doesn't change Name -> CLASS on Classic Party Frames BUT it changes in arena (after leaving arena it change back to Name).

Last edited by r3FLeX : 04-27-16 at 04:46 AM.
  Reply With Quote
04-10-14, 05:16 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Add this at the end:

Code:
hooksecurefunc("UnitFrame_OnEvent", function(frame, event, unit)
	if frame.name and event == "UNIT_NAME_UPDATE" and unit == frame.unit then
		if UnitPlayerControlled(unit) and UnitIsFriend(unit, "player") then
			SetCustomName(unit, frame.name)
		end
	end
end)
__________________
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
04-11-14, 09:26 AM   #12
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
Originally Posted by Phanx View Post
Add this at the end:

Code:
hooksecurefunc("UnitFrame_OnEvent", function(frame, event, unit)
	if frame.name and event == "UNIT_NAME_UPDATE" and unit == frame.unit then
		if UnitPlayerControlled(unit) and UnitIsFriend(unit, "player") then
			SetCustomName(unit, frame.name)
		end
	end
end)
After adding this last part:
- name change to class after joining party on classic party frames
- after join arena match name isn't changing (ONLY on Classic Party Frames, on raid frames it's fine)
- after leaving match, name properly change to class
  Reply With Quote
04-11-14, 07:23 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by r3FLeX View Post
- name change to class after joining party on classic party frames
Yes, that's what it's supposed to do... I thought you wanted class names on classic party frames?

Originally Posted by r3FLeX View Post
- after join arena match name isn't changing (ONLY on Classic Party Frames, on raid frames it's fine)
- after leaving match, name properly change to class
I'm not really sure how that can happen... the two functions being hooked are literally the only two unit frame functions that set any text to any (non-raid) frame's name fontstring, and no party-specific functions touch the fontstring.

Add these debug prints and let me know what they report when joining an arena match. It'll be spammy, so I'd advise creating another chat tab for real messages you can switch to once you're actually in the match.

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

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

hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
	print("CompactUnitFrame_UpdateName", frame.unit)
	SetCustomName(frame.unit, frame.name)
end)

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

hooksecurefunc("UnitFrame_OnEvent", function(frame, event, unit)
	if frame.name and event == "UNIT_NAME_UPDATE" and unit == frame.unit then
		print("UnitFrame_OnEvent", unit, UnitPlayerControlled(unit), UnitIsFriend(unit, "player"))
		if UnitPlayerControlled(unit) and UnitIsFriend(unit, "player") then
			SetCustomName(unit, frame.name)
		end
	end
end)
Additions highlighted in green. Changes to existing lines in blue.
__________________
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.

Last edited by Phanx : 04-11-14 at 07:25 PM.
  Reply With Quote
04-12-14, 06:26 AM   #14
r3FLeX
A Murloc Raider
Join Date: Aug 2011
Posts: 9
Originally Posted by Phanx View Post
Yes, that's what it's supposed to do... I thought you wanted class names on classic party frames?
Yes, I wanted it like this. I wrote that to let you know that before entering arena it worked.
It was like: invite member (WORKING) -> enter arena (NOT WORKING) -> leaving arena (WORKING)

Originally Posted by Phanx View Post
I'm not really sure how that can happen... the two functions being hooked are literally the only two unit frame functions that set any text to any (non-raid) frame's name fontstring, and no party-specific functions touch the fontstring.
Add these debug prints and let me know what they report when joining an arena match. It'll be spammy, so I'd advise creating another chat tab for real messages you can switch to once you're actually in the match.
I'm now confused too because last code you gave me after joining arena change classic party frames to raid frames.

result of debug
  Reply With Quote
04-14-14, 05:00 AM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I need the debug messages from when you join an arena match, not a regular party. I am not currently able to test anything related to arenas, so I can't do anything further without your (or someone else's) help.

Originally Posted by r3FLeX View Post
I'm now confused too because last code you gave me after joining arena change classic party frames to raid frames.
There is nothing in the code I posted that would cause the raid-style frames to be displayed instead of the classic raid frames. The only thing the code does is set the text of a font string. If you're seeing the frame style change, that's caused by some other addon you're running.
__________________
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 Help/Support » [Addon/Script]party name to class name


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