Author Sticky: Post Working Scripts Here
Seek Posted: Saturday, 22 June 09:49AM
These two scripts can be used for making secret trapdoors or other hidden objects. When a PC comes near the secret trap door a search check is made. If the check results in success a trapdoor will appear. When clicked the trapdoor calls an area transfer.

First, use the Placeable Wiz to make a trapdoor. Don't place it in your area. Edit the trapdoor (it will be somewhere in your custom palette) to run this script 'OnUsed'.

NWScript:
void main()

{

    object oPC = GetLastUsedBy();

    object oTarget = GetWaypointByTag( "wp_basement1");

    //replace wp_basement with the waypoint you want to end up at

    AssignCommand( oPC, JumpToObject( oTarget));

}



Now when a player clicks the trapdoor they'll do an area transfer. Next drop a waypoint in your area where you want the hidden trapdoor to be. Now set up a general trigger that stakes out the detection radius for the trapdoor. Drop this script in 'OnEnter'.

NWScript:
int MyAutoDC(int DC, int nSkill, object oTarget) //Ripped from Brent Knowles of Bioware with minor mods by me

{

//These might need to be tweaked.

//Easy = Lvl/4 ...rounded up

//Moderate = 3/Lvl + Lvl ...rounded up

//Difficult = Lvl * 1.5 + 6 ...rounded up

    int nLevel = GetHitDice( oTarget);

    int nTest = 0;

    switch (DC)

    {

    case 0: nTest = nLevel / 4 + 1; break;

        // * minor tweak to lower the values a little

    case 1: nTest = (3 / nLevel + nLevel) - abs( (nLevel/2) -2); break;

    case 2: nTest = FloatToInt( nLevel * 1.5 + 6) - abs( ( FloatToInt( nLevel/1.5) -2));   break;

    }

    //debug

    //SendMessageToPC( oTarget, IntToString( nTest));

    //end debug

    // * Roll d20 + skill rank vs. DC + 10

    if (GetSkillRank( nSkill, oTarget) + d20() >= nTest + 10)

        return TRUE;

    return FALSE;

}

int DoOnce() //Also ripped from Brent

{

    int bResult = FALSE;

    if ( GetLocalInt( OBJECT_SELF, "NW_L_DOONCE999") == 0)

    {

        SetLocalInt( OBJECT_SELF, "NW_L_DOONCE999", 1);

        bResult = TRUE;

    }

return bResult;

}



void main()

{

    object oPC = GetEnteringObject();

    //Find out where to create the object once it is detected

    location loc = GetLocation( GetNearestObjectByTag( "wp_trapdoor", oPC));

    //wp_trapdoor is the tag of a waypoint I set where I want the hidden object to appear

    int nDC = 2; //Set detection difficulty: 0-easy, 1-medium, 2-hard

    if( GetIsPC( oPC) && MyAutoDC( nDC, SKILL_SEARCH, oPC)) //Skill check vs. search skill

    {

        while( DoOnce())

        {

            SendMessageToPC( oPC, "You've found something...");

            CreateObject( OBJECT_TYPE_PLACEABLE, "cotrapdoor", loc, TRUE);

            //cotrapdoor is the template name of the triggered trapdoor

            //that I created and added to my palette

        }

    }

//  else SendMessageToPC( oPC, "Do you feel a draft?");

}



Both scripts compile and work as described for me. I hope others find the same. I'm not sure about the AutoDC skill check function. Medium seems way too easy and Easy is just a joke. I think I'll have it check PC level or some other number instead of hit dice.
I think I put comments in at the couple of places where you'll want to change tags to fit your modules. You'll want to change the way points and the trapdoor template name for sure. Hope I didn't leave anything out. It's 5am here and the Coffee isn't cutting it anymore.

-Seek
.

EDIT: UPDATED

I had the skill check determining DC based on the level of the player that was searching. This is obviously not the way to do it, so I made some (more) changes to AutoDC().

This new script will check based on challenge level (int nDC: 0-easy, 1-medium, 2-hard) specified in main(). Also it takes into account the level of the hidden object or the level of the hider if you want to think of it in those terms (int nHiddenObjLevel).

NWScript:
//AutoDC() ripped from Brent Knowles of Bioware with minor mods by me

//DoOnce() also ripped from Brent

//main() is all me

int MyAutoDC( int DC, int nLevel, int nSkill, object oTarget)

{

//These might need to be tweaked.

//Easy = Lvl/4 ...rounded up

//Moderate = 3/Lvl + Lvl ...rounded up

//Difficult = Lvl * 1.5 + 6 ...rounded up

    int nTest = 0;

    switch (DC)

    {

    case 0: nTest = nLevel / 4 + 1; break;

        // * minor tweak to lower the values a little

    case 1: nTest = (3 / nLevel + nLevel) - abs( (nLevel/2) -2); break;

    case 2: nTest = FloatToInt( nLevel * 1.5 + 6) - abs( ( FloatToInt( nLevel/1.5) -2));   break;

    }

    //debug

    //SendMessageToPC( oTarget, IntToString( nTest));

    //end debug

    // * Roll d20 + skill rank vs. DC + 10

    if (GetSkillRank( nSkill, oTarget) + d20() >= nTest + 10)

        return TRUE;

    return FALSE;

}

int DoOnce()

{

    int bResult = FALSE;

    if (GetLocalInt( OBJECT_SELF, "NW_L_DOONCE999") == 0)

    {

        SetLocalInt( OBJECT_SELF, "NW_L_DOONCE999", 1);

        bResult = TRUE;

    }

return bResult;

}



void main()

{

    object oPC = GetEnteringObject();

    //Find out where to create the object once it is detected

    location loc = GetLocation( GetNearestObjectByTag( "wp_trapdoor", oPC));

    //wp_trapdoor is the tag of a waypoint I set where I want the hidden object to appear

    int nDC = 1; //Set detection difficulty: 0-easy, 1-medium, 2-hard

    int nHiddenObjLevel = 3; //"level" of the hidden object or level of the one who hid it

    if( GetIsPC( oPC) && MyAutoDC( nDC, nHiddenObjLevel, SKILL_SEARCH, oPC)) //Skill check vs. search skill

    {

        while( DoOnce())

        {

            SendMessageToPC( oPC, "You've found something...");

            CreateObject( OBJECT_TYPE_PLACEABLE, "cotrapdoor", loc, TRUE);

            //cotrapdoor is the template name of the triggered trapdoor

            //that I created and added to my palette

        }

    }

//  else SendMessageToPC( oPC, "Do you feel a draft?");

}



Enjoy.

-Seek