Originally Posted by 10leej
I currently use this script I found to run a coundown timer, but I'm wondering if there's a way I can call DBM's countdown function with this script as well
Lua Code:
local defaultcdtime = 6 local channel = "RAID_WARNING" local frame = CreateFrame("frame", nil) SlashCmdList['COUNTDOWN'] = function(newtime) if newtime ~= "" then cdtime = newtime+1 else cdtime = defaultcdtime+1 end local ending = false local start = floor(GetTime()) local throttle = cdtime frame:SetScript("OnUpdate", function() if ending == true then return end local countdown = (start - floor(GetTime()) + cdtime) if (countdown + 1) == throttle and countdown >= 0 then if countdown == 0 then SendChatMessage('Pulling', channel) throttle = countdown ending = true else SendChatMessage(countdown, channel) throttle = countdown end end end) end SLASH_COUNTDOWN1 = "/inc"
|
If I were you, I'd maybe make a slight change to your existing code which you posted:
Lua Code:
local defaultcdtime = 6
local channel = "RAID_WARNING"
local frame = CreateFrame("frame", nil)
SlashCmdList['COUNTDOWN'] = function(newtime)
local cdtime = newtime and ( newtime + 1 ) or ( defaultcdtime + 1 );
local throttle, ending, start, msg = cdtime, false, floor(GetTime()), "";
frame:SetScript("OnUpdate", function()
if ending then
frame:SetScript("OnUpdate", nil);
return;
end
local countdown = ( start - floor(GetTime()) + cdtime );
if ( ( ( countdown + 1 ) == throttle ) and ( countdown >= 0 ) ) then
ending = ( countdown == 0 );
throttle = countdown;
msg = ( countdown == 0 ) and "Pulling" or countdown;
SendChatMessage(msg, channel);
end
end);
end
SLASH_COUNTDOWN1 = "/inc"
The only part changed is where the function returns out if var
ending is true. The way it is, it'll check the value of
ending every time your frames are drawn which can be up to 100 times per second.
I've changed it so that instead of it just returning out time and time again, it removes the function from the OnUpdate code altogether. When the function is called, it auto re-creates the function anyway.
I tidied it up a bit while I was at it.