1. #1

    How do I broadcast sound files to players in group with my addon?

    I posted a thread yesterday asking for help and while help was provided I'm still lost, so any help would be appreciated.

    I'll post the relevant code for what I've got so far:

    Code:
    if not ReceiveSoundFrame then
    
       ReceiveSoundFrame = CreateFrame("Frame")
    
    end
    
    local function OnEvent(self, event, prefix, message, channel, sender)
    
       if prefix == "OWQ" then
    
          print("Playing sound sent from: " .. sender)
    
          PlaySoundFile(message)
    
       end
    
    end
    
    local frame = ReceiveSoundFrame
    
    frame:RegisterEvent("CHAT_MSG_ADDON")
    
    frame:SetScript("OnEvent", OnEvent)
    
    local soundFile = "Interface\\AddOns\\OverwatchQuotes\\Sounds\\Pharah\\Justice_rains_from_above!.ogg"
    SendAddonMessage("OWQ", soundFile, "RAID")
    That SendAddonMessage is triggered by a button press but I didn't include that part because I don't think it's relevant for this troubleshooting.

    So what happens when I click that button is it plays the soundfile, and it prints the ""Playing sound sent from: " .. sender" line, but my friend who also has my addon does not hear or see anything. I'm not sure if the example I'm looking at has outdated/bad code (it's from 7 years ago) or if I somehow put it together wrong but if anyone could steer me in the right direction I'd be very appreciative.

  2. #2
    While I'm not getting the need for a separate thread on the same topic, I can only refer to the info that was posted there:
    You're omitting the call to RegisterAddonMessagePrefix.
    The CHAT_MSG_ADDON event seems to be a bit trigger-happy when it comes to invoking handlers that haven't been primed by the afore-mentioned prefix registration method, at least according to this older thread. This could explain why the sound is being played on your client, while your fellow addon-users don't hear anything.
    And on a more obvious note: You're in a raid/party with your friend?
    Last edited by speku; Yesterday at 08:20 PM.

  3. #3
    Quote Originally Posted by speku View Post
    While I'm not getting the need for a separate thread on the same topic, I can only refer to the info that was posted there:
    You're omitting the call to RegisterAddonMessagePrefix.
    The CHAT_MSG_ADDON event seems to be a bit trigger-happy when it comes to invoking handlers that haven't been primed by the afore-mentioned prefix registration method, at least according to this older thread. This could explain why the sound is being played on your client, while your fellow addon-users don't hear anything.
    And on a more obvious note: You're in a raid/party with your friend?
    My apologies for the second topic, I'm so used to reddit in which you can't actually bump topics so I just instinctively made another.

    Would registering that prefix just be as simple as adding this line before all prefix usage?
    Code:
    RegisterAddonMessagePrefix("OWQ")
    And that's it? Also yep, we are grouped at all times while testing.

  4. #4
    As far as the linked documentation goes, that should be it. However I'm not sure if it makes a difference when you register the prefix. The PLAYER_ENTERING_WORLD handler seems to be the common place to do it. You can always print the return value "print(RegisterAddonMessagePrefix("OWQ")) to see whether the registration was successful.

  5. #5
    Quote Originally Posted by speku View Post
    As far as the linked documentation goes, that should be it. However I'm not sure if it makes a difference when you register the prefix. The PLAYER_ENTERING_WORLD handler seems to be the common place to do it. You can always print the return value "print(RegisterAddonMessagePrefix("OWQ")) to see whether the registration was successful.
    Yep, seems like it was successful without using PLAYER_ENTERING_WORLD at all, but I'll keep that in mind if I run into any hurdles. I'll have to test this later when I have time and then continue development!

    Thanks for the help.

  6. #6
    I would suggest not using PLAYER_ENTERING_WORLD. That event fires every time you load into somewhere, like an instance or a continent. The most common addon initialize event is PLAYER_LOGIN, which happens after you first login and after a /reload, both times are fresh instances of the UI. Almost everything in the API is available at that time and it happens after all addons are loaded and before the loading screen goes away.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •