Script: Simple Rest Control Script
Compilation
Function: Allows module builders to control where PCs rest with
an option to restrict by PC level
I thought some of you might find this useful in your modules, be they
stand-alone, semi-persistent, or persistent.
This series of scripts allows you to decide where the PCs can rest in
your module. You can attach the scripts to either Generic Triggers that
you place where you want a rest spot, or to the Area itself.
The first script to change is the Module's OnClientEnter script. You
will want to replace the OnClientEnter script with the following one, or
add the content of this script appropriately into yours if you have
already made modifications to your script.
NWScript: void main()
{
object oEnteringPlayer = GetEnteringObject();
if (GetIsPC(oEnteringPlayer) == TRUE){
SetLocalInt(oEnteringPlayer, "iInRestArea", 0);
}
}
Next, modify your Module's OnPlayerRest script with the following:
NWScript:
void main()
{
object oRestingPC = GetLastPCRested();
int iCanRest = GetLocalInt(oRestingPC, "iInRestArea");
if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED){
if (iCanRest != 1){
AssignCommand(oRestingPC, ClearAllActions());
SendMessageToPC(oRestingPC, "You cannot rest here. You should move to an inn room or other area that allows you to rest.");
}
}
}
Now you need to set up some areas in which the PCs can rest. If you want
to make this area a room in an inn, for example, paint a Generic Trigger
on the floor of the room and place this script into the trigger's
OnEnter script:
NWScript:
void main()
{
object oPC = GetEnteringObject();
if (GetIsPC(oPC) == TRUE){
SendMessageToPC(oPC, "You may rest in this area.");
SetLocalInt(oPC, "iInRestArea", 1);
}
}
...and this code into the trigger's OnExit script:
NWScript:
void main()
{
object oPC = GetExitingObject();
if (GetIsPC(oPC) == TRUE){
SendMessageToPC(oPC, "It is no longer safe for you to rest.");
SetLocalInt(oPC, "iInRestArea", 0);
}
}
NOTE: The two above scripts can also be used in an Area's
OnEnter and OnExit scripts to enable resting in the entire area without
the need for painted triggers.
Now, say you want to have an area where your "newbie" players can rest,
but the veterans cannot: a newbie area of sorts. Use the following
script in lieu of the above OnEnter:
NWScript:
#include "NW_I0_GENERIC"
void main()
{
object oPC = GetEnteringObject();
if (GetCharacterLevel(oPC) <= 3){
if (GetIsPC(oPC) == TRUE){
SendMessageToPC(oPC, "You may rest in this area.");
SetLocalInt(oPC, "iInRestArea", 1);
}
}
}
...and then for the OnExit:
NWScript: #include "NW_I0_GENERIC"
void main()
{
object oPC = GetExitingObject();
if (GetCharacterLevel(oPC) <= 3){
if (GetIsPC(oPC) == TRUE){
SendMessageToPC(oPC, "You may rest in this area.");
SetLocalInt(oPC, "iInRestArea", 1);
}
}
}
I hope some of you find this script useful. Feel free to use it as is or
modify it in any way as long as you say "thanks" somewhere.
|