Thread: RealID list
View Single Post
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