Spell Script

From NWN Lexicon
Jump to: navigation, search

Spell Script

A spell script is a script called when a successful spell is cast. It uses the ImpactScript column of spells.2da. This can fire off as a true spell, monster ability, item spell or called from a feat being used which is tied to a spell ID line.

Think of "spells" in this context as any scripted ability. Spell scripts are used for Magic Missile, Fireball, Turn Undead, Wild Shape, Barbarian Rage, Dragon Breath, Aura of Fear and more.


A spell being cast or ability being used referenced in spells.2da under the ImpactScript column.


Generally a set of effects are created and fired from the script, an area of effect is placed, or something is summoned. See the Effect Functions for these.

The script is run on the caster (not the target), thus OBJECT_SELF is always the user of the spell or feat.

Spells can do a lot of different things but many uses these functions often:

  • GetSpellId - lets you know which spells.2da line called it (to differentiate the same script being called from multiple lines).
  • GetCasterLevel - during the spell script the game will have set the caster level on the caster for the last instance they called. Only works for true spells and true spells cast as monster abilities (which have a caster level set in the toolset). This caster level is hardcoded back into effects generated and applied in the spell script for determining dispel effects.
  • GetMetaMagicFeat - lets you know if the main modifier metamagic feats are in use; METAMAGIC_EXTEND, METAMAGIC_EMPOWER and METAMAGIC_MAXIMIZE.
  • GetLastSpellCastClass - lets you know what class called this spell. For instance Bioware used this to determine the casters ability modifier for Black Blade of Disaster.
  • GetSpellCastItem - if a valid item cast this spell it can be checked with this. For instance; spell scroll? do something special (further Use Magical Device checks for instance).
  • GetSpellSaveDC - returns the game defined spell save DC, or 10 if a non-spell was "cast".
  • GetSpellTargetLocation and GetSpellTargetObject - If the target object is valid, you can use this as a location using GetLocation. Many AOE spells can be cast on a target which homes in on them.

For spells involving saves or spell resistance:

For Area of Effect spells:

To fire that a spell or spell-like ability is targeting a creature, use:


See existing Bioware made spell scripts for inspiration. Example names:

  • Spells: nw_s0_xxx, x0_s0_xxx, x2_s0_xxx
  • Monster and spell-like abilities: nw_s1_xxx, x0_s1_xxx, x1_s1_xxx, x2_s1_xxx
  • Feats: nw_s2_xxx, x0_s2_xxx, x1_s2_xxx, x2_s2_xxx

Known Bugs

There are probably still an array of bugs with many spells due to built in functions not quite covering all edge cases.

Some have been fixed in NWN:EE, see Patches for details.

See Also


GetSpellId GetLastSpellCaster Event