This is not how I'd make it but it's not my addon so... not going to rewrite it
Code:
local function StopTimer(...)
local name = ...
local global = "SKTIMERS_"..name
_G[global]:SetScript("OnUpdate",nil)
_G[global] = nil
print("Stopped timer: "..name)
end
local function CreateTimer(...)
local name,duration,mode,chime = ...
local f = CreateFrame("Frame","SKTIMERS_"..name)
f.d = duration
-- Duration String
local sDuration = function(duration)
if duration > 60 then
return string.format("'%.2f' minutes",(duration/60))
else
return "'"..duration.."' seconds"
end
end
-- Create chimes and verbose
if chime then
chime = chime.."."
f.chime = function()
PlaySoundFile(chime,"master")
end
else
chime = "default chime."
f.chime = function()
PlaySound("LEVELUPSOUND","master") -- see here for alternate sounds: http://www.wowwiki.com/API_PlaySound
end
end
if mode then -- Create timer
mode = strlower(mode)
if mode == "reoccuring" then
mode = "Reoccuring"
f:SetScript("OnUpdate",function(self,elapsed)
self.d = self.d - elapsed
if self.d < 0 then
self.chime()
self.d = duration
end
end)
elseif mode == "onetime" then
mode = "Onetime"
f:SetScript("OnUpdate",function(self,elapsed)
self.d = self.d - elapsed
if self.d < 0 then
self.chime()
StopTimer(name)
end
end)
end
end
print(mode.." timer created named '"..name.."' for "..sDuration(duration).." using "..chime)
end
local params = {}
local function slash_handler(commands)
if not commands or commands == "" then print("Proper format: /skt 'name' 'duration' 'reoccuring/onetime'") return end
wipe(params)
for cmd in commands:lower():gmatch("[%S]+") do
tinsert(params,cmd)
end
local name,duration,mode,chime = params[1],tonumber(params[2]),params[3],params[4]
if not duration then print("Invalid formatting") return end
local global = "SKTIMERS_"..name
if _G[global] and type(_G[global]) == "table" then -- Looks for existing Timer
if duration <= 0 then
StopTimer(name)
else
print("Timer named '"..name.."' already exists. To change duration please stop timer and create a new one.")
end
else -- No timer found, make one with a duration > 0
if duration <= 0 then print("Duration must be greater than 0") return end
if mode and type(mode) == "string" then -- If there's a mode specified, use it.
mode = strlower(mode)
if mode == "reoccuring" or mode == "onetime" then
CreateTimer(name,duration,mode,chime)
else
print("Invalid mode type: "..mode)
end
else
CreateTimer(name,duration,"onetime",chime)
end
end
end
SLASH_SKTIMERS1,SLASH_SKTIMERS2 = "/skt", "/sktimers"
SlashCmdList["SKTIMERS"] = slash_handler
--[[
Here are some examples of what your slash commands could be:
Let's create a timer that will reoccur every 30 minutes.
/skt DKP 1800 reoccuring
-- "Reoccuring timer created named 'DKP' for '30.00' minutes using default chime."
1800 is the duration of 30 minutes in seconds.
Let's do the same but with a custom sound instead.
/skt DKP 1800 reoccuring "Interface\AddOns\Sounds\Alarm.mp3"
-- "Reoccuring timer created named 'DKP' for '30.00' minutes using "Interface\AddOns\Sounds\Alarm.mp3"."
This should now assign the chime function to use a specified alarm file.
Creating a simple 1 time alarm for a specific duration is simple.
/skt Hearthstone 600
-- "Onetime timer created named 'Hearthstone' for '10.00' minutes using default chime."
If the mode is not specified then it will default to "onetime" and a default chime will be added.
To stop any timer use the same case sensitive name and 0 for the duration.
/skt Hearthstone 0
-- "Timer stopped: Hearthstone"
]]--
Replace the whole file contents with this, should have outstanding issues fixed.