Quantcast
Flashy name for nearby guild mates - WoWInterface
Thread Tools Display Modes
05-01-21, 06:11 AM   #1
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Flashy name for nearby guild mates

Hi everyone, I noticed that when I travel there's sometimes people of my guild nearby but I miss them most times because there are a lot of people of other guilds all around.

Is it possible to create an addon that automaticaly detects people that are in the same guild than mine and change their name in a flashy color so I dont miss them anymore and I can /hug them? I would be grateful if you can share your knowledge with me.

Last edited by Yukka : 05-01-21 at 07:14 AM.
  Reply With Quote
05-01-21, 11:56 AM   #2
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 982
Just some general advice, what did you already try?
Did you use the addon search function on WoWInterface? Did you try googling first?

https://meta.stackexchange.com/quest...ampire-problem
  Reply With Quote
05-01-21, 12:12 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,831
You would need to have friendly nameplates turned on, and be in range for them to show.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-01-21, 12:21 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
You might want to have a look at how the person created this one and see if you can add guild related checks to modify similar items to your specifications.

https://www.wowinterface.com/downloa...ameplates.html

If you are not knowledgeable enough to do this yourself then if you ask nicely the developer of that addon may add a guildie option to their addon.
__________________
  Reply With Quote
05-01-21, 04:36 PM   #5
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
I tried this but it doesnt work

local status = true
if IsInGuild("New Horizon")
then
showName = true, = CreateColor(0, 0.7, 0)
end
  Reply With Quote
05-01-21, 08:30 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
You need to use GetGuildInfo to get the guild name of a unit such as the player.

https://wowpedia.fandom.com/wiki/API_GetGuildInfo

All IsInGuild does is return whether someone is in a guild and doesn't take any parameters.

Unfortunately, needing a unit name to execute means this will have to be someone you are looking at specifically "mouseover", "target" or in a group/raid with "raid2", "party2" etc.

So, the next option to consider is looking at how nameplate addons *scan* the nameplate and extract the information. If one of them is the guild name you can then do your guild check once you have identified which guild the nameplate is showing.

Unfortunately I haven't played with nameplates at all to know what is and isn't possible from that point of access.
__________________

Last edited by Xrystal : 05-01-21 at 08:35 PM.
  Reply With Quote
05-01-21, 10:10 PM   #7
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 559
Any nameplate you see has a valid unit in the form of nameplaten where n goes up to 40. All functions that accept a unit work with nameplate units.

As for looking for nearby guildies, in my experience, it's better to maintain a local table of guildies and then compare players to that list. This bypasses the awkwardness of GetGuildInfo (which isn't reliable outside of inspect distance) as well as avoiding querying the guild roster each time.

Lua Code:
  1. local guildie,myrealm={}
  2. local function normalize(name,realm)
  3.     realm=lower((gsub(realm or (match(name,"%-(.*)")) or 'nil','[%p%s]','')))
  4.     name=lower((gsub((match(name,"(.-)%-")) or name,'[%p%s]','')))
  5.     return realm~='nil' and name..'-'..realm or name..'-'..myrealm
  6. end
  7. local f=CreateFrame("frame")
  8. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  9. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  10. f:RegisterEvent("PLAYER_LOGIN")
  11. f:SetScript("OnEvent",function(self,event,unit)
  12.     if event=="GUILD_ROSTER_UPDATE" then
  13.         self.tguild,self.online=GetNumGuildMembers()
  14.         if self.oguild~=self.online then
  15.             self.oguild=self.online
  16.             wipe(guildie)
  17.             for i=1,self.tguild do
  18.                 local name,_,_,_,_,_,_,_,online=GetGuildRosterInfo(i)
  19.                 if name and online then
  20.                     -- guilds on a connected realm list names with -realm in them
  21.                     guildie[normalize(name)]=true
  22.                 end
  23.                 if #guildie==self.oguild then
  24.                     return
  25.                 end
  26.             end
  27.         end
  28.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  29.  
  30.         if guildie[normalize(UnitFullName(unit))] then
  31.             -- here's where the check happens
  32.             -- you can either do something with the nameplate
  33.             -- using C_NamePlate.GetNamePlateForUnit(unit) to get the frame
  34.             -- or something simple like play a sound to announce the guildie
  35.         end
  36.  
  37.     elseif event=="PLAYER_LOGIN" then
  38.         local _,realm=UnitFullName("player")
  39.         myrealm=lower((gsub(realm,"[%p%s]","")))
  40.     end
  41. end)


