DMH-Online

Dungeon Masters Helper · Est. 2005

Areas Scripts

NWN Script: random_interiors.htm

Author Sticky: Post Working Scripts Here
jordinn Posted: Friday, 19 July 07:14AM
1. Script Name: randominterior and exitrandomtp

2. What it does: This pair of scripts takes players to randomly selected interiors when using doors and returns them back to their original location when they leave the interior space.

3. Notes: Here is a little script I put together to use for big cities where every building has some random filler content that isn't plot or important, but is filled in with possible encounters.

Here is what you need to do:

1) Make 1-20 interior areas generically, and fill with items, encounters, etc.
2) Place a waypoint in each one with the TAG WP_RandomX where X = 1 to 20 (actually the tag is not name specific, but you'll need to specify the right tag in the script.)
3) On the door out, attach the exitrandomtp script to the OnAreaTransitionClick or OnOpen event.
4) Now for each door in the outer area you create, attach the randominterior script to the OnAreaTransitionClick or OnOpen event.

This should take the party to a randomly selected interior let them fight, loot, etc, then take them back to the starting point when they use the door to get out.

Notes:
Currently not tested or written for multiparty modules or persistent worlds. The variables used will have to be adjusted or this could result in parties teleporting to each others locations.

I haven't tested and optimized respawn settings for the interiors yet. My next enhancement will be to trigger a respawn timer on the exit of the last player, but I haven't gotten around to that yet.

Some side effects of this are present, not sure I know how to avoid them at this point. First, the same door may take you to different interiors when revisting the door. Also if the party splits up and clicks multiple doors, they will end up in the same place. Not good for Hard Core RP Rules or "reality" in the game.

Due to the random number functions available, I've set it so you can have 2, 3, 4, 6, 8, 10, 12, 20 possible unique locations. If you want 5, use the 6 function and just make a roll of 6 go to one of the 1-5 locations.

Module Level variables used:
iPartyCount - Used to track how many go in so you can get them all back out and reset at teh end.
iRandomTPActive - Flag for determining if a current random Teleport is going on so all party members can be sent to same location.

User Level Variables:
lRandomTPLoc - THe loc a user teleported from so they can be returned to that location later.

4. The Script itself

NWScript:
/*//////////
//Random Genric Interior Script v1.0
///////////
//This script rolls 1dX and takes players to the random interior determined by the roll.
// All ensuing clicks go to same location until entire party leaves.
// X can be values 2, 3, 4, 6, 8, 10, 12, or 20
//Variable reset at time of leaving done via separate script (exitrandomtp)
///////////
//Script by Jordinn
//Date Created: 7/16/02
// props to Lenkyl Greatstorm for the random speech script that I based this on.
//////////*/
/*////////
// Notes on Script v1.0:
//  Assumes single party at this point.
//   Will need to modify to account for multiple active parties.
//  Assumes party stays together.
//   May need to implement scripts to enforce group cohesion on door use
//  Introduces some nonhardcore RP issues
//  Same door can go to multiple places when revisted.
//  Split party clicking multiple doors go to same place currently, but
//   return to original loc on exit
///////////*/
//This is the variable for storing the location you came from
// (reset via exitrandomtp script)
//location lRandomTPLoc;
//This is the flag for Active teleport (TP) (0 = inactive, 1-20 = active)
// int iRandomTPActive;
//This is the flag to count party going in so you know when they are all out.
//  int iPartyCount;
//Specify the waypoint names for later use.
// Change WP_XXXX to correct waypoints built into the target areas.
//Comment out the ones not used.
// (ie if you use 4 for iLocNum then comment out 5 - 20 on this list.)
string sWaypoint1 = "WP_Random1";
string sWaypoint2 = "WP_Random2";
string sWaypoint3 = "WP_Random3";
string sWaypoint4 = "WP_Random4";
/*string sWaypoint5 = "WP_Random5";
string sWaypoint6 = "WP_Random6";
string sWaypoint7 = "WP_Random7";
string sWaypoint8 = "WP_Random8";
string sWaypoint9 = "WP_Random9";
string sWaypoint10 = "WP_Random10";
string sWaypoint11 = "WP_Random11";
string sWaypoint12 = "WP_Random12";
string sWaypoint13 = "WP_Random13";
string sWaypoint14 = "WP_Random14";
string sWaypoint15 = "WP_Random15";
string sWaypoint16 = "WP_Random16";
string sWaypoint17 = "WP_Random17";
string sWaypoint18 = "WP_Random18";
string sWaypoint19 = "WP_Random19";
string sWaypoint20 = "WP_Random20";*/
//Declare object and set to what clicked on the door / area transition
object oUser = GetClickingObject();
//Change to below if using enter instead of click as event to fire transition
//object oUser = GetEnteringObject();
//If somehow this is done via conversation, try using this line
//object oUser = GetPCSpeaker();
//Declare object for target of teleport
object oTarget;
//Declare int for later use
int iRolledNum;
//Declare variable to store temp count data
int iTempCount;
void main()
{
    //Defines the random number rolled.  Comment out the lines not used.
    //Avoid rerolling if we've got an active TP going.
    if (GetLocalInt(GetModule(), "iRandomTPActive") == 0)
    {
        //iRolledNum = d2(1);
        //iRolledNum = d3(1);
        iRolledNum = d4(1);
        //iRolledNum = d6(1);
        //iRolledNum = d8(1);
        //iRolledNum = d10(1);
        //iRolledNum = d12(1);
        //iRolledNum = d20(1);
    }
    else
    {
        //If active TP going on, use the existing number stored
        iRolledNum = GetLocalInt(GetModule(), "iRandomTPActive");
    }
    if(iRolledNum != 0)       //Catch Case 0 just in case
    {
        switch(iRolledNum)    //Jump to the rolled statement number.
        {
            case 1:
                oTarget = GetWaypointByTag(sWaypoint1);
            break;
            case 2:
                oTarget = GetWaypointByTag(sWaypoint2);
            break;
            case 3:
                oTarget = GetWaypointByTag(sWaypoint3);
            break;
            case 4:
                oTarget = GetWaypointByTag(sWaypoint4);
            break;
            /*case 5:
                oTarget = GetWaypointByTag(sWaypoint5);
            break;
            case 6:
                oTarget = GetWaypointByTag(sWaypoint6);
            break;
            case 7:
                oTarget = GetWaypointByTag(sWaypoint7);
            break;
            case 8:
                oTarget = GetWaypointByTag(sWaypoint8);
            break;
            case 9:
                oTarget = GetWaypointByTag(sWaypoint9);
            break;
            case 10:
                oTarget = GetWaypointByTag(sWaypoint10);
            break;
            case 11:
                oTarget = GetWaypointByTag(sWaypoint11);
            break;
            case 12:
                oTarget = GetWaypointByTag(sWaypoint12);
            break;
            case 13:
                oTarget = GetWaypointByTag(sWaypoint13);
            break;
            case 14:
                oTarget = GetWaypointByTag(sWaypoint14);
            break;
            case 15:
                oTarget = GetWaypointByTag(sWaypoint15);
            break;
            case 16:
                oTarget = GetWaypointByTag(sWaypoint16);
            break;
            case 17:
                oTarget = GetWaypointByTag(sWaypoint17);
            break;
            case 18:
                oTarget = GetWaypointByTag(sWaypoint18);
            break;
            case 19:
                oTarget = GetWaypointByTag(sWaypoint19);
            break;
            case 20:
                oTarget = GetWaypointByTag(sWaypoint20);
            break;*/
        } //End Switch Statement
    }  //End If Statement
    else
    {
        //Assuming 0 should be invalid, set to desired waypoint
        //Change this to whatever the "Default value" the waypoint should be
        iRolledNum = 1;
        oTarget = GetWaypointByTag(sWaypoint1);
    }
    //Check to see if there is an active TP, if not set to number being used.
    if (GetLocalInt(GetModule(), "iRandomTPActive") == 0)
    {
        SetLocalInt(GetModule(), "iRandomTPActive", iRolledNum);
    }
    //Count party members going in so you know when all leave.
    iTempCount = GetLocalInt(GetModule(), "iPartyCount");
    iTempCount++;
    SetLocalInt(GetModule(), "iPartyCount", iTempCount);
    //Remember user's location so you can put them back at right door later.
    SetLocalLocation(oUser, "lRandomTPLoc", GetLocation(oUser));
    //Teleport command
    AssignCommand(oUser, JumpToObject(oTarget));
}  //End Main



