WoW:API CastSpellByName: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
mNo edit summary
m (Move page script moved page API CastSpellByName to API CastSpellByName without leaving a redirect)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<center>'''CastSpellByName''' ''-Documentation by Sliver-''</center>
{{wowapi}}
----
{{protectedapi|2.0.1|For alternatives, try [[API_SecureTemplates|Secure Template]] or the new [[Conditional slash commands#/cast|/cast]].}}
;''Arguments''


:( name{, onSelf})
CastSpellByName(spellName{, onSelf});
:;name : String - Spell Name(as seen when mouse-over).
:;onSelf : Value - Any value or nil.


----
==Arguments==
;''Returns''
:;name : String - Name of the spell to cast. Rank is optional, if omitted, highest possible is picked automatically.
:;nil
:;onSelf : Boolean - Should the spell be cast on the player (vs target)? If no target exists and the onSelf evaluates to false, cursor is switched to casting mode.
----
;''Example''
:( syntax )
:;CastSpellByName("spellname(Rank X)")
:;CastSpellByName("spellname")
:;CastSpellByName("spellname", onSelf )
 


CastSpellByName('Life Tap(Rank 2)')
==Example==
----
;''Result''


: Casts Life Tap (This example is warlock specific). When the (Rank X) string is omitted, the ''highest rank of the spell which the user has in his spellbook'' is cast. ''This is not true for Stone creation spells (i.e. "Create Firestone"), because they do not use "ranks".''
CastSpellByName("Flash Heal(Rank 2)"); -- Cast Flash Heal (Rank 2) on target.
----
CastSpellByName("Flash Heal"); -- Cast Flash Heal (Highest rank) on target.
;''Description''
CastSpellByName("Flash Heal",1); -- Cast Flash Heal (Highest rank) on self.


: Casts a spell by the spells given name.
==Notes==
 
To cast spells that contains parentheses in the spell name, such as "Create Healthstone (Major)" and "Faerie Fire (Feral)", it's necessary to either specify rank or add () to the end of the spell name, like:  
----
CastSpellByName("Faerie Fire (Feral)()");
;''Notes:''
You might encounter difficulties when using this on a localized version of WoW.
: To cast spells that contains parentheses in the spell name, such as "Create Healthstone (Major)" and "Faerie Fire (Feral)", it's necessary to either specify rank or add () to the end of the spell name, like: CastSpellByName("Faerie Fire (Feral)()").
* See the [[HOWTO:_Localize_an_AddOn#Unicode|Unicode part]] of the Localization HOWTO for more details about editing a source file containing localized strings.
: You might encounter difficulties when using this on a localized version of WoW.
* This problem does only appear when working with Lua source files. When you're using macros, inside the WoW client, it should work in unicode directly.
: See the [[HOWTO:_Localize_an_AddOn#Unicode|Unicode part]] of the Localization HOWTO for more details about editing a source file containing localized strings.
* You ''can'' still use this function outside of secure code to open trade skill windows and to summon non-combat pets and mounts.
 
: This problem does only appear when working with Lua source files. When you're using macros, inside the WoW client, it should work in unicode directly.
 
:In patch 1.10, this function operates when called From Button presses, Slash Commands and '''some''' Events. (PLAYER_TARGET_CHANGED is the only one i have found, but there may be more, i assume Events that are called In reaction to Player's Actions are those that work).
 
:This function can not be called by an AddOn itself. You need a hardwareevent (mouse or keyboard) to activate the function.
 
----
 
{{Template:WoW API}}

Latest revision as of 04:45, 15 August 2023

WoW API < CastSpellByName

CastSpellByName(spellName{, onSelf});

Arguments

name
String - Name of the spell to cast. Rank is optional, if omitted, highest possible is picked automatically.
onSelf
Boolean - Should the spell be cast on the player (vs target)? If no target exists and the onSelf evaluates to false, cursor is switched to casting mode.

Example

CastSpellByName("Flash Heal(Rank 2)"); -- Cast Flash Heal (Rank 2) on target.
CastSpellByName("Flash Heal"); -- Cast Flash Heal (Highest rank) on target.
CastSpellByName("Flash Heal",1); -- Cast Flash Heal (Highest rank) on self.

Notes

To cast spells that contains parentheses in the spell name, such as "Create Healthstone (Major)" and "Faerie Fire (Feral)", it's necessary to either specify rank or add () to the end of the spell name, like:

CastSpellByName("Faerie Fire (Feral)()");

You might encounter difficulties when using this on a localized version of WoW.

  • See the Unicode part of the Localization HOWTO for more details about editing a source file containing localized strings.
  • This problem does only appear when working with Lua source files. When you're using macros, inside the WoW client, it should work in unicode directly.
  • You can still use this function outside of secure code to open trade skill windows and to summon non-combat pets and mounts.