Thread Tools Display Modes
05-15-14, 09:47 AM   #21
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
You're not using OnUpdate correctly. You're setting your "remaining" variable to 0 every time your script runs, and setting "sec" to 60, and then checking a variable named "secs" that isn't defined anywhere, and then checking if "remaining" and "secs" are not equal which (assuming the "sec" definition is actually meant to be "sec") will always pass because 0 will never be equal to 60 and those are the only values those variables can ever have, and you're not actually keeping track of how much time has elapsed at all.

Code:
-- This variable needs to be outside of the OnUpdate so it persists between executions:
local remaining = PROPOSAL_DURATION

f:SetScript("OnUpdate", function(self, elapsed) -- You need to know how much time has elapsed
	-- Deduct the elapsed time (since the last OnUpdate) from the total remaining time:
	remaining = remaining - elapsed

	local color = remaining > 20 and "20ff20" or remaining > 10 and "ffff00" or "ff0000"

	-- Use SetFormattedText here, and don't split the color code in the middle of the alpha value.
	text:SetFormattedText("Queue Expires in |cff%s%s|r", color, SecondsToTime(remaining))
end)

f:RegisterEvent("LFG_PROPOSAL_SHOW")
f:SetScript("OnEvent", function(self, event)
	if event == "LFG_PROPOSAL_SHOW" then
		-- Restart the timer:
		remaining = PROPOSAL_DURATION
		self:Show()
	else
		self:Hide()
	end
end)
Thank You again Phanx. Works like a charm.

Coke.
  Reply With Quote
05-19-14, 02:18 PM   #22
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Ok so here is the code I'm currently using is anyone is interested in adding it to one of there addons.

LFG:
Code:
	-- Code provided by Phanx from WoWInterface.com

	local PROPOSAL_DURATION = 60

	local f = CreateFrame("Frame", nil, LFGDungeonReadyPopup)

	-- This variable needs to be outside of the OnUpdate so it persists between executions:
	local remaining = PROPOSAL_DURATION

	f:SetScript("OnUpdate", function(self, elapsed) -- You need to know how much time has elapsed
		-- Deduct the elapsed time (since the last OnUpdate) from the total remaining time:
		remaining = remaining - elapsed

		local color = remaining > 20 and "20ff20" or remaining > 10 and "ffff00" or "ff0000"

		-- Use SetFormattedText here, and don't split the color code in the middle of the alpha value.
		LFGDungeonReadyDialog.label:SetFormattedText("Expires in |cff%s%s|r", color, SecondsToTime(remaining))
	end)

	f:RegisterEvent("LFG_PROPOSAL_SHOW")
	f:SetScript("OnEvent", function(self, event)
		if event == "LFG_PROPOSAL_SHOW" then
			-- Restart the timer:
			remaining = PROPOSAL_DURATION
			self:Show()
		else
			self:Hide()
		end
	end)
LFPvP:
Code:
	local f = CreateFrame("Frame", nil, PVPReadyDialog)

	-- Permission to use the following code given by Jordon 
	-- Author of SafeQueue -- http://www.curse.com/addons/wow/safequeue
	------------------------------------------------------------------------------------
	local queueTime
	local queue = 0
	local remaining = 0
	
	f:SetScript("OnUpdate", function(self)	
		if PVPReadyDialog:IsShown() then
			local secs = GetBattlefieldPortExpiration(queue)
			if secs and secs > 0 and remaining ~= secs then
				remaining = secs
				local color = secs > 20 and "20ff20" or secs > 10 and "ffff00" or "ff0000"
				PVPReadyDialog.label:SetFormattedText("Expires in |cff%s%s|r", color, SecondsToTime(secs))
			end
		end
	end)
	
	function f:UPDATE_BATTLEFIELD_STATUS()
		local queued
		for i=1, GetMaxBattlefieldID() do
			local status = GetBattlefieldStatus(i)
			if status == "queued" then
				queued = true
				if not queueTime then queueTime = GetTime() end
			elseif status == "confirm" then
				if queueTime then
					queueTime = nil
					remaining = 0
					queue = i
				end					
			end
			break
		end
		if not queued and queueTime then queueTime = nil end
	end	
	
	f:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
	f:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
	------------------------------------------------------------------------------------
Screenshots are below.

Thanks
Coke
Attached Thumbnails
Click image for larger version

Name:	LFG.png
Views:	175
Size:	94.4 KB
ID:	8100  Click image for larger version

Name:	PVP.png
Views:	174
Size:	109.6 KB
ID:	8101  
  Reply With Quote
06-15-14, 12:26 PM   #23
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Getting and Error

I get a error with the following code when ever someone refuses or I do not accept the LFG Invite. Is there a way to say "if nil then" ?

Thanks
Coke

Code:
	-- Code provided by Phanx from WoWInterface.com

	local PROPOSAL_DURATION = 60

	local f = CreateFrame("Frame", nil, LFGDungeonReadyPopup)

	-- This variable needs to be outside of the OnUpdate so it persists between executions:
	local remaining = PROPOSAL_DURATION

	
	f:SetScript("OnUpdate", function(self, elapsed) -- You need to know how much time has elapsed
		-- Deduct the elapsed time (since the last OnUpdate) from the total remaining time:
		remaining = remaining - elapsed

		local color = remaining > 20 and "20ff20" or remaining > 10 and "ffff00" or "ff0000"

		-- Use SetFormattedText here, and don't split the color code in the middle of the alpha value.
		local _, _, typeID, subtypeID, _, _, _, _, _, _, numMembers, _ = GetLFGProposal();
		if ( typeID == TYPEID_RANDOM_DUNGEON and subtypeID ~= LFG_SUBTYPEID_SCENARIO ) then
			LFGDungeonReadyDialog.label:SetFormattedText(RANDOM_DUNGEON_IS_READY.." |cff%s%s|r remaining.", color, SecondsToTime(remaining))
		else
            if ( numMembers > 1 ) then
                LFGDungeonReadyDialog.label:SetFormattedText(SPECIFIC_DUNGEON_IS_READY.." |cff%s%s|r remaining.", color, SecondsToTime(remaining));
            else
                LFGDungeonReadyDialog.label:SetFormattedText(SPECIFIC_INSTANCE_IS_READY.." |cff%s%s|r remaining.", color, SecondsToTime(remaining));
            end
		end
	end)

	f:RegisterEvent("LFG_PROPOSAL_SHOW")
	f:SetScript("OnEvent", function(self, event)
		if event == "LFG_PROPOSAL_SHOW" then
			-- Restart the timer:
			remaining = PROPOSAL_DURATION
			self:Show()
		else
			self:Hide()
		end
	end)
Error shown by Buggsack:
Code:
62x nExtras\nExtras-5.4.5.lua:445: attempt to compare number with nil
nExtras\nExtras-5.4.5.lua:445: in function <nExtras\nExtras.lua:434>

Locals:

Last edited by cokedrivers : 06-15-14 at 01:22 PM.
  Reply With Quote
06-15-14, 12:29 PM   #24
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
"if not variable" or "if variable == nil"
  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