Thread Tools Display Modes
07-17-13, 04:26 PM   #1
ConstanT1ne32
An Aku'mai Servant
 
ConstanT1ne32's Avatar
Join Date: Oct 2005
Posts: 34
Manual Timer/Alarm

Hey guys,


I looking for an addon that will allow me to set a custom time and will alert me when the timer runs out. I know that default blizzard alarm can do that but I'm looking for something with a bit more functionality.

For example, I'd like addon to be able to give me some sort of signal every 30 min to I can award DKP etc.

Are there any timer addon that can do that?
  Reply With Quote
07-18-13, 12:16 PM   #2
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by ConstanT1ne32 View Post
Hey guys,


I looking for an addon that will allow me to set a custom time and will alert me when the timer runs out. I know that default blizzard alarm can do that but I'm looking for something with a bit more functionality.

For example, I'd like addon to be able to give me some sort of signal every 30 min to I can award DKP etc.

Are there any timer addon that can do that?
Spent a little time trying to create something for you since I couldn't seem to find what you were looking for myself:

http://www.wowinterface.com/download...-SKTimers.html

Edit: This is untested but I believe it should be bug free.

Lua Code:
  1. local function StopTimer(...)
  2.     local name = ...
  3.     local global = "SKTIMERS_"..name
  4.     _G[global]:SetScript("OnUpdate",nil)
  5.     _G[global] = nil
  6.     print("Stopped timer: "..name)
  7. end
  8.  
  9. local function CreateTimer(...)
  10.     local name,duration,mode,chime = ...
  11.     local f = CreateFrame("Frame","SKTIMERS_"..name)
  12.     local f.d = duration
  13.     -- Duration String
  14.     local sDuration = function(duration)
  15.         if duration > 60 then
  16.             sDuration = string.format("'%.2f' minutes",(duration/60))
  17.         else
  18.             sDuration = "'"..duration.."' seconds"
  19.         end
  20.     end
  21.     -- Create chimes and verbose
  22.     if chime then
  23.         chime = chime.."."
  24.         f.chime = function()
  25.             PlaySoundFile(chime,"master")
  26.         end
  27.     else
  28.         chime = "default chime."
  29.         f.chime = function()
  30.             PlaySound(LEVELUPSOUND,"master") -- see here for alternate sounds: [url]http://www.wowwiki.com/API_PlaySound[/url]
  31.         end
  32.     end
  33.     if mode then -- Create timer
  34.         mode = strlower(mode)
  35.         if mode == "reoccuring" then
  36.             mode = "Reoccuring"
  37.             f:SetScript("OnUpdate",function(self,elapsed,duration)
  38.                 self.d = self.d - elapsed
  39.                 if self.d < 0 then
  40.                     self.chime()
  41.                     self.d = duration
  42.                 end            
  43.             end)
  44.         elseif mode == "onetime" then
  45.             mode = "Onetime"
  46.             f:SetScript("OnUpdate",function(self,elapsed,name)
  47.                 self.d = self.d - elapsed
  48.                 if self.d < 0 then
  49.                     self.chime()
  50.                     StopTimer(name)
  51.                 end
  52.             end        
  53.         end
  54.     end
  55.    
  56.     print(mode.." timer created named '"..name.."' for "..sDuration.." using "..chime)
  57. end
  58.  
  59. local function slash_handler(...)
  60.     local name,duration,mode,chime
  61.     if type(name) ~= "string" or type(duration) ~= "number" then print("Invalid formatting") return end
  62.     local global = "SKTIMERS_"..name
  63.     if _G[global] and type(_G[global]) == "table" then -- Looks for existing Timer
  64.         if duration <= 0 then
  65.             StopTimer(name)
  66.         else
  67.             print("Timer named '"..name.."' already exists. To change duration please stop timer and create a new one.")
  68.         end
  69.     else -- No timer found, make one with a duration > 0
  70.         if duration <= 0 then print("Duration must be greater than 0") return end
  71.         if mode and type(mode) == "string" then -- If there's a mode specified, use it.
  72.             mode = strlower(mode)
  73.             if mode == "reoccuring" or mode == "onetime" then
  74.                 CreateTimer(name,duration,mode,chime)
  75.             else
  76.                 print("Invalid mode type: "..mode)
  77.             end
  78.         else
  79.             CreateTimer(name,duration,"onetime",chime)
  80.         end
  81.     end
  82. end
  83.  
  84. SLASH_SKTIMERS1,SLASH_SKTIEMRS2 = "/skt", "/sktimers"
  85. SlashCmdList["SLASH_SKTIMERS"] = slash_handler
  86.  
  87. --[[
  88.     Here are some examples of what your slash commands could be:
  89.         Let's create a timer that will reoccur every 30 minutes.
  90.             /skt DKP 1800 reoccuring
  91.             -- "Reoccuring timer created named 'DKP' for '30.00' minutes using default chime."
  92.         1800 is the duration of 30 minutes in seconds.
  93.        
  94.         Let's do the same but with a custom sound instead.
  95.             /skt DKP 1800 reoccuring "Interface\AddOns\Sounds\Alarm.mp3"
  96.             -- "Reoccuring timer created named 'DKP' for '30.00' minutes using "Interface\AddOns\Sounds\Alarm.mp3"."
  97.         This should now assign the chime function to use a specified alarm file.
  98.        
  99.         Creating a simple 1 time alarm for a specific duration is simple.
  100.             /skt Hearthstone 600
  101.             -- "Onetime timer created named 'Hearthstone' for '10.00' minutes using default chime."
  102.         If the mode is not specified then it will default to "onetime" and a default chime will be added.
  103.        
  104.         To stop any timer use the same case sensitive name and 0 for the duration.
  105.             /skt Hearthstone 0
  106.             -- "Timer stopped: Hearthstone"
  107. ]]--

Last edited by suicidalkatt : 07-18-13 at 12:25 PM.
  Reply With Quote
07-18-13, 08:13 PM   #3
ConstanT1ne32
An Aku'mai Servant
 
ConstanT1ne32's Avatar
Join Date: Oct 2005
Posts: 34
Thanks so much for taking time to do this, I really appreciate it.

I did install it, but /skt doesn't seem to work for some reason:S. I checked in my addons list, it is active, however slash command doesn't work.
  Reply With Quote
07-18-13, 09:51 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
If that's the same code posted that has been packaged, the slash handler doesn't process the ... variable.

An ellipsis won't work there too, command-line is passed as a contiguous string and further arguments need to be parsed out

Replacing these lines
Code:
local function slash_handler(...)
    local name,duration,mode,chime
    if type(name) ~= "string" or type(duration) ~= "number" then print("Invalid formatting") return end
with
Code:
local params = {}
local function slash_handler(commands)
    if not commands or commands == "" then --[[show help?]] 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] -- could also use unpack
    if type(name) ~= "string" or not duration then print("Invalid formatting") return end
