Cast, SpellID, "TargetID"
Object_ID->Cast, "flame", Player
The Cast function makes the calling object cast the spell "SpellID" on the target "TargetID", and Target will suffer or benefit from the effects normally. The calling object does not need to have the spell in inventory: it will be cast regardless.
The spell's target must be specified, even if the spell is "on self". In this case you can specify the caster or the player as the target: if the spell is "on self" it won't make any difference. If you intend to place the target during the game, you will still need to place a reference in the editor. Cast will prefer a reference in the current cell if there is one available, so there's no need to move a reference from a storage cell: you can just place a new one.
Notes:
• It was believed that Cast would only work on the PC. At least with Tribunal (not sure about earlier versions) you can use cast to cast a spell from an activator, or any other object, on an Actor. However, make sure the object you are casting the spell from is not in the inventory of another actor/object, as that will result in a CTD.
• You cannot force an actor to cast a spell on an activator, but you can have them cast on themselves, other actors, or the player.
• You can get non actor objects to cast spells on themselves. Just use the player (or some other object) as a target, but cast an “On Self” spell.
• NPCs will not automatically lose magicka from a scripted cast. If you want the NPC to use up magicka in casting, this also needs to be scripted. -(Forum info/Kateri)
• If the spell's target is not in the current cell, the NPC will cast anyway (this doesn't cause any errors, but it does look a little odd - particularly targeted spells). They will also cast 'through' objects, other NPCs, walls… anything that's in the way.
• It is entirely possible for a targeted spell to miss its target. If this could cause problems, it's possible to use a touch spell instead: it will be cast like a targeted spell (from wherever the NPC is standing at the time) and will always succeed, but it will have the same visual effects as a normal touch spell. The downside of this is that if you want an NPC to cast a touch spell normally (from close up) you need to get them into position some other way.
Sample Script: The cast function can be used for traps, as in the following example attached to a Container. Note that there is a do once condition here, so that the effect is not cast continuously on the player.
Begin Trap_script
short done
if ( OnActivate == 1 )
if ( done == 1 ) ;do-once condition
Activate
return
else
Cast, "flame", Player ;damage to player
set done to 1
Activate
endif
endif
End trap_script
The next example script uses the AddSpell function:
begin Item_Cast
short OnPCEquip
short CurseAdded
float Timer
if ( CurseAdded )
set Timer to ( Timer + GetSecondsPassed )
if ( Timer >= 25 ) ; after 25 s remove the spell. 25 damage done.
set Timer to 0
Player->RemoveSpell "ItemFlame"
set CurseAdded to 0
endif
endif
if ( OnPCEquip );when item is equipped
if ( MenuMode )
return
elseif ( CurseAdded == 0 )
Player->AddSpell "ItemFlame" ; a spell of type curse!
;custom spell one point of fire damage / s
set Timer to 0
set CurseAdded to 1
elseif ( CurseAdded ) ; Add the spell only once
Player->RemoveSpell "ItemFlame"
set CurseAdded to 0
endif
end Item_Cast
(script by Patrin, edited)
The added spell is a custom-made curse spell doing one point per second flame damage. Note that there is again a do once condition implicit in this script. Failure to have a do once condition can crash the game! Also, it appears that creatures killed with curse spell effects on them cause all other creatures of that type to have the same curse on them. This can be avoided by using ‘RemoveSpell’ in an ‘OnDeath’ section of the script. (Forum Info / Argent)