Page 1 of 1

open a door with a lever (keyed and unkeyed)

Posted: Thu Mar 18, 2004 3:22 am
by Psyco
This is something we were discussing last night in IRC.

It allows a door to only be opened when a placeable is used. this can be used with or without a key, and best of all it is 100% generic.

Code: Select all

//::///////////////////////////////////////////////
//:: Name     remote_door_open
//:: FileName remote_door_open.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////

/*
When a PC uses the placeable, it opens a door with
tag: DOOR_<tag of placeable>
*/

//:://////////////////////////////////////////////
//:: Created By: Psyco
//:: Created On: March 18, 2004
//:://////////////////////////////////////////////

// It gets the keytag from the keytag field of the target door.
// The keytag on the door must have the form NOKEY_<keytag>
// If there is a blank keytag on the door, no key will be required.

#include "nw_i0_plot"

void main()
{
    string sTempTag = GetTag(OBJECT_SELF);
    object oDoor = GetObjectByTag("DOOR_"+ sTempTag);

    if (GetIsObjectValid(oDoor))
    {
        string sTempKeyTag = GetLockKeyTag(oDoor);
        int nLength = GetStringLength(sTempKeyTag);
        int nKeyTagLength = nLength - GetStringLength("NOKEY_");

        if (nKeyTagLength > 0)
        {
            string sKeyTag = GetStringRight(sTempKeyTag, nKeyTagLength);
            object oPC=GetLastUsedBy();

            if (HasItem(oPC, sKeyTag))
            {
                ActionOpenDoor(oDoor);
            }
        }
        else
        {
            ActionOpenDoor(oDoor);
        }
    }
}

Posted: Thu Mar 18, 2004 9:51 am
by Mistcaller
Well done Psyco! :)


-Mistcaller,
fan of generic scripts

Posted: Thu Mar 18, 2004 11:00 am
by Psyco
Considering that is the first time i have ever written a NWN script, i think i did fairly well :-)