Author Sticky: Post Working Scripts Here
Malverin Posted: Wednesday, 26 June 03:13AM
Name: Area Passport System

What it does: This script utilizes a token system to allow PCs to jump back to the same area they left a game from in Muliplayer after logging off so that they do not have to start all the way at the end of the module.

Notes: See text below

I had my own ideas on how to make a script that would spawn a person into the same area as the one from which they just left and this is the solution that I came up with.

It requires 3 basic scripts:

1. An OnModuleLoad script that scans the PC inventory upon entrance for a "passport" which designates the last area the PC visited. If it finds a valid passport, it will transport the PC to a specific waypoint in that area as defined in the script. For the script to work the passport item must adhere to the following format:

Name: Any (eg. Area 2)
Tag: Area Name (Area2)
Unique reference ID: Generated when you name the waypoint (eg. area2)

I decided not to use a claw/hide slot as many people seem to want to use them and if the player goes to another server that erases the passport token they will be forced to begin at the usual module starting location.

The waypoints to which the PC will be teleported in the various areas should be tagged in the following manner: TagName + SpawnHere, i.e. Area2SpawnHere, as the script automatically generates the teleport location from the passport token tag ID.

NWScript:
// module_passport

// Author: Malverin

// E-mail: Malverin@nwtavern.com

// To be place in OnModuleLoad for the module

// This script checks for an item on the entering PC

// indicating the last area the PC visited before exporting

// their character.  If it finds an item, it will transport

// the PC to that area.

// Note: This script should be run in conjunction with the

// area_passport and area_passportexit scripts

void main()

{

// Declaring the variables

object oPC=GetEnteringObject();

string sLastArea;

object oPassportCheck;

string sPassportCheck;

int nHasPassport=0;

string sGoToArea;

// Only runs script if entering object is a PC

if (GetIsPC(oPC))

 {

 SendMessageToPC(oPC,"Checking for passport:");  //Debugging Text - can be deleted

 oPassportCheck=GetFirstItemInInventory(oPC);

 sPassportCheck=GetTag(oPassportCheck);

 while (GetIsObjectValid(oPassportCheck))

  {

  // Set up a conditional for each passport

  if (sPassportCheck=="Area2")  //Must manually assign Tag of area passport item

   {

   sLastArea=sPassportCheck;

   nHasPassport=1;

   SendMessageToPC(oPC,"Passport for Area 2 found.");

   }

  else if (sPassportCheck=="Area3")

   {

   sLastArea=sPassportCheck;

   nHasPassport=1;

   SendMessageToPC(oPC,"Passport for Area 3 found.");

   }

   //Repeat check for as many areas as necessary

   //Cycle to Next Inventory Item

  oPassportCheck=GetNextItemInInventory(oPC);

  sPassportCheck=GetTag(oPassportCheck);

  }

 // Checks for outcome of passport check and moves PC

 if (nHasPassport==1)

  {

   sGoToArea=(sLastArea+"SpawnHere");

   SendMessageToPC(oPC,"Sending you to desired location.");

   AssignCommand(oPC,ActionJumpToLocation(GetLocation(GetObjectByTag(sGoToArea))));

  }

 else

  {

  SendMessageToPC(oPC,"No Passport found.  Sending you to module start location.");

  }

 }

}



2. The second script is very basic and is specific to each area that will generate a passport. All it does it spawn the area specific passport into the PC's inventory. Two examples are shown below:

NWScript:
// area2_passport

// Author: Malverin

// E-mail: Malverin@nwtavern.com

// To be placed in OnEnter for the Area

// This is a simple script that spawns an item into the entering PC's

// inventory.  The item must have a valid blueprint in the module.

void main()

{

object oPC=GetEnteringObject();

if (GetIsPC(oPC))

 {

 //Create Passport for the area in question.

 CreateItemOnObject ("area2passport",oPC,1);

 // Debugging text - can be removed

 SendMessageToPC (oPC,"You should now have a passport for this area.  Do not lose it!");

 }

}



NWScript:
// area3_passport

// Author: Malverin

// E-mail: Malverin@nwtavern.com

// To be placed in OnEnter for the Area

// This is a simple script that spawns an item into the entering PC's

// inventory.  The item must have a valid blueprint in the module.

void main()

{

object oPC=GetEnteringObject();

if (GetIsPC(oPC))

 {

 //Create Passport for the area in question.

 CreateItemOnObject ("area3passport",oPC,1);

 // Debugging text - can be removed

 SendMessageToPC (oPC,"You should now have a passport for this area.  Do not lose it!");

 }

}



3. The final script is a housekeeping script. It simple deletes any passport the player may be carrying when they exit an area. It must contain a conditional for each of the passports and should be applied to the OnExit for each area.

NWScript:
// area_passportexit

// Author: Malverin

// E-mail: Malverin@nwtavern.com

// To be placed in OnExit for all areas in the module.

// This is a simple script that spawns an item into the entering PC's

// inventory.  The item must have a valid blueprint in the module.

void main()

{

object oPC=GetEnteringObject();

object oAreaPassportCheck=GetFirstItemInInventory(oPC);

string sAreaPassportCheck;

if (GetIsPC(oPC))

 {

 // Search PC inventory and delete any old passport carried

 while (oAreaPassportCheck!=OBJECT_INVALID)

  {

  sAreaPassportCheck=GetTag(oAreaPassportCheck);

  // Set up conditional for all known passports

  if (sAreaPassportCheck=="Area2")

   {

    DestroyObject(oAreaPassportCheck);

   }

  else if (sAreaPassportCheck=="Area3")

   {

    DestroyObject(oAreaPassportCheck);

   }

  // Use as many conditionals as necessary

  // Just be certain strings match passport item tag

  oAreaPassportCheck=GetNextItemInInventory(oPC);

  }

 }

}



I have tested all these scripts in game and verified that they work. If anyone has questions on how to implement them or wishes to discuss how to optimize the code, let me know. This is my first attempt at coding so I am pretty certain that there is an easier way to do some things.

Thanks!

_________________
Malverin

Check out the new world being created for NWN at Neverwinter Tavern.