Trap system

From Dragon Age Toolset Wiki
Jump to: navigation, search

The trap system combines various resources and scripting to produce, what appears to the Player as, individual traps that can be placed, armed, disarmed, detected and triggered.

Definitions

  • Trap - A placeable object with the Trap Type setting (see below) set to a value != 0.
  • Trap Type - A trap's type defines the effect(s) and/or scripted actions the object will apply to its surrounding when triggered. Trap Type is defined in the integer variable 'PLC_TRAP_TYPE' on the placeable's local variables.
  • Armed - A trap placeable that is flagged as 'inactive' is considered 'not armed' and will not react to creatures entering or leaving its trigger volume. This is to allow the user to leave the area of effect of the trap after setting it without being damaged. Arming a placeable automatically sets it to 'active'.
  • Detected - Traps that have the integer variable 'PLC_TRAP_DETECTED' set to 0 (default) when they are armed are considered 'not detected' and are automatically set to be invisible to the player and his party. Traps dynamically created by the player are always set to 'detected' after they are created.
  • Trap Owner - Traps dynamically spawned by a creature in the game world have the object variable 'PLC_TRAP_OWNER' on them pointing to the creature that created them. Any hostility checks performed or effects applied by the trap will be attributed to owner of the trap, ensuring that proper experience rewards are given to the trap creator for objects killed by a trap.
  • Rearming Delay - Traps that have the float variable 'PLC_TRAP_REARM' set to a positive value will not be automatically destroyed when triggered but instead deactivate themselves and rearm after the number of seconds defined in the variable.
  • Signal Target - Traps can optionally define a signal target object by defining the string variable 'PLC_SIGNAL_TAG' on the template. If set to a valid object tag, the trap will send EVENT_TYPE_TRAP_TRIGGER_ENTER to this object to allow designers to script custom actions. This is mostly interesting for pre placed designer traps

Trap Placeables

There are two possible ways for Trap objects to enter the world:

  • Being pre-placed by a designer in the toolset.
  • Being dynamically spawned by a player controlled creature that has the Traps Skill.

When a pre-placed object is initially loaded, it will receive a EVENT_TYPE_SPAWN event, during which the placeable's event script, by default placeable_core, will automatically 'arm' the trap if the object is 'active' at that time. If the object is not active, it needs to be activated and armed manually by the designer. This can be done by calling the Trap_ArmTrap function.

Dynamically spawned traps are created when a player controlled character uses one of the trap kit item abilities from their quickbar, causing the character to play a kneeling 'conjure' animation. The object will spawn in as initially inactive at the players location and will arm itself after a short grace period to allow the player to exit the danger area around the trap. The player will also automatically be set as the trap's owner.

Once a trap placeable is armed, it will automatically spawn an EFFECT_TYPE_AOE onto itself that provides the trigger mechanism for the trap. The type of the area of effect object spawned is defined for each trap type in traps.xls, pointing to an entry in AOE.xls defining the dimensions of the trigger volume. Afterwards, if a Signal Target was defined on the placeable, the target object will receive EVENT_TYPE_TRAP_TRIGGER_ARMED.

Logic Tree

Pre-placed:

object spawns
    |
    V
    is its trap type set?  --No--> do nothing
        |
       Yes
        |
        V
        is it active?   --No--> do nothing
            |
           Yes
            |
            V
            object arms itself
            object spawns AoE trigger on itself

Dynamic:

Trap Item Ability Use
    |
    V
    Placeable object is created (inactive)
        |
        V
        object is armed/activated after delay
        object spawns AoE trigger on itself

Triggering a Trap

Any creature object entering the area of effect object trigger around an armed trap object will cause an EVENT_TYPE_ENTER to fire into placeable's event script, which will call the Trap_HandleEventEnter function.

Here, a number of conditions are checked to validate if the entering object triggers the trap:

  • If the trap object is currently set inactive, the function will exit immediately without applying any effects.
  • If the trap has a valid owner associated with it, a hostility check between the owner and the entering creature is performed. If they are found non hostile. the function exits immediately without applying any effects.
  • If the trap does not have an owner set, it is considered an environmental trap and only hostile to the player's group. If the entering creature is not a member of the player's group, the function exists immediately without applying any effects.

