WoW:API GetSpellCooldown: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
Retrieves the cooldown data of the spell specified.
Retrieves the cooldown data of the spell specified.


  local start, duration = GetSpellCooldown(spellID, "bookType");
  start, duration, enabled = GetSpellCooldown(spellName or spellID, "bookType");


----
==Arguments==
;''Arguments''
:;spellName : String - name of the spell to retrieve cooldown data for.
:;spellID : Number - The ID of the spell to retrieve cooldown data for
:;bookType : String - BOOKTYPE_SPELL or BOOKTYPE_PET depending on whether you wish to query the player or pet spellbook.


:(Number spellID)
==Returns==
:;startTime : Number - The time when the cooldown started (as returned by [[API GetTime|GetTime()]]); zero if no cooldown; current time if (enabled == 0).
:;duration : Number - Cooldown duration in seconds, 0 if spell is ready to be cast.
:;enabled : Number - 0 if the spell is active (Stealth, Shadowmeld, Presence of Mind, etc) and the cooldown will begin as soon as the spell is used/cancelled; 1 otherwise.


:;spellID : The ID of the spell to retrieve cooldown data for
==Example==
 
local start, duration, enabled = GetSpellCooldown("Presence of Mind");
:(string bookType)
if enabled == 0 then
 
  DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is currently active, use it and wait " .. duration .. " seconds for the next one.");
:;bookType : BOOKTYPE_SPELL or BOOKTYPE_PET depending on whether you wish to query the player or pet spellbook.
  elseif ( start > 0 and duration > 0) then
 
  DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is cooling down, wait " .. (start + duration - GetTime()) .. " seconds for the next one.");
----
;''Returns''
 
:(Number startTime, Number duration, Number enable)
 
:;startTime : The time when the cooldown started (as returned by [[API GetTime|GetTime()]]) or zero if no cooldown
:;duration : The number of seconds the cooldown will last, or zero if no cooldown
:;enable : Returns 1 when the spell cooldown starts, for abilities that can be toggled like Stealth, Shadowform this returns 0 when you activate it.
 
----
;''Example''
local start, duration = GetSpellCooldown(spellID, BOOKTYPE_SPELL);
  if ( start > 0 and duration > 0) then
Print('Please wait ' .. duration - ( GetTime() - start) .. ' seconds before using this spell.');
  else
  else
Print('Spell is ready.');
  DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is ready.");
  end
  end


;''Result''
===Result===
 
Checks status of the [[Presence of Mind]] cooldown and outputs the appropriate message to the default chat frame.
: Retrieves data. Does not (to my knowledge) actually change anything.
 
: "For the [[Nature's_Swiftness|Nature's Swiftness]] spell and posibly other spells that don't start their cooldown timer before they are used up the values retrieved by GetSpellCooldown change over time. The startTime returned is the current time (that this function was called), not the time the spell was cast. The duration is 0.001 not the spell's normal cooldown.


: In this way we can use GetSpellCooldown to see if this type of spell is active on the player without having to look at buffs and debuffs."
==Notes==
*The enabled return value allows addons to easily check if the player has used a buff-providing spell (such as Presence of Mind or Nature's Swiftness) without searching through the player's buffs.
*Values returned by this function are not updated immediately when UNIT_SPELLCAST_SUCCEEDED event is raised.

Revision as of 13:35, 25 September 2007

WoW API < GetSpellCooldown

Retrieves the cooldown data of the spell specified.

start, duration, enabled = GetSpellCooldown(spellName or spellID, "bookType");

Arguments

spellName
String - name of the spell to retrieve cooldown data for.
spellID
Number - The ID of the spell to retrieve cooldown data for
bookType
String - BOOKTYPE_SPELL or BOOKTYPE_PET depending on whether you wish to query the player or pet spellbook.

Returns

startTime
Number - The time when the cooldown started (as returned by GetTime()); zero if no cooldown; current time if (enabled == 0).
duration
Number - Cooldown duration in seconds, 0 if spell is ready to be cast.
enabled
Number - 0 if the spell is active (Stealth, Shadowmeld, Presence of Mind, etc) and the cooldown will begin as soon as the spell is used/cancelled; 1 otherwise.

Example

local start, duration, enabled = GetSpellCooldown("Presence of Mind");
if enabled == 0 then
 DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is currently active, use it and wait " .. duration .. " seconds for the next one.");
elseif ( start > 0 and duration > 0) then
 DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is cooling down, wait " .. (start + duration - GetTime()) .. " seconds for the next one.");
else
 DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is ready.");
end

Result

Checks status of the Presence of Mind cooldown and outputs the appropriate message to the default chat frame.

Notes

  • The enabled return value allows addons to easily check if the player has used a buff-providing spell (such as Presence of Mind or Nature's Swiftness) without searching through the player's buffs.
  • Values returned by this function are not updated immediately when UNIT_SPELLCAST_SUCCEEDED event is raised.