View Single Post
05-12-13, 02:20 PM   #3
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by 10leej View Post
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:
  1. local defaultcdtime = 6
  2. local channel = "RAID_WARNING"
  3.  
  4. local frame = CreateFrame("frame", nil)
  5. SlashCmdList['COUNTDOWN'] = function(newtime)
  6.     if newtime ~= "" then
  7.         cdtime = newtime+1
  8.     else
  9.         cdtime = defaultcdtime+1
  10.     end  
  11.     local ending = false
  12.     local start = floor(GetTime())
  13.     local throttle = cdtime
  14.     frame:SetScript("OnUpdate", function()
  15.         if ending == true then return end
  16.         local countdown = (start - floor(GetTime()) + cdtime)
  17.         if (countdown + 1) == throttle and countdown >= 0 then
  18.             if countdown == 0 then
  19.                 SendChatMessage('Pulling', channel)
  20.                 throttle = countdown
  21.                 ending = true
  22.             else
  23.                 SendChatMessage(countdown, channel)
  24.                 throttle = countdown
  25.             end
  26.         end
  27.     end)
  28. end
  29. SLASH_COUNTDOWN1 = "/inc"
If I were you, I'd maybe make a slight change to your existing code which you posted:

Lua Code:
  1. local defaultcdtime = 6
  2. local channel = "RAID_WARNING"
  3.  
  4. local frame = CreateFrame("frame", nil)
  5.  
  6. SlashCmdList['COUNTDOWN'] = function(newtime)
  7.     local cdtime = newtime and ( newtime + 1 ) or ( defaultcdtime + 1 );
  8.     local throttle, ending, start, msg = cdtime, false, floor(GetTime()), "";
  9.     frame:SetScript("OnUpdate", function()
  10.         if ending then
  11.             frame:SetScript("OnUpdate", nil);
  12.             return;
  13.         end
  14.         local countdown = ( start - floor(GetTime()) + cdtime );
  15.         if ( ( ( countdown + 1 ) == throttle ) and ( countdown >= 0 ) ) then
  16.             ending = ( countdown == 0 );
  17.             throttle = countdown;
  18.             msg = ( countdown == 0 ) and "Pulling" or countdown;
  19.             SendChatMessage(msg, channel);
  20.         end
  21.     end);
  22. end
  23. 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.
__________________
__________________
  Reply With Quote