Author Sticky: Post Working Scripts Here
skibei_neko Posted: Monday, 24 June 10:44PM
1. immigration_main

2. This is a very usefull script for semi-persistant worlds. When implimented, it keeps track of the areas the player has last been in. If the player logs off the server and back on, or if the player goes to another erver running the same module with this script implimented, the player character will jump to the last area he/she was at. Actually, it does not have to go to the last area...the Builder reduce scripting work by selecting only certain areas to impliment. The best way to describe the usage is to compare it to Diablo 2; when a player logs on, they will appear at the last town of the Act that they last played.

This script allows that functionality accross different servers and can be used cooperatively between Builders.

Note...its my first time scripting and programming. I'm sure people out there can make this better. This is already updated from an earlier post making the script a little more efficient.

3. Basically this script checks a token passport item in the characters inventory and jumps the player to a corresponding waypoint. If there was no passport item, the script creates one.

In order to impliment, you need several components. First, for every area that can be a "save area", you need to create a "passport" item. In this script, the passports are "oOutTown", "oStagingArea", "oWestDock", etc. If the player discards this passport, they are SOL.

I created these three areas. StagingArea is a 1X1 room. This script "immigration_main" is attached to the "OnEnter" of Staging Area.

The other areas need to have waypoints. In this script, the waypoints are "MULTI_OutTown", "MULTI_WestDock". Those areas run corresponding "imm_" scripts on enter.

ONE VERY IMPORTANT ITEM is the TOTALAREAS constant. I don't know how to automate the counting of the number of save areas. Each time a save area is added to the module, you need to add to the TOTALAREAS constant in this script and in each of the imm_scripts.

fendis_khan and others helped me make this. Thanks to all the friendly NWN community people who helped me learn how to script.

There are a bunch of testing messages in here that you will need to delete later.

NWScript:
//:: Name  skibei_neko

//:: FileName  immigration_main

//:: Copyright (c) 2001 Bioware Corp.

/* This is a very usefull script for semi-persistant worlds.  When impimented,

it keeps track of the areas the player has last been in.  If the player logs off

the server and back on, or if the player goes to another server running the same

module with this script implimented, the player character will jump to the last

area he/she was at.  Actually, it does not have to go to the last area...the

Builder reduce scripting work by selecting only certain areas to impliment.  The

best way to describe the usage is to compare it to Diablo 2; when a player logs on,

they will appear at the last town of the Act that they last played.  This script

allows that functionality accross different servers and can be used cooperatively

between Builders.

Note...its my first time scripting and programming.  I'm sure people out there can

make this better.

In order to impliment, you need several components.  First, for every area that can

be a "save area", you need to create a "passport" item.  In this script, the passports

are "oOutTown", "oStagingArea", and "oWestDock".  If the player discards this passport

, they are SOL.

I created these three areas.   StagingArea is a 1X1 room.  This script "immigration" is

attached to the "OnEnter" of Staging Area.

The other areas need to have waypoints.  In this script, the waypoints are

"MULTI_OutTown", "MULTI_WestDock", etc.. All the save areas also have a script called

"immigratgion_area"

ONE VERY IMPORTANT ITEM is the TOTALAREAS constant.  I don't know how to automate the

counting of the number of save areas.  Each time a save area is added to the module,

you need to add to the TOTALAREAS constant in this script. Also, the "immigration_area" script

needs updating.  Y

fendis_khan and others helped me make this.  Thanks to all the friendly NWN community

people who helped me learn how to script.

There are a bunch of testing messages in here that you will need to delete later.

*/

//:: Created By:  skibei_neko@ yahoo.com

//:: Created On:   6/23/02



void main()

