View Single Post
05-18-14, 05:43 PM   #1
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
BNplayer Hyperlink

I am trying to create a player link for a copy-cat chat message, but I'm having trouble understanding the arguments that it needs.
Basically what the addon is supposed to do is to send a chat message when a player who is logged onto the Battle.net desktop app only logs onto a game. The message mimics the one sent when your Battle.net friends normally log on without the client ("Soandso (W Toonname) has come online.").

I found the following code in Interface\FrameXML\ChatFrame.lua:

lua Code:
  1. playerLink = "|HBNplayer:"..arg2..":"..arg13..":"..arg11..":"..chatGroup..(chatTarget and ":"..chatTarget or "").."|h"

However, I'm having issues trying to figure out what each of the arguments are and how to incorporate it into my code.

lua Code:
  1. local events = CreateFrame("Frame")
  2.       events:RegisterEvent("ADDON_LOADED")
  3.       events:RegisterEvent("PLAYER_LOGIN")
  4.       events:RegisterEvent("BN_TOON_NAME_UPDATED")
  5.       events:RegisterEvent("BN_FRIEND_TOON_ONLINE")
  6.       events:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
  7.       events:SetScript("OnEvent", function(self, event, ...)
  8.           return self[event] and self[event](self, event, ...)
  9.       end)
  10.  
  11. local Friends = {}
  12.  
  13. -- Get online players.
  14. function events:ADDON_LOADED(event, addon)
  15.     if addon == "FriendsFixes" then
  16.         for x = 1, BNGetNumFriends() do
  17.             local presenceID = BNGetFriendInfo(x)
  18.             Friends[presenceID] = {BNGetFriendInfo(x)}
  19.         end
  20.     end
  21. end
  22.  
  23. function events:PLAYER_LOGIN(event, ...)
  24.     for x = 1, BNGetNumFriends() do
  25.         local presenceID = BNGetFriendInfo(x)
  26.         Friends[presenceID] = {BNGetFriendInfo(x)}
  27.     end
  28. end
  29.  
  30. -- Prevents double login spam from App.
  31. local function FilterBNLoginSpam(self, event, type, ...)
  32.     local presenceID = select(12, ...)
  33.  
  34.     if type == "FRIEND_ONLINE" and presenceID then
  35.         if Friends[presenceID][8] then
  36.             return true
  37.         else
  38.             for x = 1, BNGetNumFriends() do
  39.                 local presenceID = BNGetFriendInfo(x)
  40.                 Friends[presenceID] = {BNGetFriendInfo(x)}
  41.             end
  42.         end
  43.     end
  44. end
  45.  
  46. ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_INLINE_TOAST_ALERT", FilterBNLoginSpam)
  47.  
  48. -- -- Announces login while logged into App.
  49. function events:BN_TOON_NAME_UPDATED(event, ...)
  50.     for x = 1, BNGetNumFriends() do
  51.         local friendPresenceID, friendName, friendBtag, _, friendToonName, friendToonID, friendGame, friendOnline = BNGetFriendInfo(x)
  52.         local friends = Friends[friendPresenceID]
  53.  
  54.         if friends and friends[7] ~= friendGame then
  55.             if friends[7] == "App" then
  56.                 print(BATTLENET_FONT_COLOR_CODE .. friendName .. " (" .. BNet_GetClientEmbeddedTexture(friendGame, 14) .. (friendToonName and friendToonName or "") .. ") has come online.")
  57.             end
  58.             Friends[friendPresenceID] = {BNGetFriendInfo(x)}
  59.         end
  60.     end
  61. end
  62.  
  63. events.BN_FRIEND_TOON_ONLINE = events.BN_TOON_NAME_UPDATED
  64.  
  65. function events:BN_FRIEND_ACCOUNT_OFFLINE(event, ...)
  66.     for x = 1, BNGetNumFriends() do
  67.         local presenceID = BNGetFriendInfo(x)
  68.         Friends[presenceID] = {BNGetFriendInfo(x)}
  69.     end
  70. end

Last edited by Niketa : 05-18-14 at 10:59 PM.
  Reply With Quote