I’m trying to write function which will play custom alert sound, based on Blizzard’s built-in stopwatch timer:
-- Init
local dgframe = CreateFrame("Frame")
dgframe:SetScript("OnEvent", function(self, event, a1)
if event == "PLAYER_LOGIN" then print("Use /dg to toggle on/off");
end
end)
dgframe:RegisterEvent("PLAYER_LOGIN")
-- Reset timer on key input
local function timeres(self, key)
StopwatchTicker.timer = 0;
if StopwatchTicker.timer == 5 then
PlaySoundFile("Interface\\AddOns\\DG\\horn.mp3");
end
end
dgframe:SetScript("OnKeyDown", timeres)
dgframe:SetPropagateKeyboardInput(true)
--toggle on/off
SLASH_DGTOGGLE1 = "/dg";
function SlashCmdList.DGTOGGLE(msg, editBox)
Stopwatch_Toggle();
Stopwatch_Play();
end
if statement works, when both “StopwatchTicker.timer” values within the “timeres” function are the same, so I assume it needs some type of “OnUpdate” function to read timer in real time after it gets reset on key press. This is my first time coding an addon, so I’m absolutely lost. Could you point me to the right direction? Thanks
local function OnEvent(self, event, addon)
if addon == "Blizzard_TimeManager" then
function Stopwatch_FinishCountdown()
Stopwatch_Clear()
PlaySoundFile("Interface\\AddOns\\DG\\horn.mp3")
end
self:UnregisterEvent(event)
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", OnEvent)
Thanks for taking time to help me. From what I’ve checked /sw is not available for Classic WoW UI, since it was added in 2.4.3 as it seems: https://wow.gamepedia.com/Patch_2.4.3#User_Interface
Nevertheless I was able to run countdown via: Stopwatch_StartCountdown(0, 0, 30); Stopwatch_Play()
This alters the logic of the addon that I had in mind originally, but works so thank you again!