Thread Tools Display Modes
05-08-14, 10:19 PM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Count Down Timer

I was wondering if there is a way to add a count down timer to the frame that you click enter dungeon on to show exactly how long you have. Lately ive qued for ramdoms and been in the middle of a quest and would like to lnow how long I have u ntill the window closes.

I am on my phone right now but with /fstack I was able to get the frame name. I would something like
Code:
countdowntimer = CreateFrame ("Frame", nil, (the frames name))
countdowntimer:SetPoint ("BOTTOM", (the frame name), 0, 0)
to create a frame to put the count down in.

Ive seen DBM have a count down stays bar show. But I'm just looking for a numeric count down nothing dance.

Ill look threw DBM maybe I can find how they get the timer info.

Coke
  Reply With Quote
05-08-14, 10:47 PM   #2
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Originally Posted by cokedrivers View Post
I was wondering if there is a way to add a count down timer to the frame that you click enter dungeon on to show exactly how long you have. Lately ive qued for ramdoms and been in the middle of a quest and would like to lnow how long I have u ntill the window closes.

I am on my phone right now but with /fstack I was able to get the frame name. I would something like
Code:
countdowntimer = CreateFrame ("Frame", nil, (the frames name))
countdowntimer:SetPoint ("BOTTOM", (the frame name), 0, 0)
to create a frame to put the count down in.

Ive seen DBM have a count down stays bar show. But I'm just looking for a numeric count down nothing dance.

Ill look threw DBM maybe I can find how they get the timer info.

Coke
The basic function is simple enough. I use this for a pull timer, though it uses a chat output
Lua Code:
  1. local pull, seconds, onesec
  2. local frame = CreateFrame("Frame")
  3. frame:Hide()
  4. frame:SetScript("OnUpdate", function(self, elapsed)
  5.     --Start DBM pull timer
  6.     onesec = onesec - elapsed
  7.     pull = pull - elapsed
  8.     if pull <= 0 then
  9.         SendChatMessage("Pulling!", cfg.channelannounce)
  10.         self:Hide()
  11.     elseif onesec <= 0 then
  12.         SendChatMessage(seconds, cfg.channelannounce)
  13.         seconds = seconds - 1
  14.         onesec = 1
  15.     end
  16. end)
  17. SlashCmdList["COUNTDOWN"] = function(t)
  18.     t = tonumber(t) or 6
  19.     pull = t + 1
  20.     seconds = t
  21.     onesec = 1
  22.     frame:Show()
  23. end
  24. SLASH_COUNTDOWN1 = "/inc"

just replace SendChatMessage and a few other things with a status bar fill I imagine.
__________________
Tweets YouTube Website
  Reply With Quote
05-08-14, 11:55 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by cokedrivers View Post
Ive seen DBM have a count down stays bar show. But I'm just looking for a numeric count down nothing dance.

Ill look threw DBM maybe I can find how they get the timer info.
DBM just hardcodes it at 40 seconds; AFAIK there is no API function to get the remaining time.

Code:
local PROPOSAL_DURATION = 40

local frame = CreateFrame("Frame", nil, LFGDungeonReadyPopup)
frame:SetPoint("TOP", LFGDungeonReadyPopup, "BOTTOM", 0, -5)
frame:SetSize(20, 20) -- doesn't actually matter, just needs nonzero dimensions

local text = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
text:SetPoint("TOP")

local t = PROPOSAL_DURATION
frame:SetScript("OnUpdate", function(self, elapsed)
     t = t - elapsed
     text:SetText(floor(t + 0.5))
end)

frame:RegisterEvent("LFG_PROPOSAL_SHOW")
frame:SetScript("OnEvent", function(self, event)
     if event == "LFG_PROPOSAL_SHOW" then
          t = PROPOSAL_DURATION
          self:Show()
     else
          self:Hide()
     end
end)
If you wanted a status bar (complete with gradient coloring) instead:

Code:
local PROPOSAL_DURATION = 40

