open a door with a lever (keyed and unkeyed)

Moderator: Event DM

Post Reply
User avatar
Psyco
Elder Sage
Posts: 3288
Joined: Mon Jun 30, 2003 10:05 pm
Location: New Zealand (NZDT, +12 GMT)
Contact:

open a door with a lever (keyed and unkeyed)

Post by Psyco » Thu Mar 18, 2004 3:22 am

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);
        }
    }
}
User avatar
Mistcaller
Team Member; Retired with Honors
Posts: 5477
Joined: Sun Feb 09, 2003 3:42 pm
Location: Athens, Greece (GMT +2)

Post by Mistcaller » Thu Mar 18, 2004 9:51 am

Well done Psyco! :)


-Mistcaller,
fan of generic scripts
User avatar
Psyco
Elder Sage
Posts: 3288
Joined: Mon Jun 30, 2003 10:05 pm
Location: New Zealand (NZDT, +12 GMT)
Contact:

Post by Psyco » Thu Mar 18, 2004 11:00 am

Considering that is the first time i have ever written a NWN script, i think i did fairly well :-)
Post Reply