Difference between revisions of "Cast - Spell"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Jbezorg
m (→‎Notes: Daul -> Dual)
 
(5 intermediate revisions by 4 users not shown)
Line 10: Line 10:
Function Cast(ObjectReference akSource, ObjectReference akTarget = None) native
Function Cast(ObjectReference akSource, ObjectReference akTarget = None) native
</source>
</source>
 
== Examples ==
<source lang="papyrus">
mySpell.cast(myActivator, playerRef)
; myActivator has cast mySpell on the player!
</source>
== Parameters ==
== Parameters ==
*akSource: The [[ObjectReference Script|ObjectReference]] from which to cast the spell.  The source must be able to cast this spell (testings seem to show anything will work, regardless whether they have the spell or not).
*akSource: The [[ObjectReference Script|ObjectReference]] from which to cast the spell.  The source must be able to cast this spell (testings seem to show anything will work, regardless whether they have the spell or not).
Line 20: Line 24:


== Notes ==
== Notes ==
*This function cannot be called if either akSource or akTarget is in unloaded cell.
*This function casts the spell instantaneously.  This is mainly desirable only for non-actors, because it will not animate an actor.  For instance, the spell will be cast even if the actor's hands are not readied.
*This function casts the spell instantaneously.  This is mainly desirable only for non-actors, because it will not animate an actor.  For instance, the spell will be cast even if the actor's hands are not readied.
*If you wish to make an actor cast a spell using all the normal spellcasting behaviors, please instead use an AI package that includes the [[Procedure_UseMagic|UseMagic procedure]].
*If you wish to make an actor cast a spell using all the normal spellcasting behaviors, please instead use an AI package that includes the [[Procedure_UseMagic|UseMagic procedure]].
*Actor races can be set to cast magic only in the direction that the actor is facing; if the source is an actor with this racial setting, the target will be ignored.
*Actor races can be set to cast magic only in the direction that the actor is facing; if the source is an actor with this racial setting, the target will be ignored. (Exception: if the spell is a Target Actor spell, it will hit regardless of distance or direction)
*It seems that using this function on an actor that doesn't have the spell will work. To add, it will also work on Objects, such as a rock.
*Using this function on an actor that doesn't have the spell will work. To add, it will also work on Objects, such as a rock.
*Using this function will invalidate (cause it to return 0/false when it should return 1/true) any ongoing '''isDualCasting''' condition checks on akSource.   
*Using this function will invalidate (cause it to return 0/false when it should return 1/true) any ongoing '''isDualCasting''' condition checks on akSource.   
**'''isDualCasting''' will continue to return false after the '''Cast''' function is called until akSource stops dual casting.
**'''isDualCasting''' will continue to return false after the '''Cast''' function is called until akSource stops dual casting.
**There's now a fix for the above issue that is found here: [https://www.nexusmods.com/skyrimspecialedition/mods/92454 Po3's Dual Casting Fix]
== Bug ==
In rare circumstances, this may start working sporadically or quit altogether. Don't use this for functionality that is expected to trigger very frequently throughout a character's lifetime.


== See Also ==
== See Also ==

Latest revision as of 11:51, 7 January 2024

Member of: Spell Script

Casts this spell from the specified object reference, optionally toward a target object reference.

Syntax[edit | edit source]

Function Cast(ObjectReference akSource, ObjectReference akTarget = None) native

Examples[edit | edit source]

mySpell.cast(myActivator, playerRef)
; myActivator has cast mySpell on the player!

Parameters[edit | edit source]

  • akSource: The ObjectReference from which to cast the spell. The source must be able to cast this spell (testings seem to show anything will work, regardless whether they have the spell or not).
  • akTarget: An optional ObjectReference at which to aim the spell. If None is passed and the spell needs a direction, it will be aimed in a default direction.
    • Default: None

Return Value[edit | edit source]

None.

Notes[edit | edit source]

  • This function cannot be called if either akSource or akTarget is in unloaded cell.
  • This function casts the spell instantaneously. This is mainly desirable only for non-actors, because it will not animate an actor. For instance, the spell will be cast even if the actor's hands are not readied.
  • If you wish to make an actor cast a spell using all the normal spellcasting behaviors, please instead use an AI package that includes the UseMagic procedure.
  • Actor races can be set to cast magic only in the direction that the actor is facing; if the source is an actor with this racial setting, the target will be ignored. (Exception: if the spell is a Target Actor spell, it will hit regardless of distance or direction)
  • Using this function on an actor that doesn't have the spell will work. To add, it will also work on Objects, such as a rock.
  • Using this function will invalidate (cause it to return 0/false when it should return 1/true) any ongoing isDualCasting condition checks on akSource.
    • isDualCasting will continue to return false after the Cast function is called until akSource stops dual casting.
    • There's now a fix for the above issue that is found here: Po3's Dual Casting Fix

Bug[edit | edit source]

In rare circumstances, this may start working sporadically or quit altogether. Don't use this for functionality that is expected to trigger very frequently throughout a character's lifetime.

See Also[edit | edit source]