Author Sticky: Post Working Scripts Here
skibei_neko Posted: Sunday, 23 June 04:30AM
1. Immigration

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 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.

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", 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". 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. Yeah, that means that you have to always go back and modify a lot of scripts .

I don't know how to do this better. I suppose that if you can create the passport object in a particular inventory slot, alot of things can be simplified. I just worry about what happens if the player moves it to a different slot.

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.

Also, see the corresponding "imm" scripts after this.
NWScript:
void main()

{

// main bracket start

int TOTALAREAS=1;

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

     }

     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;

     }

     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;

     }

     break;

}

//switch end bracket

}

// for loop bracket end

//PC does not have passport

if (haspass==0)

{

//note when you create the passport object you need to do it by its ref tag, not its regular tag.  this caused me alot of confusion.

    CreateItemOnObject ("passport001",oPC,1);

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

    AssignCommand( oPC, ActionJumpToObject (

       GetObjectByTag( "MULTI_OutTown" )  ));

    }

}

//main bracket end



Here is the "imm_OutTown" script. Each one of these must be put in the OnEnter event for each save area. Of course, each one needs to be slightly modified (I think you can tell by looking at this). Also, each new save area needs the creation of a passport object and a waypoint.

This script deletes the old passport and creates a new passport object in inventory.

NWScript:
void main()

{

// main bracket start



int TOTALAREAS=1;

// 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,"Out Town script is running!");

int nSteps;

object currentpassport;

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

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

{

// for loop bracket begin

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

     currentpassport= GetItemPossessedBy( oPC,lastarea);

     DestroyObject( currentpassport,0.0);

     CreateItemOnObject( "passport002" ,oPC,1);

     }

     break;

case 1:

lastarea="oOutTown";

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

     break;

case 2:

lastarea="oWestDock";

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

     {

     currentpassport = GetItemPossessedBy (oPC,lastarea);

     DestroyObject (currentpassport,0.0);

     CreateItemOnObject ("passport002",oPC,1);

     }

     break;

}

//switch end bracket

}

// for loop bracket end

//end main

}