EDIT: I forgot that GetGuildRosterInfo returns a GUID. Also, the code above is basically a modified version of my own code in an addon that deals with name-realm data coming from sources that don't include a GUID and only deals with those online. Below is a much simpler version of caching your guild.

Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("frame")
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     if event=="GUILD_ROSTER_UPDATE" then
  7.         local total=GetNumGuildMembers()
  8.         wipe(guildie)
  9.         for i=1,total do
  10.             local guid=select(17,GetGuildRosterInfo(i))
  11.             if guid then
  12.                 guildie[guid]=true
  13.             end
  14.         end
  15.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  16.  
  17.         if guildie[UnitGUID(unit))] then
  18.             -- here's where the check happens
  19.             -- you can either do something with the nameplate
  20.             -- using C_NamePlate.GetNamePlateForUnit(unit) to get the frame
  21.             -- or something simple like play a sound to announce the guildie
  22.         end
  23.  
  24.     end
  25. end)

Last edited by Kanegasi : 05-01-21 at 11:41 PM.
  Reply With Quote
05-02-21, 12:57 AM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
Nice Kanegasi. Much easier than I thought it would be.
__________________
  Reply With Quote
05-02-21, 05:23 AM   #9
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Originally Posted by Kanegasi View Post

Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("frame")
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     if event=="GUILD_ROSTER_UPDATE" then
  7.         local total=GetNumGuildMembers()
  8.         wipe(guildie)
  9.         for i=1,total do
  10.             local guid=select(17,GetGuildRosterInfo(i))
  11.             if guid then
  12.                 guildie[guid]=true
  13.             end
  14.         end
  15.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  16.  
  17.         if guildie[UnitGUID(unit))] then
  18.             -- here's where the check happens
  19.             -- you can either do something with the nameplate
  20.             -- using C_NamePlate.GetNamePlateForUnit(unit) to get the frame
  21.             -- or something simple like play a sound to announce the guildie
  22.         end
  23.  
  24.     end
  25. end)
So after if guildie[UnitGUID(unit))] then if I just write Playsound(888) will it work? Or do I have to write something else? I'm still a bit confused x)

if guildie[UnitGUID(unit))] then
Playsound(888)
end

end
end)
  Reply With Quote
05-02-21, 08:37 AM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
That should in theory play a sound when it creates the nameplate. So, as long as you have nameplates enabled, and you are in range of a guildie, you should get the sound alert when it shows the nameplate. You may still have to hunt it down amongst the mass of nameplates, unless you modify it as mentioned by Kanegasi
__________________
  Reply With Quote
05-02-21, 10:08 AM   #11
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
I tryed it with guildies nearby but it doesnt play any sound. I have friendly nameplates turned on. I dont know how to make it working. Its probably my noob brain that forgot something.

Here's what's in the core.lua file:

Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("frame")
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     if event=="GUILD_ROSTER_UPDATE" then
  7.         local total=GetNumGuildMembers()
  8.         wipe(guildie)
  9.         for i=1,total do
  10.             local guid=select(17,GetGuildRosterInfo(i))
  11.             if guid then
  12.                 guildie[guid]=true
  13.             end
  14.         end
  15.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  16.  
  17.         if guildie[UnitGUID(unit))] then
  18.             Playsound(416)
  19.         end
  20.  
  21.     end
  22. end

Last edited by Yukka : 05-02-21 at 10:45 AM.
  Reply With Quote
05-02-21, 11:14 AM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
Actually, looking at your code there is an extra ')' in the guildie check.


-- If that doesn't help then the following debug steps may help narrow down the problem.

Do a print(total) after setting total and make sure that it is returning a value other than 0 or 1. The for loop doing the work won't do anything if that value isn't set.

Also, assuming it gets in that loop and sets the table up, add a print(event,unit) in the "NAME_PLATE_UNIT_ADDED" event code block to make sure it is being executed. To stop it from doing it tons of time put a counter at the top of the file and increment it each time the event is called and only print the event and unit values up to a certain count.

Then, assuming that works as expected, put a print(UnitGUID(unit)) before the play sound to see that there is a value. If this prints and the sound doesn't happen, the sound is the problem. If it doesn't print the check isn't working as expected.


As a side note for more details, once everything is working, you could try the following to get their name etc.
local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)

I'm going to give this a quick spin though to make sure it works minus the guild checking side of things as my guildies are rarely on at the same time as me.
__________________

Last edited by Xrystal : 05-02-21 at 11:17 AM.
  Reply With Quote
05-02-21, 11:27 AM   #13
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
Hmm .. not sure why but none of my debug prints are showing at all.

I have this code in place and I get none of the messages appearing.
Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("Frame")
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     print(event,unit)
  7.     if event=="GUILD_ROSTER_UPDATE" then
  8.         local total=GetNumGuildMembers()
  9.         wipe(guildie)
  10.         for i=1,total do
  11.             local guid=select(17,GetGuildRosterInfo(i))
  12.             local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  13.             print(i,unit,name,englishClass,englishRace,realm)
  14.             if guid then
  15.                 guildie[guid]=true
  16.             end
  17.         end
  18.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  19.         local guid = UnitGUID(unit)
  20.         local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  21.         print(unit,name,englishClass,englishRace,realm)
  22.         if guildie[guid] then
  23.             Playsound(416)
  24.         end
  25.     end
  26. end)


