WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Player and server name from received whisper (https://www.wowinterface.com/forums/showthread.php?t=49032)

Zax 03-05-14 10:40 AM

Player and server name from received whisper
 
Hello,

Sender's name from event CHAT_MSG_WHISPER now looks like "John-KirinTor" (without any space) if a whisp is received from John from Kirin Tor server (with a space) and even if you also play on Kirin Tor server.
So, as we cann't perform a test on the server name because in this case the builtin function GetRealmName() will return "Kirin Tor", how could I do to know if John is on the same server as me ?

If John is on the same server as me, and only in this case, I would like to split the server name, the easy part.

Thanks.

GnomTEC 03-05-14 11:11 AM

I remove the Space from the name i got from GetRealmName(), this seems to be the same what Blizzard does.
Ofcourse nobody can say what funny ideas they have next, perhaps changing case unpredictable. :)

At the moment i use following in my code (which you have then to concatenate with the player's name):

Lua Code:
  1. string.gsub(GetRealmName(), "%s+", "")

PS: to get player and realm from sender i use following:

Lua Code:
  1. player, realm = strsplit( "-", sender, 2 )

Dridzt 03-05-14 11:13 AM

For any unit with a valid unitID UnitRealmRelationship(unitID) will return a constant among LE_REALM_RELATION_SAME|LE_REALM_RELATION_COALESCED|LE_REALM_RELATION_VIRTUAL

For chat you might be able to use name, realm = UnitFullName("player") and compare the realm return (I'm not sure if the realm return here is normalized and can be used for a direct comparison, no access to wow to test atm)

You can also try passing the full name through Ambiguate("name","none") it should strip off the realm if it's same realm as you so you have an indirect way to test.

Edit:Saw GnomeTEC's response, that should work for most cases but it also needs to strip out apostrophes and I'm not sure for the realms with special characters in their name (some French, Italian and Portuguese/Brazilian)
The armory at least does Unicode normalization converting the accented chars to their base equivalent.

Zax 03-06-14 08:33 AM

Thanks for your replies :)

Is it interesting to know that the "shortened" server name can be found with

Code:

local player, serverShortName = UnitFullName("player")

GnomTEC 03-06-14 09:19 AM

Ah, i didn't know this thing with UnitFullName("player"). :)

But if this "shortens" the realm name corectly it's surely the better solution to get the own realm name. I will also have a look at this and propably change my own code.

Phanx 03-06-14 04:48 PM

Quote:

Originally Posted by Dridzt (Post 291308)
... it also needs to strip out apostrophes and I'm not sure for the realms with special characters in their name (some French, Italian and Portuguese/Brazilian)

This is incorrect. At least on EU realms, apostrophes are included in the realm names as passed with CHAT_MSG_* events and returned by UnitFullName.

I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.

Dridzt 03-06-14 05:14 PM

Quote:

Originally Posted by Phanx (Post 291319)
This is incorrect. At least on EU realms, apostrophes are included in the realm names as passed with CHAT_MSG_* events and returned by UnitFullName.

I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.

I specifically noted the apostrophe part and unicode normalization as an aside relevant to the armory, not in-game.
You can safely ignore my edit and use the first part of the post that's relevant to the question and apparently provides a suitable method.

Edit: I also (with regard to armory) wasn't referring to the player name but the realm name.
As an example this is what happens to the url for "Pozzo dell'Eternità" (an Italian realm)

Zax 03-07-14 09:15 AM

I don't know why but UnitFullName("player") sometimes returns NIL if called just after the VARIABLES_LOADED event, so I finally use GnomeTEC function :

Code:

shortenedSeverName = string.gsub(GetRealmName(), "%s+", "")

Quote:

Originally Posted by Phanx (Post 291319)
I couldn't find anyone with a non-ASCII character, and didn't feel like going and making a character on a FR/IT/PT realm to check, but I suspect they are also used as-is in-game.

Realm "Confrérie du Thorium" is shortened in "ConfrérieduThorium" (which means Thorium brotherhood ;) )

Dridzt 03-07-14 09:52 AM

Quote:

Originally Posted by Zax (Post 291329)
I don't know why but UnitFullName("player") sometimes returns NIL if called just after the VARIABLES_LOADED event, <snip>
Realm "Confrérie du Thorium" is shortened in "ConfrérieduThorium" (which means Thorium brotherhood ;) )

That's because VARIABLES_LOADED is a bad event to use for addon initialization and has been bad since WoW 3.1 or something like that :p

You either want ADDON_LOADED with arg1 == 'YourAddonName' which guarantees saved variables initialization but not much else or even better PLAYER_LOGIN which ensures player information (including name / realm) are available.

Zax 03-07-14 11:05 AM

Quote:

Originally Posted by Dridzt (Post 291330)
That's because VARIABLES_LOADED is a bad event to use for addon initialization and has been bad since WoW 3.1 or something like that :p


:eek: :eek:


All times are GMT -6. The time now is 10:24 AM.

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