might work.
Warning: drycoded.
  Reply With Quote
07-18-13, 10:50 PM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Dridzt View Post
If that's the same code posted that has been packaged, the slash handler doesn't process the ... variable.

An ellipsis won't work there too, command-line is passed as a contiguous string and further arguments need to be parsed out

Replacing these lines
Code:
local function slash_handler(...)
    local name,duration,mode,chime
    if type(name) ~= "string" or type(duration) ~= "number" then print("Invalid formatting") return end
with
Code:
local params = {}
local function slash_handler(commands)
    if not commands or commands == "" then --[[show help?]] 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] -- could also use unpack
    if type(name) ~= "string" or not duration then print("Invalid formatting") return end
might work.
Warning: drycoded.
Thanks for the assistance Dridzt! Completely forgot they're passed as a single string, might be issues with the filepath for custom sounds. For params[3],params[4] added 'or nil' should there be no value in the table jic.

Updated with a help verbose where noted. Once again untested since I'm unable to get to a testing environment til Monday.

http://www.wowinterface.com/download...-SKTimers.html

Last edited by suicidalkatt : 07-18-13 at 10:55 PM. Reason: I accidentally a word.
  Reply With Quote
07-18-13, 11:00 PM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
The or nil is unnecessary (it will be nil anyway if a 3rd or 4th argument is not parsed out) but adding it won't break anything.

Edit: Btw just noticed that your alternate command (the verbose one) has a typo (SKTIEMRS2)

Last edited by Dridzt : 07-18-13 at 11:07 PM.
  Reply With Quote
07-19-13, 12:11 AM   #7
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Dridzt View Post
The or nil is unnecessary (it will be nil anyway if a 3rd or 4th argument is not parsed out) but adding it won't break anything.

Edit: Btw just noticed that your alternate command (the verbose one) has a typo (SKTIEMRS2)
I DUNT BULEEV U! *scurriez to fix*
  Reply With Quote
07-19-13, 09:42 AM   #8
ConstanT1ne32
An Aku'mai Servant
 
ConstanT1ne32's Avatar
Join Date: Oct 2005
Posts: 34
Updated to 1.1, still doesnt work
  Reply With Quote
07-19-13, 09:53 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by Dridzt View Post
Code:
for cmd in commands:lower():gmatch("[^%s]+") do
Just to let you know, you can use %S+ to match the inverse of %s+. Switching between lower and upper case performs the inverse match of the character class.



Originally Posted by Dridzt View Post
Code:
if type(name) ~= "string" or not duration then print("Invalid formatting") return end
You don't need to check the name parameter for two reasons. First, anything returning from the parameter extraction process will always be a string. Second, you're also checking if duration is valid, which can only happen when name is already given.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-19-13, 12:46 PM   #10
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Originally Posted by ConstanT1ne32 View Post
Updated to 1.1, still doesnt work
Does it print the "timer created for such and such"?

At a glance the only 'action' the mod takes is play a sound.
If you don't hear a sound the problem is with this line.
PlaySound(LEVELUPSOUND,"master").
It needs to be
PlaySound("LEVELUPSOUND","master")

Replace it and see if that fixes it.
  Reply With Quote
07-19-13, 01:20 PM   #11
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
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.
  Reply With Quote
07-19-13, 01:23 PM   #12
ConstanT1ne32
An Aku'mai Servant
 
ConstanT1ne32's Avatar
Join Date: Oct 2005
Posts: 34
Originally Posted by Dridzt View Post
Does it print the "timer created for such and such"?

At a glance the only 'action' the mod takes is play a sound.
If you don't hear a sound the problem is with this line.
PlaySound(LEVELUPSOUND,"master").
It needs to be
PlaySound("LEVELUPSOUND","master")

Replace it and see if that fixes it.
No it doesnt, it acts as if no addon installed.
  Reply With Quote
07-19-13, 01:36 PM   #13
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
We posted simultaneously, look at the post after the one you quoted.
  Reply With Quote
07-19-13, 02:10 PM   #14
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
v1.3 now up, minor fixes mentioned above as well as a reorder on the 'chime = chime.."."' to go after creating the chime function to avoid issues.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Manual Timer/Alarm


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off