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:
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:
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:RegisterEvent("PLAYER_LOGIN")
events:RegisterEvent("BN_TOON_NAME_UPDATED")
events:RegisterEvent("BN_FRIEND_TOON_ONLINE")
events:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
events:SetScript("OnEvent", function(self, event, ...)
return self[event] and self[event](self, event, ...)
end)
local Friends = {}
-- Get online players.
function events:ADDON_LOADED(event, addon)
if addon == "FriendsFixes" then
for x = 1, BNGetNumFriends() do
local presenceID = BNGetFriendInfo(x)
Friends[presenceID] = {BNGetFriendInfo(x)}
end
end
end
function events:PLAYER_LOGIN(event, ...)
for x = 1, BNGetNumFriends() do
local presenceID = BNGetFriendInfo(x)
Friends[presenceID] = {BNGetFriendInfo(x)}
end
end
-- Prevents double login spam from App.
local function FilterBNLoginSpam(self, event, type, ...)
local presenceID = select(12, ...)
if type == "FRIEND_ONLINE" and presenceID then
if Friends[presenceID][8] then
return true
else
for x = 1, BNGetNumFriends() do
local presenceID = BNGetFriendInfo(x)
Friends[presenceID] = {BNGetFriendInfo(x)}
end
end
end
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_INLINE_TOAST_ALERT", FilterBNLoginSpam)
-- -- Announces login while logged into App.
function events:BN_TOON_NAME_UPDATED(event, ...)
for x = 1, BNGetNumFriends() do
local friendPresenceID, friendName, friendBtag, _, friendToonName, friendToonID, friendGame, friendOnline = BNGetFriendInfo(x)
local friends = Friends[friendPresenceID]
if friends and friends[7] ~= friendGame then
if friends[7] == "App" then
print(BATTLENET_FONT_COLOR_CODE .. friendName .. " (" .. BNet_GetClientEmbeddedTexture(friendGame, 14) .. (friendToonName and friendToonName or "") .. ") has come online.")
end
Friends[friendPresenceID] = {BNGetFriendInfo(x)}
end
end
end
events.BN_FRIEND_TOON_ONLINE = events.BN_TOON_NAME_UPDATED
function events:BN_FRIEND_ACCOUNT_OFFLINE(event, ...)
for x = 1, BNGetNumFriends() do
local presenceID = BNGetFriendInfo(x)
Friends[presenceID] = {BNGetFriendInfo(x)}
end
end