Thread Tools Display Modes
03-31-12, 10:20 AM   #1
cormanthor
A Warpwood Thunder Caller
 
cormanthor's Avatar
AddOn Compiler - Click to view compilations
Join Date: Nov 2008
Posts: 97
RealID list

I wrote an addon whose purpose is to display the name, toon name, and level of all of my RealID friends that are currently online. It works perfectly with one exception: all the data is not present at the event-firing. This causes an error about concatenating nil fields (even though I assigned defaults) which is unrecoverable without a reload.

What would be the best method to delay the EventHandler script for 1-2 seconds? Or better yet, is there a better set of events to monitor?

Lua Code:
  1. -- People Detector for CormanthorUI
  2.  
  3. -- Create the color table (redundant, but necessary)
  4. local colorScheme = {
  5.     death_knight = "C41F3B",
  6.     druid = "FF7D0A",
  7.     hunter = "ABD473",
  8.     mage = "69CCF0",
  9.     monk = "558A84",
  10.     paladin = "F58CBA",
  11.     priest = "FFFFFF",
  12.     rogue = "FFF569",
  13.     shaman = "0070DE",
  14.     warlock = "9482C9",
  15.     warrior = "C79C6E"
  16. }
  17.  
  18. -- Create the frame and listen to events
  19. local cormPD = CreateFrame("frame", "PeopleDetector", Minimap)
  20. cormPD:SetSize(200,100)
  21. cormPD:SetPoint("TOPRIGHT", Minimap, "TOPLEFT", -10, 0)
  22. cormPD:RegisterEvent("PLAYER_ENTERING_WORLD")
  23. cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
  24. cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE")
  25. cormPD:RegisterEvent("PLAYER_FLAGS_CHANGED")
  26. local text = cormPD:CreateFontString()
  27. text:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  28. text:SetPoint("TOPRIGHT", cormPD)
  29. text:SetJustifyH("RIGHT")
  30. local myRealm = GetRealmName()
  31.  
  32. -- List the first name and toon name of all RealID friends
  33. local function Event_Handler(self, event, ...)
  34.     local online = select(2,BNGetNumFriends())
  35.     local list = ""
  36.     local friendName = ""
  37.     local toonName = ""
  38.     local toonClass = ""
  39.     local toonLevel = ""
  40.     local toonRealm = ""
  41.     for i = 1,online do
  42.         friendName = select(2,BNGetFriendInfo(i)) or "UNKNOWN"
  43.         toonName = select(4,BNGetFriendInfo(i)) or "UNKNOWN"
  44.         toonClass = gsub(strlower(select(8,BNGetFriendToonInfo(i,1)))," ","_") or "priest"
  45.         toonLevel = select(11,BNGetFriendToonInfo(i,1)) or 0
  46.         toonRealm = select(4,BNGetFriendToonInfo(i,1)) or myRealm
  47.         if toonRealm == myRealm then
  48.             list = list..friendName
  49.         else
  50.             list = list.."|cff0080FF"..friendName.."|r"
  51.         end
  52.         list = list.." (|cff"..colorScheme[toonClass]..toonName.."|r "..toonLevel..")\n"
  53.     end
  54.     text:SetText(list)
  55. end
  56.  
  57. cormPD:SetScript("OnEvent", Event_Handler)
__________________
Some days it's just not worth chewing through the restraints...
  Reply With Quote
03-31-12, 10:37 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Which event are you currently using ? I couldn't see it listed in there.

If you aren't already trying it try BN_CONNECTED or BN_SELF_ONLINE.
__________________
  Reply With Quote
03-31-12, 10:50 AM   #3
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Originally Posted by Xrystal View Post
Which event are you currently using ? I couldn't see it listed in there.

If you aren't already trying it try BN_CONNECTED or BN_SELF_ONLINE.
It's above the handler:

Code:
cormPD:RegisterEvent("PLAYER_ENTERING_WORLD")
cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE")
cormPD:RegisterEvent("PLAYER_FLAGS_CHANGED")
  Reply With Quote
03-31-12, 11:23 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Oops, thanks Waky, totally missed those lines.
__________________
  Reply With Quote
03-31-12, 01:14 PM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Second return of BNGetNumFriends is not the right number you want to iterate over the friendlist even if you only want those who are online.
You need to iterate over all friends (first value) and then check against the online flag if you need this info.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
03-31-12, 02:04 PM   #6
cormanthor
A Warpwood Thunder Caller
 
cormanthor's Avatar
AddOn Compiler - Click to view compilations
Join Date: Nov 2008
Posts: 97
Originally Posted by Rilgamon View Post
Second return of BNGetNumFriends is not the right number you want to iterate over the friendlist even if you only want those who are online.
You need to iterate over all friends (first value) and then check against the online flag if you need this info.
It actually does work well (in this regard), because Blizzard auto-sorts the online ones first, granting them the lowest index values.

