Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Detecting an instant cast spell
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Using UNIT_SPELLCAST_SUCCEEDED to track instant casts == The core event here is UNIT_SPELLCAST_SUCCEEDED (hereafter _SUCCEEDED). This event fires whenever a spellcast is completed server end, regardless of whether it is instant or cast. Therefore whenever an instant cast has been used successfully, this event will fire. However, there are times when _SUCCEEDED will fire but the spell is not instant. The events UNIT_SPELLCAST_START, UNIT_SPELLCAST_FAILED, and UNIT_SPELLCAST_INTERRUPTED (hereafter _START, _FAILED, and _INTERRUPTED) allow us to track precisely which spellcasts are instant and which are not. The key to this code is the relation between these events. Here are the relevant details: * All spells eventually trigger _SUCCEEDED if the cast completes, or _FAILED if it doesn't. * Only spells with cast times fire _START. * Every spell that starts must finish before another can begin; in other words, for every _START, we must hear '''finishing event''' (_SUCCEEDED, _FAILED or _INTERRUPTED) before we can hear another _START. Thus, to detect instant spells, note when someone starts] casting a spell, then watch for a corresponding finishing event. Any finishing event that occurs without an unfinished start event preceding it describes an instant cast spell. === Example code === -- you should replace this with a better one local print = function (msg) DEFAULT_CHAT_FRAME:AddMessage(msg) end is_casting = false SampleTrackerFunctions = { } SampleTracker = CreateFrame("Frame", nil, UIParent) SampleTracker:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") SampleTracker:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") SampleTracker:RegisterEvent("UNIT_SPELLCAST_FAILED") SampleTracker:RegisterEvent("UNIT_SPELLCAST_START") SampleTracker:SetScript("OnEvent", function (_,e) SampleTrackerFunctions[e]() end) ---- function SampleTrackerFunctions.UNIT_SPELLCAST_SUCCEEDED() if not is_casting then print("An instant spell, oh my!") end is_casting = false end ---- function SampleTrackerFunctions.UNIT_SPELLCAST_START() is_casting = true end ---- function SampleTrackerFunctions.UNIT_SPELLCAST_FAILED() is_casting = false end === Channeled Spells === Note that channeled spells are actually considered two casts by the event engine: first, the '''preceding component''' spellcast, then '''channeling component''' itself. For clarity, consider Mind Control. The preceding component is the 3-second cast before the spell takes effect, and the channeling component is the actual mind control portion of the spell. Note that '''every channeled spell has a preceding component, though many of them are instant.''' In other words, don't be surprised when the sample code (or any code using this strategy) picks up abilities like Mind Vision or Drain Life as instant. Technically, there is an instant cast spell associated with such abilities. [[Category: HOWTOs|Detect Instant Cast Spells]]
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)