Author: Karthal
Author Website: n/a
Script Name: Trap Room
Description: I wanted a door to a room which would close and lock when the "boss" NPC engaged the PC in combat. Then the door would open again when the boss was killed. I played around with this for a while and here is my current best solution...
Instructions on Use: I made a custom OnDeath and OnCombatRoundEnd scripts for my boss NPC. At the end of the OnCombatRoundEnd script I added, where d_DOOR_TAG is the TAG for the door in question.

If the PC entered the room using a key it should be destroyed when they enter.  If you use a bindstone system it should be disabled in the room (the scripts below do *not* do that).  If the NPC respawns script 1 can be placed in his OnSpawn script to close and lock the door as well.

Script 1(OnCombatRoundEnd):

//If door is open, it is automatically closed and locked
    object oDoor = GetObjectByTag("d_DOOR_TAG");
    if ( GetIsOpen(oDoor) )
    {
        AssignCommand (oDoor, ActionCloseDoor (oDoor));
        SetLocked( oDoor, 1 );
        ActionSpeakString("You will not escape.");
    }

Script 2 (OnDeath):

//Door is opened
    object oDoor = GetObjectByTag("d_DOOR_TAG");
    AssignCommand (oDoor, ActionOpenDoor (oDoor));