NWScript:
/*///////////////////////////
// exitrandomtp v1.0
// By Jordinn
// date: 16Jul02
///////////////////////////*/
//Declare Variables
int iRandomFlag;
int iTempCount;
location lTargetLoc;
object oUser;
//Main function
void main()
{
    //Get object that clicked, entered, or used the door to get out
    oUser = GetClickingObject();
    //If using enter event, use this line
    //oUser = GetEnteringObject();
    //If using conversation, use
    //oUser = GetPCSpeaker();
    //Get Variables from Module
    iRandomFlag = GetLocalInt(GetModule(), "iRandomTPActive");
    iTempCount = GetLocalInt(GetModule(), "iPartyCount");
    //Get lRandomTPLoc from the object
    lTargetLoc = GetLocalLocation(oUser, "lRandomTPLoc");
    //if not 0, decrement iTempCount
    if(iTempCount >= 1)
    {
        iTempCount--;
    }
    else
    {
        iTempCount = 0;
    }
    //if 0 set iRandomTPActive = 0
    if(iTempCount == 0)
    {
        SetLocalInt(GetModule(), "iRandomTPActive", 0);
    }
    //Reset user and module variables
    SetLocalInt(GetModule(), "iPartyCount", iTempCount);
    //Jump To Location
    AssignCommand(oUser, JumpToLocation(lTargetLoc));
}
⌂ All Scripts ← PreviousNext → 👁 Category List

All Areas Scripts

📄 ambient_npc_ani 📄 area_spawner 📄 change_lighting 📄 clean_trash_001 📄 clean_trash_002 📄 clean_trash_003 📄 despawn_mobs 📄 despawn_mobs_002 📄 disable_sound 📄 full_edge_transition_001 📄 full_edge_transition_002 📄 full_edge_transition_003 📄 full_edge_transition_004 📄 full_edge_transition_004a 📄 get_pcs 📄 guard_patrols 📄 keyed_transitions 📄 random_enc_001 📄 random_enc_002 📄 random_enc_003 📄 random_enc_004 📄 random_enc_006 📄 random_enc_009 📄 random_encounter_005 📄 random_interiors 📄 random_interiors_001a 📄 restrict_access 📄 sitting_area