{

// main bracket start



int TOTALAREAS=4;

// Note very important to specify number of areas manually and change number

// as new areas are added.

string lastarea;

// last area is the matching string to find the passport token

object oPC= GetEnteringObject();

//gets oPC object

SendMessageToPC (oPC, "Immigration script is running!");

int haspass=0;

int nSteps;

//flag to see if player has the passport in inventory

for (nSteps=0; nSteps <= TOTALAREAS; nSteps++)

{

// for loop bracket begin

if (haspass==1 ) break;

switch (nSteps)

{

//switch begin bracket

case 0:

lastarea= "oStagingArea";

if  ( GetItemPossessedBy ( oPC,lastarea)!= OBJECT_INVALID)

     {

     SendMessageToPC ( oPC,"You seem to have received the Staging Area Passport");

   //  AssignCommand ( oPC, ActionJumpToLocation( GetObjectByTag( "MULTI_StagingArea" ) ) );

       AssignCommand ( oPC, ActionJumpToObject (

       GetWaypointByTag ( "MULTI_OutTown" ),0  ));

     haspass=1;

     SetLocalString ( oPC,"MULTI_Area", "StagingArea" );

     }

     break;

case 1:

lastarea= "oOutTown";

if  (GetItemPossessedBy ( oPC,lastarea )!= OBJECT_INVALID)

     {

     SendMessageToPC ( oPC,"You seem to have received the Out Town Passport");

     AssignCommand ( oPC, ActionJumpToObject (

       GetWaypointByTag ( "MULTI_OutTown" ),0  ));

     haspass=1;

     SetLocalString ( oPC,"MULTI_Area", "OutTown");

     }

     break;



case 2:

lastarea= "oWestDock";

if  (GetItemPossessedBy (oPC,lastarea)!= OBJECT_INVALID)

     {

     SendMessageToPC(oPC,"You seem to have received the West Dock Passport");

     AssignCommand ( oPC, ActionJumpToObject(

       GetWaypointByTag ( "MULTI_WestDock" ),0  ));

     haspass=1;

     SetLocalString ( oPC, "MULTI_Area", "WestDock");

     }

     break;

case 3:

lastarea= "oFloatingDistrict";

if  (GetItemPossessedBy (oPC,lastarea)!= OBJECT_INVALID)

     {

     SendMessageToPC (oPC, "You seem to have received the Floating District Passport");

     AssignCommand ( oPC, ActionJumpToObject (

       GetWaypointByTag ( "MULTI_FloatingDistrict" ),0  ));

     haspass=1;

     SetLocalString (oPC, "MULTI_Area", "FloatingDistrict" );

     }

     break;

case 4:

lastarea = "oUnderTheCity1";

if  (GetItemPossessedBy (oPC,lastarea)!= OBJECT_INVALID)

     {

     SendMessageToPC (oPC, "You seem to have received the Sewers Passport");

     AssignCommand ( oPC, ActionJumpToObject(

       GetWaypointByTag ( "MULTI_UnderTheCity1" ) ,0  ));

     haspass=1;

     SetLocalString ( oPC, "MULTI_Area", "UnderTheCity1");

     }

     break;

}

//switch end bracket

}

// for loop bracket end

//PC does not have passport

if (haspass==0)

{

    CreateItemOnObject ( "passport001", oPC,1 );

    SendMessageToPC (oPC, "You should have received the Staging Area Passport" );

    SetLocalString ( oPC, "MULTI_Area", "StagingArea");

     AssignCommand( oPC, ActionJumpToObject(

       GetWaypointByTag ( "MULTI_OutTown" ),0  ));

    }



}

//main bracket end



Also, each save area should have "immigration_area" on their OnEnter script. This destroys the last passport and sets a new passport object. This script needs to be updated as new save-areas are added

NWScript:
//:: Name  immigration_area

//:: FileName  immigration_area

//:: Copyright (c) 2001 Bioware Corp.

/*

*/

//:: Created By: skibei_neko@yahoo.com

//:: Created On: 6/23/02

void main()

{

// main bracket start



int TOTALAREAS= 4;

// Note very important to specify number of areas manually and change number

// as new areas are added.

string lastarea;

// last area is the matching string to find the passport token

object oPC= GetEnteringObject ();

//gets oPC object

SendMessageToPC (oPC, "West Dock script is running!" );

int nSteps;

object currentpassport;

//flag to see if player has the passport in inventory

if (GetLocalString ( oPC, "MULTI_Area" ) != GetTag(OBJECT_SELF))

{

//IF LOOP character does not have right passport

for (nSteps=0; nSteps <= TOTALAREAS; nSteps++)

{

// for loop bracket begin  Need to see what passport PC has and destroy it.

switch (nSteps)

{

//switch begin bracket

case 0:

lastarea= "oStagingArea";

if  (GetItemPossessedBy ( oPC,lastarea) != OBJECT_INVALID)

     {

     currentpassport = GetItemPossessedBy (oPC,lastarea);

     DestroyObject ( currentpassport,0.0) ;

     }

     break;

case 1:

lastarea= "oOutTown";

if  (GetItemPossessedBy (oPC,lastarea)!= OBJECT_INVALID)

     {

     currentpassport = GetItemPossessedBy ( oPC,lastarea);

     DestroyObject (currentpassport,0.0);

     }

     break;



case 2:

lastarea= "oWestDocks";

if  (GetItemPossessedBy (oPC,lastarea ) != OBJECT_INVALID)

     {

      currentpassport = GetItemPossessedBy (oPC,lastarea);

     DestroyObject ( currentpassport,0.0 );

     }

     break;

case 3:

lastarea= "oFloatingDistrict";

if  (GetItemPossessedBy  (oPC,lastarea)!= OBJECT_INVALID)

     {

      currentpassport=  GetItemPossessedBy (oPC,lastarea);

     DestroyObject (currentpassport,0.0);

     }

     break;

case 4:

lastarea=  "UnderTheCity1";

if  (GetItemPossessedBy  (oPC,lastarea)!= OBJECT_INVALID)

     {

      currentpassport = GetItemPossessedBy (oPC,lastarea);

     DestroyObject (currentpassport,0.0);

     }

     break;

}

//switch end bracket

}

// for loop bracket end

//figure out which passport to put in player inv

if (GetTag  (OBJECT_SELF) == "OutTown") CreateItemOnObject ("passport002", oPC,1);

if (GetTag  (OBJECT_SELF) == "UnderTheCity1") CreateItemOnObject ("passport004" ,oPC,1);

if (GetTag (OBJECT_SELF) == "WestDocks") CreateItemOnObject ("passport003", oPC,1);

if (GetTag (OBJECT_SELF) == "FloatingDistrict") CreateItemOnObject ( "passport005", oPC,1);

SetLocalString (oPC, "MULTI_Area", GetTag(OBJECT_SELF));

}

// end if



//end main

}