Author Sticky: Post Working Scripts Here
zandramus Posted: Tuesday, 23 July 12:30AM
SmartDoor

smart door.nss
return.nss
oexit_smart door.nss

By Zandramus



SmartDoor system is complete , this works for multiple doors leading to one room. it will lock the entry of a different door from a pc trying to enter from somewhere else. Ie two pc's cannot enter the same room from 2 different doors. However everyone can enter the area from the same door.

Basically it allows you to have generic area's that many doors link to instead of having to have 1 area for each door. simply name the area's and doors correctly and it works like a charm

if the area is empty it can again be entered from any door assigned to it. if it is occupied the pc attempting to enter from a different door gets the message an unknown force keeps you from entering.

it is simple and works very well.


it consists of 3 scripts
smartdoor.nss the main script
return.nss the script that returns the pc to where they left from

oexit_smartdoor.nss the script that checks if the area is now empty and disassociates the last door from it.



NWScript:
//::///////////////////////////////////////////////

//:: Name Smart Door System

//:: FileName smartdoor.nss

//:://////////////////////////////////////////////

/*

    Place this script in the door in your area

    leading to a shared room.

    name this door the same name as the target

    room you are going to

    place a waypoint inside the room you are going

    to with a tag of DST_areaname

    Ie.

    if your are going to an area named Appartment

    you need to do the following

    1. create an area Named Appartment with a tag

       of Appartment.

    2. create a waypoint inside that area with

       a tag of DST_Appartment facing the way you

       want the character to enter.

    3. create a door with the Tag of Appartment

       in your area, you can have as many of these

       as you want each one will lead to the area

       Appartment. Click the door's area transition

       tab and select waypoint but leave the destination

       field blank. In the doors OnAreaTransitionClicked

       script Place this script.

    4. create an exit door in the appartment area

       it doesnt matter what the tag or name of this door

       is, but click the doors area transition tag and

       select waypoint and leave the destination field

       blank. In the doors OnAreaTransitionClicked

       script Place the return script.

    5. In the Area Appartment Place in the OnExit event

       the script oexit_smartdoor

     you should now have an area with a tag of Appartment

     a main area you are going from

     a door in the main area with a tag of Appartment

     a door in the Appartment area

     a waypoint in the Appartment area named DST_Appartment.

     both doors area transitions set to waypoint with the

     destination blank.

     all the scripts in their proper locations.

*/

//:://////////////////////////////////////////////

//:: Created By: Zandramus

//:: Created On: 07.23.2002

//:://////////////////////////////////////////////

void main()

{

object oidUser;

object oidDest;

string sTag = GetTag(OBJECT_SELF);

string sDest;

location dLocation;

SetLocalString(OBJECT_SELF, "Destination" , "DST_"+sTag );

sDest = GetLocalString( OBJECT_SELF, "Destination" );

oidUser = GetLastUsedBy();

SetLocalLocation(oidUser,"IWASHERE",GetLocation(oidUser));

oidDest = GetWaypointByTag(sDest);

dLocation = GetLocation(OBJECT_SELF);

// we need to find out if area is locked

if (GetLocalInt(GetModule(),sDest) == 0) // Room is Unused

    {

     SetLocalLocation(GetModule(),sTag,dLocation);

     SetLocalInt(GetModule(),sDest, 1);

     AssignCommand(oidUser,JumpToObject(oidDest,FALSE));

    }

    else

    {

    if (GetLocalLocation(GetModule(),sTag)== dLocation) // Room is Being Used By this Door

       {

       AssignCommand(oidUser,JumpToObject(oidDest,FALSE));

       }

       else

          {

          SendMessageToPC(oidUser,"An Unknown Force Prevents you from entering");// Room is Being Used By another door

          }

    }

}




NWScript:
//::///////////////////////////////////////////////

//:: Name   Smart Door Return

//:: FileName  return.nss

//:://////////////////////////////////////////////

/*

    Place this script in your interior exit door's

    ontransitionclicked event. This will check the

    last location of the pc and return him there.

*/

//:://////////////////////////////////////////////

//:: Created By: Zandramus

//:: Created On: 07.23.2002

//:://////////////////////////////////////////////

void main()

{

object oidUser;

object oidDest;

string sDest;

oidUser = GetLastUsedBy();

AssignCommand(oidUser,JumpToLocation(GetLocalLocation(oidUser,"IWASHERE")));

}



NWScript:
//::///////////////////////////////////////////////

//:: Name  On Exit Smartdoor

//:: FileName oexit_smartdoor.nss

//:://////////////////////////////////////////////

/*

    Place this in the on exit event of your fluff area's

    it will pull the global variable name from the tag

    of that area so your area tag must match your door name

    this should be obvious by now.

*/

//:://////////////////////////////////////////////

//:: Created By: Zandramus

//:: Created On: 07.23.2002

//:://////////////////////////////////////////////

void main()

{

string sTag = GetTag(OBJECT_SELF);

string sDest;

SetLocalString(OBJECT_SELF, "Destination" , "DST_"+sTag );

sDest = GetLocalString( OBJECT_SELF, "Destination" );

if(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,OBJECT_SELF,1) == OBJECT_INVALID)

  {

  SetLocalInt(GetModule(),sDest, 0);   // area is empty unlock it

  }

}



you can download the erf of the 3 scripts here

http://mynwnserver.kicks-ass.net

enjoy

Zandramus