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:
void main()
{
object oPC=GetEnteringObject();
string sLastArea;
object oPassportCheck;
string sPassportCheck;
int nHasPassport=0;
string sGoToArea;
if (GetIsPC(oPC))
{
SendMessageToPC(oPC,"Checking for passport:");
oPassportCheck=GetFirstItemInInventory(oPC);
sPassportCheck=GetTag(oPassportCheck);
while (GetIsObjectValid(oPassportCheck))
{
if (sPassportCheck=="Area2")
{
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.");
}
oPassportCheck=GetNextItemInInventory(oPC);
sPassportCheck=GetTag(oPassportCheck);
}
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:
void main()
{
object oPC=GetEnteringObject();
if (GetIsPC(oPC))
{
CreateItemOnObject ("area2passport",oPC,1);
SendMessageToPC (oPC,"You should now have a passport for this area. Do not lose it!");
}
}
NWScript:
void main()
{
object oPC=GetEnteringObject();
if (GetIsPC(oPC))
{
CreateItemOnObject ("area3passport",oPC,1);
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:
void main()
{
object oPC=GetEnteringObject();
object oAreaPassportCheck=GetFirstItemInInventory(oPC);
string sAreaPassportCheck;
if (GetIsPC(oPC))
{
while (oAreaPassportCheck!=OBJECT_INVALID)
{
sAreaPassportCheck=GetTag(oAreaPassportCheck);
if (sAreaPassportCheck=="Area2")
{
DestroyObject(oAreaPassportCheck);
}
else if (sAreaPassportCheck=="Area3")
{
DestroyObject(oAreaPassportCheck);
}
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.
|