Server Totals
M'Chek - (2)
Wilderness - (0)
Ferrell - (0)
Elysia - (0)
Le'Or - (0)
Deglos - (0)
Visimontium - (0)
Underdark - (0)
Mikona - (0)
Total players: 2
Gallery
  • Winter Ball 2015
    Album name: DM Events
    Uploaded by: Ronan
    Uploaded: Sat Jan 03, 2015 4:41 pm

Links Menu

Multiple Keys for a Locked Door.

Moderators: Nighthawk4, Dungeon Masters

Multiple Keys for a Locked Door.

PostAuthor: Jordicus » Tue Jun 24, 2003 4:21 pm

With the help of Silk and Myk D'vor, I was able to get this idea to work correctly.

If you mark a door as needing a specific key to unlock, you can normally only supply it 1 key tag to be used. I needed to have multiple tags, so finally got this work-around functional

If you have a Door tag as "Jord_Door_1", you need to place a generic trigger in front of it named "Jord_Door_1_trig". The door is marked as locked and also marked as needing a specific key to open. The trigger's tag must correctly match the Door's tag with the additional ending for the script to work properly.

On the trigger's OnEnter event add this script:

Code: Select all
int HasItem(object oPlayer, string sItemTag)
{
    int bReturnValue = FALSE;
    object oItem = GetItemPossessedBy(oPlayer, sItemTag);
    if (GetIsObjectValid(oItem)==TRUE){
        bReturnValue = TRUE;
    }
    return bReturnValue;
}

void main()
{
    object oPC = GetEnteringObject();
    string sTrig = GetTag(OBJECT_SELF);
    int iTrig = GetStringLength(sTrig) - 5;
    string sDoor = GetStringLeft(sTrig, iTrig);
    object oDoor = GetObjectByTag(sDoor);

    string sItem1 = "XYZ1";  // tag of first key
    string sItem2 = "XYZ2";  // tag of second key
    string sItem3 = "XYZ3";  // tag of third key
    string sItem4 = "XYZ4";  // tag of fourth key
    string sItem5 = "XYZ5";  // tag of fifth key

    if (HasItem(oPC, sItem1)|HasItem(oPC, sItem2)|HasItem(oPC, sItem3)|HasItem(oPC, sItem4)|HasItem(oPC, sItem5))
    {
        ActionDoCommand(SetLocked(oDoor, FALSE));
        ActionOpenDoor(oDoor);
        DelayCommand(6.0f, ActionCloseDoor(oDoor));
        DelayCommand(6.0f, SetLocked(oDoor, TRUE));
        SendMessageToPC(oPC, "You may pass");
    }else
    {
        SendMessageToPC(oPC, "This area is restricted");
    }
}


Obviously you can add or remove the key tags if you need less keys or more keys.

FYI, in case you were wondering, we found that you cannot apply this to the actual door, because the OnFailedToOpen() event of a door, does not generate either a valid GetLastUsedBy() or GetLastOpenedBy() value. Either of those would have been a much simpler solution.

If anyone sees something that could be optimized more, please let me know. Otherwise, please feel free to use.
User avatar
Jordicus
Team Member; Retired with Honors
 
Posts: 8048
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)

PostAuthor: Aloro » Tue Jun 24, 2003 4:33 pm

Use GetClickingObject() in the door's OnFailToOpen to retrieve the PC attempting to open the door. This is the easiest way I have found to have multiple keys for one door.

- Aloro
User avatar
Aloro
Team Member; Retired with Honors
 
Posts: 12810
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End

PostAuthor: Jordicus » Tue Jun 24, 2003 4:37 pm

GetClicking... ? darn how did I miss that? :P
User avatar
Jordicus
Team Member; Retired with Honors
 
Posts: 8048
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)

PostAuthor: Aloro » Tue Jun 24, 2003 4:38 pm

:)
User avatar
Aloro
Team Member; Retired with Honors
 
Posts: 12810
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End

PostAuthor: Jordicus » Tue Jun 24, 2003 4:42 pm

that would simplify it to this?

Code: Select all
int HasItem(object oPlayer, string sItemTag)
{
    int bReturnValue = FALSE;
    object oItem = GetItemPossessedBy(oPlayer, sItemTag);
    if (GetIsObjectValid(oItem)==TRUE){
        bReturnValue = TRUE;
    }
    return bReturnValue;
}

void main()
{
    object oPC = GetClickingObject();
    object oDoor = OBJECT_SELF;

    string sItem1 = "XYZ1";  // tag of first key
    string sItem2 = "XYZ2";  // tag of second key
    string sItem3 = "XYZ3";  // tag of third key
    string sItem4 = "XYZ4";  // tag of fourth key
    string sItem5 = "XYZ5";  // tag of fifth key

    if (HasItem(oPC, sItem1)|HasItem(oPC, sItem2)|HasItem(oPC, sItem3)|HasItem(oPC, sItem4)|HasItem(oPC, sItem5))
    {
        ActionDoCommand(SetLocked(oDoor, FALSE));
        ActionOpenDoor(oDoor);
        DelayCommand(6.0f, ActionCloseDoor(oDoor));
        DelayCommand(6.0f, SetLocked(oDoor, TRUE));
        SendMessageToPC(oPC, "You may pass");
    }else
    {
        SendMessageToPC(oPC, "This area is restricted");
    }
}


darn... now I have to wait until I get home to adjust it... even though the automatic doors is sort-of cool..
User avatar
Jordicus
Team Member; Retired with Honors
 
Posts: 8048
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)

PostAuthor: Aloro » Tue Jun 24, 2003 4:50 pm

Question: do you ever want the door to be closed and unlocked? Or do you want the door locked every time it is closed? My bias is to put the "autolock" script in the OnClose handler for every door with a lock. That would also shave a few lines off that code. :)

Everything looks good otherwise.

- Aloro
User avatar
Aloro
Team Member; Retired with Honors
 
Posts: 12810
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End

PostAuthor: Jordicus » Tue Jun 24, 2003 4:52 pm

for this particular instance, the door should always be locked when closed..
User avatar
Jordicus
Team Member; Retired with Honors
 
Posts: 8048
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)

PostAuthor: Aloro » Tue Jun 24, 2003 4:53 pm

In that case I'd put "autoclose" in the OnOpen and "autolock" in the OnClose handlers, respectively. This way the door will always close and lock itself, or it can be manually closed and will automatically lock.

- Aloro
User avatar
Aloro
Team Member; Retired with Honors
 
Posts: 12810
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End

PostAuthor: Jordicus » Tue Jun 24, 2003 4:55 pm

great... now, I just have to wait 5 hours before I get home and make the changes... :?
User avatar
Jordicus
Team Member; Retired with Honors
 
Posts: 8048
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)


Return to NWN Scripting

Who is online

Registered users: Sharrow