WoWInterface (
-   Lua/XML Help (
-   -   Get a Player's Class & Level (

Moonscarlet 02-01-20 07:26 AM

Get a Player's Class & Level

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.


Kanegasi 02-01-20 07:46 AM

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.

Moonscarlet 02-01-20 01:50 PM

Thanks a lot, Kanegasi.

Moonscarlet 02-01-20 03:03 PM


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.


Xrystal 02-01-20 03:19 PM

Say you wanted to find out about someone who whispered you...

These are the values that that event will have in its arguments
"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 ..

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 = { ... }
  4.    local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(args[12])
  6.   -- Deal with PlayerInfo as needed
  8. end
  10. local frame = CreateFrame("EventWatcher")
  11. frame:RegisterEvent("CHAT_MSG_WHISPER")
  12. frame:SetScript("OnEvent", OnChatEvent)

Moonscarlet 02-01-20 04:31 PM

Thank you, got it to work now.

All times are GMT -6. The time now is 09:30 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI