WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   RealID list (https://www.wowinterface.com/forums/showthread.php?t=43149)

cormanthor 03-31-12 10:20 AM

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)

Xrystal 03-31-12 10:37 AM

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.

Waky 03-31-12 10:50 AM

Quote:

Originally Posted by Xrystal (Post 254694)
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")


Xrystal 03-31-12 11:23 AM

Oops, thanks Waky, totally missed those lines.

Rilgamon 03-31-12 01:14 PM

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.

cormanthor 03-31-12 02:04 PM

Quote:

Originally Posted by Rilgamon (Post 254704)
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!

Sharparam 03-31-12 04:45 PM

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.

cormanthor 03-31-12 08:56 PM

Quote:

Originally Posted by F16Gaming (Post 254712)
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.

semlar 03-31-12 10:27 PM

Probably BN_FRIEND_LIST_SIZE_CHANGED, BN_FRIEND_TOON_ONLINE, or BN_FRIEND_ACCOUNT_ONLINE would fire after information is available.

cormanthor 04-01-12 08:15 PM

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)


All times are GMT -6. The time now is 05:52 PM.

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