WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Get a Player's Class & Level (https://www.wowinterface.com/forums/showthread.php?t=57797)

Moonscarlet 02-01-20 07:26 AM

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.

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

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.

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
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)

Moonscarlet 02-01-20 04:31 PM

Thank you, got it to work now.


All times are GMT -6. The time now is 06:15 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI