WoW:API IsUsableSpell: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (Added failure condition)
m (Move page script moved page API IsUsableSpell to API IsUsableSpell without leaving a redirect)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{wowapi}}
{{wowapi}}


usable, nomana = IsUsableSpell(SPELL);
Determines whether a spell can be used by the player character.


----
usable, nomana = IsUsableSpell("spellName" or spellID or spellIndex[, "bookType"]);
;''Arguments''


:;''SPELL'' : A spell name or SpellID
==Arguments==
;spellName : String: name of the spell to check.
;spellIndex : Number: index of a spell in the player's (or pet's) spellbook.
;spellID : Number: SpellID of a spell to check.
;bookType: String: does the spellIndex refer to the player's spellbook (BOOKTYPE_SPELL constant, default), or the pet's spellbook (BOOKTYPE_PET constant).


----
==Returns==
;''Returns''
;usable :Boolean : 1 (true) if the spell is usable, nil otherwise. A spell is not usable if any of the following conditions apply:
;usable
:* The player hasn't learned the spell
:;Boolean : 1 (true) if the spell is usable, nil otherwise.
:* The player lacks required mana or reagents.
;nomana
:* Reactive conditions haven't been met.
:;Boolean : 1 (true) if the spell can not be cast due to low mana, nil otherwise.
;nomana : Boolean : 1 (true) if the spell can not be cast due to low mana, nil otherwise.


----
==Example==
;''Example''
   usable, nomana = IsUsableSpell("Curse of Elements");
   usable, nomana = IsUsableSpell("Curse of Elements")
   if (not usable) then
   if (not usable) then
   if (not nomana) then
   if (not nomana) then
     message("The spell can not be cast");
     message("The spell cannot be cast");
   else
   else
     message("You do not have enough mana to cast the spell");
     message("You do not have enough mana to cast the spell");
Line 28: Line 30:
   end
   end


----
  usable, nomana = IsUsableSpell(20, BOOKTYPE_SPELL);  
;''Conditions for Failure''
  print(GetSpellName(20, BOOKTYPE_SPELL) .. " is " .. (usable and "" or "not ") .. " usable.");
* Spell is not in spellbook
* Not enough mana to cast spell
* Reagents required for spell do not exist in bags
* Reactive skill conditions have not been met

Latest revision as of 04:46, 15 August 2023

WoW API < IsUsableSpell

Determines whether a spell can be used by the player character.

usable, nomana = IsUsableSpell("spellName" or spellID or spellIndex[, "bookType"]);

Arguments[edit]

spellName
String: name of the spell to check.
spellIndex
Number: index of a spell in the player's (or pet's) spellbook.
spellID
Number: SpellID of a spell to check.
bookType
String: does the spellIndex refer to the player's spellbook (BOOKTYPE_SPELL constant, default), or the pet's spellbook (BOOKTYPE_PET constant).

Returns[edit]

usable
Boolean : 1 (true) if the spell is usable, nil otherwise. A spell is not usable if any of the following conditions apply:
  • The player hasn't learned the spell
  • The player lacks required mana or reagents.
  • Reactive conditions haven't been met.
nomana
Boolean : 1 (true) if the spell can not be cast due to low mana, nil otherwise.

Example[edit]

 usable, nomana = IsUsableSpell("Curse of Elements");
 if (not usable) then
  if (not nomana) then
    message("The spell cannot be cast");
  else
    message("You do not have enough mana to cast the spell");
  end
 else
    message("The spell may be cast");
 end
 usable, nomana = IsUsableSpell(20, BOOKTYPE_SPELL); 
 print(GetSpellName(20, BOOKTYPE_SPELL) .. " is " .. (usable and "" or "not ") .. " usable.");