Spell Script

From NWN Lexicon
Jump to navigationJump to 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.

Only creatures and placeables can call these scripts usually, doors oddly cannot, nor can triggers - use a placeable to instead fire traps and the like with ActionCastSpellAtObject and ActionCastSpellAtLocation.


Trigger

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

Function(s)

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).
  • GetSpellFeatId - returns the feat used to cast this ability, if any.
  • 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.
  • GetLastSpellLevel - returns the level of the spell cast
  • GetSpellCastSpontaneously - returns if the spell was cast spontaneously or not (eg Cure Light Wounds on a cleric can be cast spontaneously).

For spells involving saves or spell resistance:

  • MySavingThrow which combines WillSave, FortitudeSave and ReflexSave functions with appropriate visual effects. See remarks about how immunities are dealt with. Additionally note spell scripts may automatically apply save vs. Spells / spellcraft bonuses / Arcane Defence depending on the UserType of the spell.
  • MyResistSpell which wraps the function ResistSpell with appropriate visual effects.

For Area of Effect spells:

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

You can also alter some properties that were previously coded to be automatically applied - these can be used to mimic a spell being applied outside a spell script as well:

Remarks

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

Many of the functions have been fixed in NWN:EE, see Patches or individual functions for details. Prior to these fixes some issues with caster levels and save DCs were present.


See Also

functions:

GetSpellId GetLastSpellCaster