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:
-- Initialises the settings and settings menu
function myAddon.onAddonLoaded(event, addonName)
--Protect
if addonName ~= myAddon.name then return end
-- Only build Roster at 1st startup
myAddon.onlyAt1stLaunch = true
end
-- Triggers when EVENT_PLAYER_ACTIVATED
function myAddon.onPlayerActivated()
-- Only executed a single time
if myAddon.onlyAt1stLaunch then
myAddon.onlyAt1stLaunch = false
-- Because when onAddonLoaded triggers, guildRoster is not yet ready, createTable() here
-- Init tables for name conversion
for guild = 1, GetNumGuilds() do
-- Guildname
local guildId = GetGuildId(guild)
local guildName = GetGuildName(guildId)
-- Occurs sometimes
if(not guildName or (guildName):len() < 1) then
guildName = "Guild " .. guildId
end
myAddon.createTable(guildId, guildName)
end
end
end
-- Creates the lookup table
function myAddon.createTable(guildId, guildName)
-- Init array for guild
myAddon.lookup[guildName] = {}
-- Iterate over each guild member
for member = 1, GetNumGuildMembers(guildId) do
-- Get account name and character name
local account = GetGuildMemberInfo(guildId, member)
local hasChar, character = GetGuildMemberCharacterInfo(guildId, member)
if hasChar and character then
-- Remove extra characters.
character = zo_strformat(SI_UNIT_NAME, character)
myAddon.lookup[guildName][account] = character
end
end
end
-- Update the lookup table, triggered when EVENT_GUILD_MEMBER_PLAYER_STATUS_CHANGED
function myAddon.updateTable(guildId, guildName, account)
-- Get character name
for member = 1, GetNumGuildMembers(guildId) do
if account == GetGuildMemberInfo(guildId, member) then
local hasChar, character = GetGuildMemberCharacterInfo(guildId, member)
if hasChar and character then
-- Remove extra characters.
character = zo_strformat(SI_UNIT_NAME, character)
if myAddon.lookup[guildName] then
if myAddon.lookup[guildName][account] then
myAddon.lookup[guildName][account] = character
end
end
end
end
end
end