Logic Tree

object enters
   |
   V
   is Trap Armed?  --No--> do nothing.
      |
     Yes
      |
      V
      does it have an Owner?  --No--> IsPartyMember(object)?  --No--> do nothing.
         |                               |
         |                              Yes
        Yes                              |
         |                               V
         |                               Trigger Trap!
         V
         is object hostile to owner?   --No--> do nothing.
            |
           Yes
            |
            V
            Trigger Trap!

If all conditions are satisfied and the entering object has been found valid for triggering the trap, the Trap_Triggered function causes the effects defined in traps.xls to be applied to the entering object. In addition, if a Signal Target was defined on the trap placeable, EVENT_TYPE_TRAP_TRIGGER_ENTER will be fired to the closest object matching the 'PLC_SIGNAL_TAG' string variable on the placeable. This allows for the triggering of designer defined events (such as running environmental traps).

After running, the trap disables itself, preventing any further triggering from entering objects. Traps that have a 'Rearming Delay' specified will automatically reactivate after the specified amount of time - all other traps will self destruct after 1000ms (1 sec).

Trap Detection

The player and members of his party all run a heartbeat event which calls the Trap_RunDetectionPulse function at regular intervals.

This function scans the area around any character with the ABILITY_TALENT_HIDDEN_ROGUE ability, to a range based on the character's skill level, examining the 10 closest placeable objects for undetected, active traps in the character's line of sight.

When an undetected trap is found, the Trap_TryDetectTrap function performs a skill check to determine whether or not the player detects it. This check is based partially on the player's disable device rank.

On successful detection, the object is flagged as detected and thereby made visible to the player and his party. Another visual effect is also spawned to provide an additional visual cue to the player about the detection.

Trap Disarming

Disarming a trap will be handled through the placeable objects interaction menu. [Undocumented]

Creating a trap trigger placeable

A trap trigger placeable is a placeable object that acts as the trigger for a trap, which can be either VFX based (e.g. explosion) or based on a complex trap placeable.

Setting up the traps

Every placeable object in the game can act as a trap trigger, but only some of them actually make sense.

In order to set a placeable object up as a trap trigger, the PLC_TRAP_TYPE integer variable in its local variables has to be set to a valid row index in traps.xls.

Additional variables can be used to tweak the behavior of an object, such as whether or not it signals its triggering event to another object (e.g. a complex trap placeable) and whether or not the trap will rearm itself after triggering once.

Variable summary:

Variable name Type Default Description
PLC_TRAP_AOE int A row ID in AOE.xls identifying the AOE trigger the trap should use
PLC_TRAP_DEACTIVATE int 0 1/0 to indicate whether trap should be set inactive once triggered.
PLC_TRAP_DETECTED int 0 Defines if the trap is visible or not when spawned.
PLC_TRAP_ITEM resource The item resource used to create this trap
PLC_TRAP_OWNER object 0 Set when a trap is spawned from scripting
PLC_TRAP_REARM_DELAY float 0 If this is set to anything other than 0, the trap will rearm after triggering in so many seconds.
PLC_TRAP_SIGNAL_HEIGHT float 1 The height projectiles are fired from projectile traps.
PLC_TRAP_SIGNAL_TAG string The tag of the object that will be notified of enter events.
PLC_TRAP_TEAM int 0 The team which will approach the trap when triggered
PLC_TRAP_TYPE int 0 A row ID in traps.xls indicating what type of trap this is. An object automatically becomes a trap trigger if this is not 0.

Setting detection and disarm difficulty

Detection and disarm properties are set on the placeable properties and pick from a 2da. The granularity for these difficulties ranges from 'Auto Success' to 'Nearly Impossible'. The default value is currently 'Auto Success'.

The actual difficulty for the player will depend on his skill level, attributes and a number of other factors.

See also