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