Trap Script
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:
- GetEnteringObject - The object triggering the trap
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:
- GetTrapBaseType - Gets the index into traps.2da of what trap type this is
- GetTrapCreator - If a player-made trap it'll be the player (if they're still connected to the server)
- GetTrapOneShot - If not one shot this script may fire again (or maybe you could disable it on a conditional with SetTrapActive).
- And any other Traps Functions that are relevant.
For traps involving saves:
- MySavingThrow which combines WillSave, FortitudeSave and ReflexSave functions with appropriate visual effects.
For Area of Effect traps:
- GetFirstObjectInShape and GetNextObjectInShape for area-of-effect spells.
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:
- SetEffectCasterLevel - Sets the caster level (usually would be GetCasterLevel)
- SetEffectCreator - Sets the creator (usually would be OBJECT_SELF)
- SetEffectSpellId - Sets the Spell Id (usually would be GetSpellId)
Remarks
See remarks about using DelayCommand in trap scripts.
Bioware traps are prefixed nw_t1 or x2_t1.
See Also
| functions: |