Quantcast
Get a Player's Class & Level - WoWInterface
Thread Tools Display Modes
02-01-20, 07:26 AM   #1
Moonscarlet
A Murloc Raider
 
Moonscarlet's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 8
Get a Player's Class & Level

Hello,

I want to get a player's class/color and level from their chat message but I wasn't able to do it as I tried UnitClass() and UnitLevel(), but these seem to only work for me(even if I entered my name), player, target, party, raid...etc and not players out of my range.

I would really appreciate help with this.

Thanks.
  Reply With Quote
02-01-20, 07:46 AM   #2
Kanegasi
A Firelord
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 487
A player's level is not available from just a chat event. The only way you used to get it is from convoluted usage of the /who api, but both retail and classic now has that protected behind a hardware event.

For class info, pass the 12th argument from the chat event, the player's GUID, into GetPlayerInfoByGUID.
  Reply With Quote
02-01-20, 01:50 PM   #3
Moonscarlet
A Murloc Raider
 
Moonscarlet's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 8
Thanks a lot, Kanegasi.
  Reply With Quote
02-01-20, 03:03 PM   #4
Moonscarlet
A Murloc Raider
 
Moonscarlet's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 8
Hey,

Do you mind giving me all the arguments that I can pass in that function?
I only know about the first few up to channel name, so I'd appreciate it if you could give me a link or something that shows me more.

Thanks.
  Reply With Quote
02-01-20, 03:19 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,460
Say you wanted to find out about someone who whispered you...

These are the values that that event will have in its arguments
https://wow.gamepedia.com/CHAT_MSG_WHISPER
"text", "playerName", "languageName", "channelName", "playerName2", "specialFlags", zoneChannelID, channelIndex, "channelBaseName", unused, lineID, "guid", bnSenderID, isMobile, isSubtitle, hideSenderInLetterbox, supressRaidIcons

The GUID value has it's own set of values if you know how to extract it ..
https://wow.gamepedia.com/GUID


The following is a quick code up and is not necessarily 100% working but should give you an idea of how you can use it.

Lua Code:
  1. function OnChatEvent(self, event, ... )
  2.    local args = { ... }
  3.  
  4.    local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(args[12])
  5.  
  6.   -- Deal with PlayerInfo as needed
  7.  
  8. end
  9.  
  10. local frame = CreateFrame("EventWatcher")
  11. frame:RegisterEvent("CHAT_MSG_WHISPER")
  12. frame:SetScript("OnEvent", OnChatEvent)
__________________

Last edited by Xrystal : 02-01-20 at 03:23 PM.
  Reply With Quote
02-01-20, 04:31 PM   #6
Moonscarlet
A Murloc Raider
 
Moonscarlet's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 8
Thank you, got it to work now.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get a Player's Class & Level

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