WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Triggering sound after countdown. (https://www.wowinterface.com/forums/showthread.php?t=59778)

Kajuvra 02-01-24 07:56 AM

Triggering sound after countdown.
 
So ive created an addon that will trigger a sound file at the start of a race but the player aka racers who have the addon aren't hearing the sound file being played and i dunno why. any help would be greatly appreciated

Code:

GnomeRunner.soundFile = "Interface\\AddOns\\GnomeRunner\\Sounds\\GnomeMaleCharge03.ogg"
Code:

-- Function to trigger the sound for race start
GnomeRunner.PlayRaceStartSound = function()
    if IsInRaid() and UnitIsGroupLeader("player") then
        PlaySoundFile(GnomeRunner.soundFile)
        C_ChatInfo.SendAddonMessage(GnomeRunner.addonPrefix, "START_RACE_SOUND", "RAID")
    end
end

-- Inside the StartRace function
function GnomeRunner.StartRace()
    print("StartRace function called")

    if not GnomeRunner.raceInProgress then
        GnomeRunner.raceInProgress = true
        GnomeRunner.raceStartTime = GetServerTime()
        GnomeRunner.totalDeaths = 0
        GnomeRunner.totalRacers = 0
        GnomeRunner.totalGoldDistributed = 0

        local countdown = GnomeRunner.countdownSeconds
        local countTimer

        local DisplayCountdown = function(count)
            if count > 0 then
                SendChatMessage(count, "RAID_WARNING")
            else
                SendChatMessage("GO GO GO! " .. GnomeRunner.raceName .. " has just begun!", "RAID_WARNING")
                print("Sending addon message: START_RACE")  -- Add this line for debugging
                GnomeRunner.PlayRaceStartSound()  -- Trigger the sound here
            end
        end

        countTimer = C_Timer.NewTicker(1, function()
            if countdown == GnomeRunner.countdownSeconds then
                SendChatMessage("The Race: " .. GnomeRunner.raceName .. " is starting!", "RAID_WARNING")
            end

            DisplayCountdown(countdown)

            countdown = countdown - 1
            if countdown < 0 then
                countTimer:Cancel()
                GnomeRunner.frame:SetScript("OnUpdate", function(_, elapsed)
                    GnomeRunner.OnUpdate(elapsed)
                end)
            end
        end)
    else
        print("Race already in progress.")
    end
end

The Part of the code to recieve the message and play the sound.

Code:

function GnomeRunner.OnChatMsgAddon(prefix, message, channel, sender)
    if prefix == GnomeRunner.addonPrefix then
        print("Addon message received:", message)

        if message == "START_RACE" then
            print("Received START_RACE. Playing sound.")
            PlaySoundFile(GnomeRunner.soundFile)
        elseif message == "START_RACE_SOUND" then
            PlaySoundFile(GnomeRunner.soundFile)
        end
    end
end


SDPhantom 02-01-24 12:20 PM

Have you registered your addon chat messages to be received using C_ChatInfo.RegisterAddonMessagePrefix()?
This tells the Blizzard chat servers that you're available to receive messages marked with your addon message prefix.

Kajuvra 02-01-24 05:46 PM

this was it! its working now! thank you so much! still so many other issues but crossed one thing off the list thank you so much! gotta credit ya for the assist :D


All times are GMT -6. The time now is 01:17 PM.

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