I'm not sure about the other events listed above, as there doesn't seem to be much documentation on them. But I will give them a try this evening and post the results (and final code if it is fixed).

Thanks for the help and suggestions so far everyone!
__________________
Some days it's just not worth chewing through the restraints...
  Reply With Quote
03-31-12, 04:45 PM   #7
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Did some quick tests, and it seems that Battle.Net data is not available on PLAYER_ENTERING_WORLD (or at least not all data is available).

You probably have to wait for some kind of event that confirms that (all) Battle.Net data is available.
  Reply With Quote
03-31-12, 08:56 PM   #8
cormanthor
A Warpwood Thunder Caller
 
cormanthor's Avatar
AddOn Compiler - Click to view compilations
Join Date: Nov 2008
Posts: 97
Originally Posted by F16Gaming View Post
Did some quick tests, and it seems that Battle.Net data is not available on PLAYER_ENTERING_WORLD (or at least not all data is available).

You probably have to wait for some kind of event that confirms that (all) Battle.Net data is available.
I have found that the BN info isn't complete on anyone's login. I'll have to find a way to delay the EventHandler script directly.
__________________
Some days it's just not worth chewing through the restraints...
  Reply With Quote
03-31-12, 10:27 PM   #9
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Probably BN_FRIEND_LIST_SIZE_CHANGED, BN_FRIEND_TOON_ONLINE, or BN_FRIEND_ACCOUNT_ONLINE would fire after information is available.
  Reply With Quote
04-01-12, 08:15 PM   #10
cormanthor
A Warpwood Thunder Caller
 
cormanthor's Avatar
AddOn Compiler - Click to view compilations
Join Date: Nov 2008
Posts: 97
I was unable to get any response at all from BN_FRIEND_TOON_ONLINE, however the following modifications seem to have fixed it:
Lua Code:
  1. -- People Detector for CormanthorUI
  2.  
  3. -- Create the color table (redundant, but necessary)
  4. local colorScheme = {
  5.     death_knight = "C41F3B",
  6.     druid = "FF7D0A",
  7.     hunter = "ABD473",
  8.     mage = "69CCF0",
  9.     monk = "558A84",
  10.     paladin = "F58CBA",
  11.     priest = "FFFFFF",
  12.     rogue = "FFF569",
  13.     shaman = "0070DE",
  14.     warlock = "9482C9",
  15.     warrior = "C79C6E"
  16. }
  17.  
  18. -- Create the frame and listen to events
  19. local cormPD = CreateFrame("frame", "PeopleDetector", Minimap)
  20. cormPD:SetSize(200,100)
  21. cormPD:SetPoint("TOPRIGHT", Minimap, "TOPLEFT", -10, 0)
  22. cormPD:RegisterEvent("PLAYER_ENTERING_WORLD")
  23. cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
  24. cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE")
  25. cormPD:RegisterEvent("PLAYER_FLAGS_CHANGED")
  26. local text = cormPD:CreateFontString()
  27. text:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  28. text:SetPoint("TOPRIGHT", cormPD)
  29. text:SetJustifyH("RIGHT")
  30. local myRealm = GetRealmName()
  31.  
  32. -- List the first name and toon name of all RealID friends
  33. local function Event_Handler(self, event, ...)
  34.     local online = select(2,BNGetNumFriends())
  35.     local list = ""
  36.     local friendName = ""
  37.     local toonName = ""
  38.     local toonClass = ""
  39.     local toonLevel = ""
  40.     local toonRealm = ""
  41.     for i = 1,online do
  42.         friendName = select(2,BNGetFriendInfo(i)) or "UNKNOWN"
  43.         toonName = select(4,BNGetFriendInfo(i)) or "UNKNOWN"
  44.         toonClass = gsub(strlower(select(8,BNGetFriendToonInfo(i,1)))," ","_") or "priest"
  45.         toonLevel = select(11,BNGetFriendToonInfo(i,1)) or 0
  46.         toonRealm = select(4,BNGetFriendToonInfo(i,1)) or myRealm
  47.         if toonRealm == myRealm then
  48.             list = list..friendName
  49.         else
  50.             list = list.."|cff0080FF"..friendName.."|r"
  51.         end
  52.         if toonClass then
  53.             if toonName then
  54.                 list = list.." (|cff"..colorScheme[toonClass]..toonName.."|r"
  55.             else
  56.                 list = list.." (|cff808080UNKNOWN|r"
  57.             end
  58.             if toonLevel then
  59.                 list = list.." "..toonLevel..")\n"
  60.             else
  61.                 list = list..")\n"
  62.             end
  63.         end
  64.     end
  65.     text:SetText(list)
  66. end
  67.  
  68. cormPD:SetScript("OnEvent", Event_Handler)
__________________
Some days it's just not worth chewing through the restraints...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » RealID list

Thread Tools
Display Modes

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