WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SendAddonMessage to Channel not working (https://www.wowinterface.com/forums/showthread.php?t=58645)

hamunaptra 03-21-21 04:48 AM

SendAddonMessage to Channel not working
 
1 Attachment(s)
As a followup to my previous post about sending messages around...

It seems that using SendAddonMessage with a custom channel doesn't work (or I'm doing something totally wrong).

If I send a message with SendAddonMessage to a party, it works fine, but if I do it to a (custom) channel, nothing get's received.

Sample project attached. What am I doing wrong? It looks right...

Code:

SLASH_ZSCT1 = "/zsct"

SlashCmdList["ZSCT"] = function(msg)
    print("Sent message through party ...")
    C_ChatInfo.SendAddonMessage(prefix, "sent using party")
    print("Sent message through channel (" .. channelid .. ") ...")
    C_ChatInfo.SendAddonMessage(prefix, "sent using channel", "CHANNEL", channelid)
end

local function zSendChatTest_EventHandler(self, event, pre, msg, distribution, sender)
    if pre == prefix then
        print("Received message " .. msg)
    end
end

channelname = "zsendchattest"
prefix = "zsendchattest"
password = "secret"

JoinChannelByName(channelname, password)
channelid = GetChannelName(channelname)

C_ChatInfo.RegisterAddonMessagePrefix(prefix)

zSendChatTest_Frame = CreateFrame("Frame")
zSendChatTest_Frame:SetScript("OnEvent",  zSendChatTest_EventHandler)
zSendChatTest_Frame:RegisterEvent("CHAT_MSG_ADDON")

print("ZSCT Loaded")

Results:
Client 1 ("master")


Client 2 ("slave")

Ketho 03-25-21 07:47 AM

This works for me fine on Retail (I didn't bother writing code to join a specific chat channel and get the index from that)

I also didn't test it with another player or account, just with myself
Lua Code:
  1. local prefix = "SomePrefix123"
  2. local playerName = UnitName("player")
  3.  
  4. local function OnEvent(self, event, ...)
  5.     if event == "CHAT_MSG_ADDON" then
  6.         print(event, ...)
  7.     elseif event == "PLAYER_ENTERING_WORLD" then
  8.         local isInitialLogin, isReloadingUi = ...
  9.         if isInitialLogin or isReloadingUi then
  10.             C_ChatInfo.RegisterAddonMessagePrefix(prefix)
  11.             C_ChatInfo.SendAddonMessage(prefix, "Hello world!", "CHANNEL", 5)
  12.         end
  13.     end
  14. end
  15.  
  16. local f = CreateFrame("Frame")
  17. f:RegisterEvent("CHAT_MSG_ADDON")
  18. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  19. f:SetScript("OnEvent", OnEvent)

hamunaptra 03-25-21 11:40 AM

Hm... that also works across different chars on different accounts, so yeay :).

I think the problem is/was, that my program was joining the channel too early in the loading process (immediately instead of after entering the world). With that change, it now works in my bigger addon, as well.

Thank you!


All times are GMT -6. The time now is 06:26 AM.

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