Author Sticky: Post Working Scripts Here
Milamber-POL Posted: Thursday, 25 July 12:01AM
This script prevents a PC from using an area transition unless they have one of the seven keys that open rooms on the other side of the area transition. I don't allow resting except at the Inn in my module, and for that you need to buy a key from the barkeeper. To prevent cheap PCs from just going upstairs and resting in the hall I needed a script that would allow multiple keys to use a single door.


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

// at_1doormanykey

// By:  Milamber-POL

// July 20, 2002

// OnAreaTransition

///////////////////////////////////////////////////////

//

// This prevents a PC from using an area transition

// Unless they have an appropriate key.   In this

// case the area transition leads to the second floor

// of an Inn Named the Rainbow Parrot.   There are

// a number of rooms on the second floor for resting

// but to get through the Area tranition the PC needs

// a key which has "ParrotKey" as the first part

// of the tag.

// NOTE the key is taken from the PC when they go back

// downstairs.

//

///////////////////////////////////////////////////////

void main()

{

  object oClicker = GetClickingObject();

  object oTarget = GetTransitionTarget(OBJECT_SELF);

  location lLoc = GetLocation(oTarget);

  string sKey = "ParrotKey";

  object firstItemInInv;

  object currentItemInInv;

    firstItemInInv = GetFirstItemInInventory(oClicker);

    currentItemInInv = firstItemInInv;

    SetLocalInt(OBJECT_SELF, "KEY_CHECK", FALSE);

    // Insure they have at least one object

    if(currentItemInInv != OBJECT_INVALID)

    {

        do

        {

          string sItem = GetTag(currentItemInInv);            // get the tag of the Item

          string s1 = GetStringLeft(sItem, 9);                // get the first 9 chartacters

            if(s1 == sKey)

            {

                SetLocalInt(OBJECT_SELF, "KEY_CHECK", TRUE);  // Set Local Int to True

            }

            // get next item

            currentItemInInv = GetNextItemInInventory(oClicker);

        // loop while we have a new item to check

        }while(currentItemInInv != OBJECT_INVALID &&

               currentItemInInv != firstItemInInv);

     }

    if (GetLocalInt(OBJECT_SELF, "KEY_CHECK") == 1)

    {

        AssignCommand(oClicker,JumpToLocation(lLoc));

    }

    else

    {

        SpeakString( "You need to have a room key to access this area.");

    }

}




Milamber-POL
Paladins of Light
www.pofl.org