Trap Script

From NWN Lexicon
Jump to navigationJump to search

A trap script is a script called when a trap is triggered (ie activated). It uses the TrapScript column of traps.2da. It won't fire if the builder-specified OnTrapTriggered event is set.

Since an object will be trapped, the caller of the script will be a trigger, placeable or door.

Trigger

A trap is triggered (ie activated). It uses the TrapScript column of traps.2da to determine the script to run.

Note on DelayCommand

NOTE: Trap scripts are tricky since trigger traps are removed from the game as objects just after this script is fired (unless the trap is repeatable) it means DelayCommand calls from the trap script will fail if the object has gone. This makes bugs with EffectDamage (recursively calling other scripts) somewhat more difficult to deal with (see EffectDamage page for issues). To safely do things with the traps, call all the relevant saving throw and immunity checks in the main trap script but anything exciting like damage or delayed VFX you could make a separate placeable, the area or the module generate via. AssignCommand or ExecuteScript and DelayCommand.

This is notably why the electrical trap is so laggy - it has to do all the damage and VFX instantly in the same frame.

If the trap just generates a non-damage effect such as cloud of noxious gas or some ability score decrease this can just be applied instantly.


Function(s)

The functions useful for trap scripts are generally similar to Spell Scripts. This is because they usually involve saving throws and applying effects.

These are basic functions you'll need:

Generally these can be used to help customise the traps difficulty or if you use a generic trap script work out which trap it is firing:

For traps involving saves:

For Area of Effect traps:

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 remarks about using DelayCommand in trap scripts.

Bioware traps are prefixed nw_t1 or x2_t1.


See Also

functions:

OnTrapTriggered