1. I'm trying to made a very simple (or at least it sounds simple in my head) addon called "Who That Who There" that watches for friends/guildmates that login/logout. When found the addon outputs the login/logout info to the UIErrorsFrame and plays a sound. I've found an addon that already does this but it uses Ace, which I'd like to stay away from. I also found a snippet on this site that uses the CHAT_MSG_CHANNEL event in hopes that it would help me with the CHAT_MSG_SYSTEM event. With these two references and things I've tried to understand in the book, I've come up with this frankenstein of code, which isn't working...

     if not LoginLogoutFrame then
          LoginLogoutFrame = CreateFrame("Frame")
     end
    
     local frame = LoginLogoutFrame
    
     frame:RegisterEvent("CHAT_MSG_SYSTEM")
     frame:OnEvent(wdwd)
    
     function wdwd:CHAT_MSG_SYSTEM(msg)
          local system_msg = msg
          if (system_msg:find("online.") ~= nil) then
               UIErrorsFrame:AddMessage(system_msg)
               PlaySound("AuctionWindowOpen")
          end
          if (system_msg:find("offline.") ~= nil) then
               UIErrorsFrame:AddMessage(system_msg)
               PlaySound("AuctionWindowOpen")
          end
     end
    

    There are a number of things I don't understand. Am I correct in assuming the top section of code makes a frame that looks for the CHATMSGSYSTEM event and then registers it when found? How do I use OnEvent to do something with the event I registered? Is OnEvent needed to do what I am trying to achieve?

    If someone has the patience to address my questions and/or point me in the right direction, I would be greatly appreciative. Thanks in advance.

  2. I think I got it worked out.

     if not LoginLogoutFrame then
        LoginLogoutFrame = CreateFrame("Frame")
     end
    
     local frame = LoginLogoutFrame
    
     frame:RegisterEvent("CHAT_MSG_SYSTEM")
     frame:SetScript("OnEvent", function(self, event, ...)
           local system_msg = select(1, ...)
           if (system_msg:find("online.") ~= nil) then
              UIErrorsFrame:AddMessage(system_msg)
              PlaySound("AuctionWindowOpen")
           end
           if (system_msg:find("offline.") ~= nil) then     
              UIErrorsFrame:AddMessage(system_msg)
              PlaySound("AuctionWindowOpen")
           end
        end
     )
    
  3. Yep, that looks right to me, does it work? :P

  4. As far as I can tell it does. I made a slight change to the code to make it look for afk messages since that's a system message I can control with slash commands and it worked. Thanks for this great site. It compliments the book! Browsing through more snippets helped me figure it out.

  5. I'm really glad they helped you out =)