WoW:API GetSpellCooldown: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
m (Move page script moved page API GetSpellCooldown to API GetSpellCooldown without leaving a redirect)
 
(11 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{wowapi}}
Retrieves the cooldown data of the spell specified.
Retrieves the cooldown data of the spell specified.


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


;
==Arguments==
:;spellName
:: String - name of the spell to retrieve cooldown data for.
:;spellID
:: Number - ID of the spell in the database
:;slotID
:: Number - Valid values are 1 through total number of spells in the spellbook on all pages and all tabs, ignoring empty slots.
:;bookType
:: String - BOOKTYPE_SPELL or BOOKTYPE_PET depending on whether you wish to query the player or pet spellbook.


----
==Returns==
;''Arguments''
:;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.


:(Number spellID)
==Example==
 
  local start, duration, enabled = GetSpellCooldown("Presence of Mind");
:;spellID : The ID of the spell to retrieve cooldown data for
if enabled == 0 then
 
  DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is currently active, use it and wait " .. duration .. " seconds for the next one.");
:(Number spellnumTab)
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.");
:;spellnumTab : The tab within your spellbook, ignore empty slots. As of 1.41 this argument appears to be required, but not used.
else
 
  DEFAULT_CHAT_FRAME:AddMessage("Presence of Mind is ready.");
----
end
;''Returns''


:(Number startTime, Number duration, Number enable)
===Result===
Checks status of the [[Presence of Mind]] cooldown and outputs the appropriate message to the default chat frame.


:;startTime : The time when the cooldown started (as returned by [[API GetTime|GetTime()]]) or zero if no cooldown
==Example==
:;duration : The number of seconds the cooldown will last, or zero if no cooldown
local name = GetSpellInfo(28370);
local start, duration, enabled = GetSpellCooldown(name);
etc...


:;enable : Appears to be set to 1 if this spell is in cooldown, and 0 otherwise.
Example of using SpellIDs to retrieve cooldown info


----
;''Example''
local start, duration = GetSpellCooldown(spellID, spellnumTab);
if ( start > 0 and duration > 0) then
Print('Please wait ' .. duration - ( GetTime() - start) .. ' seconds before using this spell.');
else
Print('Spell is ready.');
end


;''Result''
==Example==
local start, duration, enabled = GetSpellCooldown(48505);


: Retrieves data. Does not (to my knowledge) actually change anything.
===Result===
returns 0, 0, 1 if the spell 'Starfall' is not on Cooldown
otherwise it returns GetTime(), 90, 1


----
;''Description''


: Retrieves data on the cooldown of a specific spell within your spellbook.
==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.
{{Template:WoW API}}
*Values returned by this function are not updated immediately when UNIT_SPELLCAST_SUCCEEDED event is raised.
[[Category:API Functions|GetSpellCooldown]]
*GetSpellCooldown() does not directly accept SpellIDs. You must first retrieve the spell name using GetSpellInfo(spellID) [Seems out of date as of 3.3]
[[Category:API Spell Functions|GetSpellCooldown]]
*GetSpellCooldown() accepts SpellIDs [Noticed in 3.3.2 - but worked with it as of 3.3]

Latest revision as of 04:46, 15 August 2023

WoW API < GetSpellCooldown

Retrieves the cooldown data of the spell specified.

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

Arguments

spellName
String - name of the spell to retrieve cooldown data for.
spellID
Number - ID of the spell in the database
slotID
Number - Valid values are 1 through total number of spells in the spellbook on all pages and all tabs, ignoring empty slots.
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.

Example

local name = GetSpellInfo(28370);
local start, duration, enabled = GetSpellCooldown(name);
etc...

Example of using SpellIDs to retrieve cooldown info


Example

local start, duration, enabled = GetSpellCooldown(48505);

Result

returns 0, 0, 1 if the spell 'Starfall' is not on Cooldown otherwise it returns GetTime(), 90, 1


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.
  • GetSpellCooldown() does not directly accept SpellIDs. You must first retrieve the spell name using GetSpellInfo(spellID) [Seems out of date as of 3.3]
  • GetSpellCooldown() accepts SpellIDs [Noticed in 3.3.2 - but worked with it as of 3.3]