Author Sticky: Post Working Scripts Here
Felderin Posted: Wednesday, 26 June 11:43PM
I just put the finishing touches (and finished debugging) my personal cross-country travel system (with multiple scripts), and I thought I'd share. Here's some background:

The goal was to create area transition exits that can lead to multiple destinations to simulate cross-country travel. For example, in my test module I have a bunch of local areas linked together via standard static area transitions, and then an exit from that cluster of local areas that leads into the open countryside. When you click on that exit, a conversation window pops open with a message that says "The road leads into the Western Region..." and gives you a list of destinations from which to choose. Click on one, and you travel there.

The cool thing is that it's very easy to script variables that add new destinations (new dialog choices) to the list when certain conditions are met. So perhaps the players meet a person who reveals the location of the Lost Ruins in the Western Region. Next time the players click on the Western Region exit, "The Lost Ruins" will appear in their list of possible destinations.

With me so far?

For extra fun, I added in a random encounter script. When you use the exit, it rolls a die to determine whether you have a random encounter on your journey. If you don't get a random encounter, it won't check again until the next game day. If you do, it diverts you from your chosen destination area to a special random encounter area. My random encounter area is basically a chunk of road with an exit at either end. The starting exit transports the players back to wherever they came from (determined dynamically), allowing them to flee. The exit at the other end allows them to continue to their original destination. In between them and that exit is a encounter trigger. The encounter area stays active (i.e. all traffic through the Western Region exit(s) gets diverted to the encounter area) until the players defeat the encounter.

Sound like something you want in your module? Here's how to do it.

1. First, you'll need to make some areas. For the purpose of this tutorial, let's make four (they can be any size and any tileset). We'll call the first one The Shady Woods, the second one The Sleepy Town, the third one The Sunny Fields, and the fourth one Random Encounter. You'll be able to travel to any of the first three areas from any other. Sometimes you'll get diverted to the Random Encounter area along the way, and will have to defeat an encounter in order to continue. Make sure that each of the first three areas has one exit. Make two exits (on opposite ends of the area) in the Random Encounter area. Name each of the exits something that you will remember (it helps to come up with a naming system BEFORE you start work on your module).

2. You will set up each of the exits in the same fashion *except* for the starting Random Encounter area exit (we'll deal with that one later). For now, choose any other exit and do the following: Under the "Advanced" tab, set the exit's faction to "Commoner" (we'll come back later and attach the conversation, after we create it). Under the "Area Transition" tab, select the "Door" destination type (leave everything else alone). Under the "Scripts" tab, add the following script to the OnAreaTransitionClick slot:

Code:
//::///////////////////////////////////////////////

//:: Object Conversation

//:: bs_obj_converse

//::

//:: Created By: Felderin

//:: Created On: 6/25/02

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

//Launches a conversation attached to an object. For placeables, this script must be placed

//in the "OnUsed" slot (make sure the object is flagged as "useable." For doors and area

//exits, this script must be placed in the OnAreaTransitionClick slot.

void main()

{

    ActionStartConversation(GetEnteringObject());

}



3. Create a conversation called "spooky_wilderness." Create a node off the Root that says "The roads leads into the Spooky Wilderness..." and then create three player response nodes off that one, like this:

Root
"The road leads into the Spooky Wilderness..."
[Travel to the Shady Woods]
[Travel to the Sleepy Town]
[Travel to the Sunny Fields]

Choose the "[Travel to the Shady Woods]" node and click on the "Actions Taken" tab. Click "Edit" and paste in this script:

Code:
//::///////////////////////////////////////////////

//:: Felderin's Cross-Country Travel Script

//:: bs_encounter.nss

//::

//:: Created By: Felderin

//:: Created On: 6/25/02

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

//Initiates travel from a travel conversation node, and generates a random chance that the

//player will be diverted to a random encounter area.

void main()

{

    //Roll the encounter die.

    int nEncounter = d3();

    //Get the player triggering the script.

    object oPC = GetEnteringObject();

    //Set the random encounter area.

    object oEncounter = GetObjectByTag("EncounterDoorTag");

    //Set the target destination.

    object oTarget = GetObjectByTag("DestinationAreaDoorTag");

    //Encounter state variables are assigned to the party leader.

    object oLeader = GetFirstPC();

    //Set a variable to remember the triggering player's starting location (see bs_travel_flee.nss).

    SetLocalLocation( oPC, "StartingLocation", GetLocation(oPC));

    //If an encounter is already active, the exit will automatically transport players to the encounter area until it is resolved.

    if (GetLocalInt( oLeader, "nEncounterActive") > 0)

        {

        AssignCommand( oPC, JumpToObject( oEncounter));

        }

    //If a negative encounter check was already made today, the script will not make another check until tomorrow.

    else if (GetLocalInt( oLeader, "nEncounterInactive") == GetCalendarDay())

        {

        AssignCommand( oPC, JumpToObject( oTarget));

        }

    //If neither encounter state variable checks out, the script makes a new encounter check.

    else if (nEncounter < 3)

        {

        AssignCommand( oPC, JumpToObject( oTarget));

        SetLocalInt( oLeader, "nEncounterInactive", GetCalendarDay());

        }

    else

        {

        AssignCommand( oPC, JumpToObject( oEncounter));

        SetLocalInt( oLeader, "nEncounterActive", 1);

        }

}



Do the same for each of the other destination nodes in your conversation, making sure to change "ShadyWoodsDoorTag" to the door tag of the target destination in each instance. Save the conversation.

4. Go to each of the exits in your first three areas and attach this conversation to them in the "Advanced" tab of the Properties window. **Be sure to flag the "No Interrupt" checkbox.**

5. The entry door (the door the players will appear at when they have a random encounter) in the random encounter area works a bit differently. Open that door's properties. Under the "Basic" tab, make sure the door's tag matches the "EncounterDoorTag" string in the bs_travel.nss script. Under the "Area Transition" tab, select the Door transition type. Under the "Scripts" tab, place the following script in the OnAreaTransitionClick slot:

Code:
//::///////////////////////////////////////////////

//:: Flee from Random Encounter Area

//:: bs_travel_flee.nss

//::

//:: Created By: Felderin

//:: Created On: 6/26/02

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



//This script allows the players to flee from the Random Encounter area, and is intended for use

//in conjunction with script bs-travel.nss. Place this script in the OnAreaTransitionClick slot of

//the entry door to the random encounter area. Players that use this door will be taken back to

//their starting area (determined dynamically).

void main()

{

    object oPC = GetEnteringObject();

    AssignCommand( oPC, JumpToLocation(GetLocalLocation(oPC, "StartingLocation")));

}



Set up the second (exit) Random Encounter area door in the same fashion as the doors in all the other areas. Now you need to make the encounter itself; paint down an encounter trigger right next to the entry door in the Random Encounter area. Make sure that the players *must* walk through the trigger in order to traverse the area. The encounter can be anything you like. Open its Properties window and place the following script in the OnExhausted slot under the "Scripts" tab:

Code:
//::///////////////////////////////////////////////

//:: Encounter Switch

//:: bs_travel_switch.nss

//::

//:: Created By: Felderin

//:: Created On: 6/26/02

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

//This script turns off the random encounter area, and is intended to be used in conjunction with

//script bs_travel.nss. Place this script in the OnExhausted slot of the encounter trigger in your

//random encounter area.

void main()

{

    SetLocalInt( GetFirstPC(), "nEncounterActive", 0);

    SetLocalInt( GetFirstPC(), "nEncounterInactive", GetCalendarDay());

}



You should be set. Save your module, try it out. Enjoy. =)