View Single Post
03-26-13, 10:14 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
GetSpellCooldown returns the timestamp of when you first cast it and its duration. All you need to do is subtract the current time from that to get how much time is left.

Here's a complete example.
Lua Code:
  1. local text = UIParent:CreateFontString(nil, nil, 'GameFontNormal')
  2. text:SetPoint('CENTER')
  3. CreateFrame('frame'):SetScript('OnUpdate', function()
  4.  local start, duration = GetSpellCooldown('conflagrate')
  5.  if duration > 2 then
  6.   local timeLeft = start + duration - GetTime() -- time until it recharges the first charge, in seconds
  7.   text:SetFormattedText('%d seconds until conflagrate', timeLeft)
  8.  else
  9.   text:SetText('Conflagrate not on cooldown')
  10.  end
  11. end)

Last edited by semlar : 03-26-13 at 10:23 PM.
  Reply With Quote