Author Sticky: Post Working Scripts Here
jordinn Posted: Monday, 22 July 09:13AM
MODS: This is an update to the post on page 28 for the same scripts, that post can be deleted, as all the information is contained here.

Script Name: randominterior and exitrandomtp

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.

Description
UPDATED TO VERSION 1.5
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. Once they leave the treasure will delay then respawn, encounters in the interiors will respawn at intervals set on the encounter.

Notes:

New in 1.5:
Now henchmen, familiars, summoned, etc will come with you into the rooms.
Treasure respawning code added to repopulate placeables that can contain loot.

Future Improvements Pending:
Set random chance to lock chest on treasure respawn.
Use random doors unless character has a city map, then all doors stay static once visited.

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 suggest setting the encounter respawns to a minimum of 5 minutes and maximum of 7 minutes, depending on how close together the doors are. This is subject to your own testing based on the size of the areas you build for the interiors.

The treasure respawn is set to 45 seconds after exiting, but this is adjustable to your needs.

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.

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.

The Scripts:


NWScript:
/*//////////

//Random Genric Interior Script v1.5

///////////

//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, shea@oz.net

//Date Created: 7/16/02

// props to Lenkyl Greatstorm for the random speech script that I based this on, and

//  Malachai Moonshadow and Raasta for the code or clues they provided in their scripts.

//////////*/

/*////////

// Notes on Script v1.5:

//  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));

    //These lines will ensure all "supporting cast" members go too.

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION,oUser),JumpToObject(oTarget));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_DOMINATED,oUser),JumpToObject(oTarget));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_FAMILIAR,oUser),JumpToObject(oTarget));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_HENCHMAN,oUser),JumpToObject(oTarget));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_SUMMONED,oUser),JumpToObject(oTarget));

}  //End Main




NWScript:
/*///////////////////////////

// exitrandomtp v1.5

// By Jordinn

// date: 21Jul02

///////////////////////////*/

#include "NW_O2_CONINCLUDE"

//Declare Variables

int iRandomFlag;

int iTempCount;

int iRandNum;

location lTargetLoc;

object oUser;

object oContainer;

object oArea;

float fDelay;

//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();

    //Set area to current

    oArea = GetArea(OBJECT_SELF);

    //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);

        // Get nearest placeable object to generate treasure in

        oContainer = GetFirstObjectInArea(oArea);

        while (oContainer != OBJECT_INVALID)

        {

            if (GetObjectType(oContainer) == OBJECT_TYPE_PLACEABLE)

            {

                //How long before the treasure will respawn, in seconds

                fDelay = 45.0;

                //Randomly choose value of treasure that will appear

                iRandNum = d6(1);

                switch(iRandNum)

                {

                    case 1:

                    case 2:

                    case 3:

                        DelayCommand(fDelay, GenerateLowTreasure(oUser, oContainer));

                    break;

                    case 4:

                    case 5:

                        DelayCommand(fDelay, GenerateMediumTreasure(oUser, oContainer));

                    break;

                    case 6:

                        DelayCommand(fDelay, GenerateHighTreasure(oUser, oContainer));

                    break;

                }

            }

            //Wrap this in random number to randomly lock placeable objects on respawn

                //Uncomment the following line for the object to lock after being used.

                //DelayCommand(fDelay+0.5, ActionDoCommand(SetLocked(oContainer, TRUE)));

            oContainer = GetNextObjectInArea(oArea);

        }

    }

    //Reset user and module variables

    SetLocalInt(GetModule(), "iPartyCount", iTempCount);

    //Jump To Location

    AssignCommand(oUser, JumpToLocation(lTargetLoc));

    //These lines will ensure all "supporting cast" members go too.

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oUser), JumpToLocation(lTargetLoc));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_DOMINATED, oUser), JumpToLocation(lTargetLoc));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oUser), JumpToLocation(lTargetLoc));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_HENCHMAN, oUser), JumpToLocation(lTargetLoc));

    AssignCommand(GetAssociate(ASSOCIATE_TYPE_SUMMONED, oUser), JumpToLocation(lTargetLoc));

}



[ Edited By jordinn: Monday, 22 July 09:21AM (GMT) ]