← PRC8
Heroes Of Profound Enlightenment :: Manual :: Module Building :: Respawning Traps
Note: This system was written and implemented before NWN 1.67 added the function for creating traps though scripting. If you wish to, this can be incorporated into normal traps by setting the trigger script to "prgt_trap_fire" and set a trap struct (defined in prgt_inc_trap) as a local named "TrapSettings".
PRC v3.0 includes a novel spawning ground trap system. This system has several unique attributes:
- Does not require any toolset placed objects.
- Vast selection of trap types.
- Can have a random trap type.
- Ability to create new trap types purely from scripting.
- Easily award XP (or other rewards) from the trap, either from the PRC XP system or via custom scripting.
- Spell-casting traps any arbitrary caster level.
- Can be hooked up to NPC events so they can lay traps too.
- Can be set to automatically respawn after a period of time.
The way the system works internally is fairly complex, but the outline is this:
- Two invisible auras are created, one as a trigger, and one as a detection area.
- This auras have certain attributes set on them when created such as detection and disarm DCs.
- Every 6 seconds a creature is in the detection trigger in detect mode, there is a chance to reveal the trap.
- When the trap is detected, a grid of invisible placeables are spawned inside the trigger aura.
- Each of these invisible placeables are trapped, this gives off a red glow to display where the trap is.
- If detected or not, the trap goes off when a creature enters the trigger aura. The exception to this is if the creature is moving to disarm, flag, or recover one of the trapped invisible placeables.
- If a creature is inside the trigger aura and not disarming, flagging, or recovering, the trap goes off.
- When the trap is triggered, there are several things that can happed.
- If there is a custom script assigned to the trap, it will be run.
- If there is a spell assigned to the trap, it will be cast.
- Otherwise, the trap will do its pre-set damage, VFX, etc.
- After a trap has triggered, again several things could happen.
- The trap could be destroyed entirely, for a one-shot trap.
- The trap may stay around untill disarmed.
- The trap may be destroyed for a time and respawn later.
Examples
The simplest way for a builder to implement respawning ground traps is to create a set of invisible object placeables that replace themselves with traps in-game. This can either be done with a range of pre-fixed difficulties or dynamically integrated into a spawn system.
Below is an example of a pre-set difficulty script that will spawn a random trap. This is in the PRC as prgt_spawneg. Simply place it in the OnHeartbeat event of an invisible non-static non-plot placeable. This trap will not repsawn and will be a one-shot trap
//An example OnHB script for an invisible placeable to spawn a ground trap
#include "prc_alterations"
#include "prgt_inc"
void main()
{
struct trap tTrap;
//this will use 5 as the CR for the trap
tTrap = CreateRandomTrap(5);
//add code in here to change things if you want to
//for example, to set the detect DC to be 25 use:
//tTrap.nDetectDC = 25;
CreateTrap(GetLocation(OBJECT_SELF), tTrap);
DestroyObject(OBJECT_SELF);
}
If you want to have a respawning trap, you need to set nRespawnSeconds to be greater than zero, as shown in the script below. Also, this script will recreate the random trap each time it respawns.
//An example OnHB script for an invisible placeable to spawn a ground trap
#include "prc_alterations"
#include "prgt_inc"
void main()
{
struct trap tTrap;
//this will use 5 as the CR for the trap
tTrap = CreateRandomTrap(5);
//add code in here to change things if you want to
//for example, to set the detect DC to be 25 use:
//tTrap.nDetectDC = 25;
tTrap.nRespawnSeconds = 600; //will respawn after 10 minutes
tTrap.nRespawnCR = 5; //will rerandomize the trap each time its respawned
CreateTrap(GetLocation(OBJECT_SELF), tTrap);
DestroyObject(OBJECT_SELF);
}
The full details of the variables in a trap are detailed in prgt_inc. The main upshot is that you can either have it cast a spell, complete with specified level, DC, and metamgic, or you can apply direct damage along with radius damage and almost any visual effect you can think of. All of the information on a trap is stored in the trap struct and can be accessed using the . operator (dot).