Nevermind .. I forgot to add the lua file to the toc file .. newbie mistake *slaps head*

Now that I have that minor thing working rofl. I am getting nameplateadded event triggering with a parameter of nameplate1 or nameplate2 with 4 players being referenced by them as they appear and then disappear and are recycled.

Now to test the guildie part of the equation with my lowbie free account character.
__________________

Last edited by Xrystal : 05-02-21 at 11:35 AM.
  Reply With Quote
05-02-21, 11:55 AM   #14
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
okay .. with the following code ( some bug fixes to spelling mistakes ) it worked. I turned nameplates always on and walked in and out of range of my other character in the guild and the sound played. It may get annoying if several guildies arrive at the same time or you are running back and forth. So you may want to consider some sort of timing system so that it only alerts you for a person once every x seconds/minutes etc.

Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("Frame")  >>>>> Upper case F here
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     if event=="GUILD_ROSTER_UPDATE" then
  7.         local total=GetNumGuildMembers()
  8.         wipe(guildie)
  9.         for i=1,total do
  10.             local guid=select(17,GetGuildRosterInfo(i))
  11.             local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  12.             if guid then
  13.                 guildie[guid]=true
  14.             end
  15.         end
  16.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  17.         local guid = UnitGUID(unit)    
  18.         local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  19.         if guildie[guid] then
  20.             PlaySound(416)  >>> Upper case S here
  21.             print(name)   >>> Displays name of guild member to know who .. you can use whatever alert system you want to display the message to make it more prominent if you want.
  22.         end
  23.     end
  24. end)   >>> Remember the bracket here
__________________
  Reply With Quote
05-02-21, 01:06 PM   #15
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Nice it plays the sound, thanks. I like a lot when it print the guildie name in the chat

Instead of a sound playing is there a way to just change the color of the name of the nearby guildie(s) so I can quickly diferenciate them from other people? I Tryed to replace Playsound(416) with showName = true, = CreateColor(0, 0.7, 0) but its not working (as always...)
  Reply With Quote
05-02-21, 05:10 PM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
Adding this after the PlaySound line changed the color of the name of the player when the nameplate is created.

Lua Code:
  1. local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
  2. nameplate.UnitFrame.name:SetTextColor(1,0,1,1)
__________________
  Reply With Quote
05-03-21, 04:19 AM   #17
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Awesome. I wish I had your knowledge. Thanks all for the great help. Now I'm gonna hug all the guildies I see
  Reply With Quote
05-03-21, 08:08 AM   #18
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Please what is the code to hide the healthbars below the names when nameplates are activated, I dont find it on wowwiki API. Its just for the aesthetic, no need healthbars when not in combat, right?
  Reply With Quote
05-03-21, 10:32 AM   #19
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,628
This is the xml file that describes the different frames

The one you want to look at is the one that shows parentKey = "UnitFrame"

Under that is a section called parentKey = "healthBar" and some other bars.

You would want to do a check for not InCombatLockdown and use nameplate.UnitFrame.healthBar:Hide() etc. But remember your code only executes when the nameplate is created ( comes back into range or you use Shift V to view them again ) so the bars may get redrawn if an update happens after your changes.

I haven't tested this out but in theory thats all you will need to do if that is the only bar that is showing at first. When in combat the others may appear.
__________________
  Reply With Quote
05-03-21, 01:00 PM   #20
Yukka
An Aku'mai Servant
 
Yukka's Avatar
Join Date: Feb 2020
Posts: 32
Nice I added the code you gave above at line 23 and it works well and hide healthbars on guildies. But other people around that are not in my guild still have their healthbars under their name. Where else can I put nameplate.UnitFrame.healthBar:Hide() to hide other people healthbars?

Lua Code:
  1. local guildie={}
  2. local f=CreateFrame("Frame")
  3. f:RegisterEvent("GUILD_ROSTER_UPDATE")
  4. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  5. f:SetScript("OnEvent",function(self,event,unit)
  6.     if event=="GUILD_ROSTER_UPDATE" then
  7.         local total=GetNumGuildMembers()
  8.         wipe(guildie)
  9.         for i=1,total do
  10.             local guid=select(17,GetGuildRosterInfo(i))
  11.             local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  12.             if guid then
  13.                 guildie[guid]=true
  14.             end
  15.         end
  16.     elseif event=="NAME_PLATE_UNIT_ADDED" then
  17.         local guid = UnitGUID(unit)    
  18.         local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
  19.         if guildie[guid] then
  20.             PlaySound(416)
  21.             local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
  22.             nameplate.UnitFrame.name:SetTextColor(1,1,1,1)
  23.             nameplate.UnitFrame.healthBar:Hide()
  24.             print(name)
  25.         end
  26.     end
  27. end)
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Flashy name for nearby guild mates

Thread Tools
Display Modes

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