local bar = CreateFrame("StatusBar", nil, LFGDungeonReadyPopup)
bar:SetPoint("TOPLEFT", LFGDungeonReadyPopup, "BOTTOMLEFT", 0, -5)
bar:SetPoint("TOPRIGHT", LFGDungeonReadyPopup, "BOTTOMRIGHT", 0, -5)
bar:SetHeight(5)
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetMinMaxValues(0, PROPOSAL_DURATION)

local spark = bar:CreateTexture(nil, "OVERLAY")
spark:SetPoint("CENTER", bar:GetStatusBarTexture(), "LEFT")
spark:SetSize(5, 8) -- height should be about 2.5x width
spark:SetAlpha(0.5)
spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
spark:SetBlendMode("ADD")

local t = PROPOSAL_DURATION
local HALF_POINT = PROPOSAL_DURATION / 2
bar:SetScript("OnUpdate", function(self, elapsed)
     t = t - elapsed
     self:SetValue(t)
     if t > HALF_POINT then
          self:SetStatusBarColor(1, t / PROPOSAL_DURATION, 0)
     else
          self:SetStatusBarColor(1 - (t / PROPOSAL_DURATION), 1, 0)
     end
end)

frame:RegisterEvent("LFG_PROPOSAL_SHOW")
frame:SetScript("OnEvent", function(self, event)
     if event == "LFG_PROPOSAL_SHOW" then
          t = PROPOSAL_DURATION
          self:Show()
     else
          self:Hide()
     end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 05-09-14 at 12:03 AM.
  Reply With Quote
05-09-14, 07:34 AM   #4
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Thank you for both versions, ill test it tonight. Now if the 40 seconds is to long all ill need to change is the 40 at the top correct?

Coke

EDIT: Will this also work for PvP, or is that a different frame?

Last edited by cokedrivers : 05-09-14 at 02:51 PM.
  Reply With Quote
05-09-14, 07:25 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
PvP is a different frame, a different event, and possibly a different duration, but the general idea should be the same.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-09-14, 09:47 PM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
PvP is a different frame, a different event, and possibly a different duration, but the general idea should be the same.
so for the PvP I was able to create this:
Code:
	local PROPOSAL_DURATION = 90

	local PVPTimerFrame = CreateFrame("Frame", nil, PVPReadyDialog)
	PVPTimerFrame:SetPoint("TOP", PVPReadyDialog, "BOTTOM", -1, 20)
	PVPTimerFrame:SetWidth(300)
	PVPTimerFrame:SetHeight(35)
	PVPTimerFrame:SetBackdrop({ 
		bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], 
		edgeFile = [[Interface\AddOns\nExtras\Media\UI-DialogBox-Border.blp]], 
		edgeSize = 25, insets = { left = 5, right = 5, top = 5, bottom = 5 } 
	})
	PVPTimerFrame:SetBackdropColor(0, 0, 0, 1)
	
	local text = PVPTimerFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
	text:SetPoint("CENTER")

	local t = PROPOSAL_DURATION
	PVPTimerFrame:SetScript("OnUpdate", function(self, elapsed)
		 t = t - elapsed
		 text:SetText(floor(t + 0.5).."s left to Enter Battleground.")
	end)

	PVPTimerFrame:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
	PVPTimerFrame:SetScript("OnEvent", function(self, event)
		 if event == "UPDATE_BATTLEFIELD_STATUS" then
			  t = PROPOSAL_DURATION
			  self:Show()
		 else
			  self:Hide()
		 end
	end)
Which inturn gave me this:


But the time keeps reseting, I don't think I have the correct event. There are like 6 of them but in the event doc page the other ones are for like World PvP not battlegrounds.

Thanks for any help.

Coke
  Reply With Quote
05-10-14, 03:27 AM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I don't think the event is the issue here, more like the timer onupdate. Elapsed is a time in miliseconds, and the 90 sec timer is a decimal. I can make an example tonight how do it, if noone will do it faster, but i have to leave now.
  Reply With Quote
05-10-14, 05:23 AM   #8
karmamuscle
A Cobalt Mageweaver
 
karmamuscle's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 205
Originally Posted by cokedrivers View Post
That looks really useful for dungeon/lfr/pvp queues!
Is it something that you plan to release as a standalone addon?
__________________
55 89 144 233 377 610 987 1597 2584 4181 6765
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Count Down Timer


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