Thread Tools Display Modes
10/02/14, 07:39 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Get Account Name from Character Name

Is there a way to get someones "Account Name" (i.e. their @username) from their character name? i'm thinking some function like GetDisplayName() but allows me to pass a parameter to get someone else's account name.
  Reply With Quote
10/02/14, 08:22 PM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
The only link you can use between character names and userID are rosters
They are : friendlist, ignorelist (i never tested but it should work), guild rosters.
If the source is not on those lists, you cannot guess the other field

If people is on those list, you can build lookup table and refresh them at every login :

exemple for guild : (some params like GuildNames are not all accessible from events, but it's easier to build guildrosters with Guildnames to void reorganization problems) I didn't show all the code ..

Lua Code:
  1. -- Initialises the settings and settings menu
  2. function myAddon.onAddonLoaded(event, addonName)
  3.  
  4.     --Protect
  5.     if addonName ~= myAddon.name then return end
  6.    
  7.     -- Only build Roster at 1st startup
  8.     myAddon.onlyAt1stLaunch = true
  9.    
  10. end
  11.  
  12. -- Triggers when EVENT_PLAYER_ACTIVATED
  13. function myAddon.onPlayerActivated()
  14.    
  15.     -- Only executed a single time
  16.     if myAddon.onlyAt1stLaunch then
  17.    
  18.         myAddon.onlyAt1stLaunch = false
  19.        
  20.         -- Because when onAddonLoaded triggers, guildRoster is not yet ready, createTable() here
  21.         -- Init tables for name conversion
  22.         for guild = 1, GetNumGuilds() do
  23.        
  24.             -- Guildname
  25.             local guildId = GetGuildId(guild)
  26.             local guildName = GetGuildName(guildId)
  27.            
  28.             -- Occurs sometimes
  29.             if(not guildName or (guildName):len() < 1) then
  30.                 guildName = "Guild " .. guildId
  31.             end
  32.            
  33.             myAddon.createTable(guildId, guildName)
  34.        
  35.         end
  36.        
  37.     end
  38.    
  39. end
  40.  
  41.  
  42.  
  43. -- Creates the lookup table
  44. function myAddon.createTable(guildId, guildName)
  45.    
  46.     -- Init array for guild
  47.     myAddon.lookup[guildName] = {}
  48.    
  49.     -- Iterate over each guild member
  50.     for member = 1, GetNumGuildMembers(guildId) do
  51.         -- Get account name and character name
  52.         local account = GetGuildMemberInfo(guildId, member)
  53.         local hasChar, character = GetGuildMemberCharacterInfo(guildId, member)
  54.        
  55.         if hasChar and character then
  56.            
  57.             -- Remove extra characters.
  58.             character = zo_strformat(SI_UNIT_NAME, character)
  59.             myAddon.lookup[guildName][account] = character
  60.            
  61.         end
  62.     end
  63.    
  64. end
  65.  
  66. -- Update the lookup table, triggered when EVENT_GUILD_MEMBER_PLAYER_STATUS_CHANGED
  67. function myAddon.updateTable(guildId, guildName, account)
  68.    
  69.     -- Get character name
  70.     for member = 1, GetNumGuildMembers(guildId) do
  71.         if account == GetGuildMemberInfo(guildId, member) then
  72.            
  73.             local hasChar, character = GetGuildMemberCharacterInfo(guildId, member)
  74.            
  75.             if hasChar and character then
  76.                 -- Remove extra characters.
  77.                 character = zo_strformat(SI_UNIT_NAME, character)
  78.                
  79.                 if myAddon.lookup[guildName] then
  80.                     if myAddon.lookup[guildName][account] then
  81.                         myAddon.lookup[guildName][account] = character
  82.                     end
  83.                 end
  84.                
  85.             end
  86.            
  87.         end
  88.     end
  89.    
  90. end

Last edited by Ayantir : 10/02/14 at 08:25 PM.
  Reply With Quote
10/02/14, 08:24 PM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
thanks for the detailed response... i'll guess i'll have to go with the roster or friendlist.
  Reply With Quote
10/02/14, 08:32 PM   #4
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
I found the method below for ignore. but I don't see a way to iterate the "IgnoreList" like you can a friends list or guild list.

Ignore
GetNumIgnored()
Returns: integer numIgnored
GetIgnoredInfo(luaindex index)
Returns: string displayName, string note
IsIgnored(string displayName)
Returns: bool isIgnored
AddIgnore(string charOrDisplayName)
RemoveIgnore(string displayName)
SetIgnoreNote(luaindex ignoreIndex, string note)
  Reply With Quote
10/02/14, 09:35 PM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by skobyjay View Post
I found the method below for ignore. but I don't see a way to iterate the "IgnoreList" like you can a friends list or guild list.

Ignore
GetNumIgnored()
Returns: integer numIgnored
GetIgnoredInfo(luaindex index)
Returns: string displayName, string note
IsIgnored(string displayName)
Returns: bool isIgnored
AddIgnore(string charOrDisplayName)
RemoveIgnore(string displayName)
SetIgnoreNote(luaindex ignoreIndex, string note)
There is no function that will return character name for ignored player, but you can probably use ignore list for conversion from character name to display/account name.

Lua Code:
  1. local function ConvertToDisplayName(name)
  2.     local displayName
  3.     if IsDecoratedDisplayName(name) then
  4.         displayName = name
  5.     else
  6.         if IsFriend(name) then
  7.             for i, GetNumFriends() do
  8.                 local _, characterName = GetFriendCharacterInfo(i)
  9.                 if characterName == name then
  10.                     displayName = GetFriendInfo(i)
  11.                     break
  12.                 end
  13.             end
  14.         end
  15.         if not displayName then
  16.             if not IsIgnored(name) then
  17.                 AddIgnore(name) --add player to the ignore list
  18.                 displayName = GetIgnoredInfo(GetNumIgnored()) --get display name of the last added ignored player
  19.                 RemoveIgnore(displayName) --remove player from the ignore list
  20.             else
  21.                 d("Name is on the ignore list, conversion failed.")
  22.             end
  23.         end
  24.     end
  25.     return displayName
  26. end
Code is untested and probably won't work because there is a limit how often you can use social requests. Maybe adding of some delay between requests can solve the issue.

Last edited by Garkin : 10/02/14 at 09:57 PM.
  Reply With Quote
10/03/14, 07:15 AM   #6
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
awesome!! thanks. i will give this a shot, that looks like exactly what i'm needing.
  Reply With Quote
10/03/14, 02:04 PM   #7
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
this runs good. i think it submits the requests too fast to the API to process I got a "Busy Processing Social requests" or something like that. maybe I need to add a delay in there between the calls to ignore?
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Get Account Name from Character Name


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