Author Sticky: Post Working Scripts Here
lostcarrier Posted: Sunday, 21 July 09:28PM
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()

{

 // Get the entering player and set his/her ability to rest to FALSE

 object oEnteringPlayer = GetEnteringObject();

 if (GetIsPC(oEnteringPlayer) == TRUE){

  SetLocalInt(oEnteringPlayer, "iInRestArea", 0);

  }

}



Next, modify your Module's OnPlayerRest script with the following:

NWScript:
// This script will cancel rest if a PC tries to rest in an area not designated for resting

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:
// This script sets the PCs local variable to 1, allowing them to rest while in this area

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:
// This script sets the PCs local variable to 0, prohibiting rest

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:
// This script will only let PCs level 3 and under rest in an area

#include "NW_I0_GENERIC"

void main()

{

 object oPC = GetEnteringObject();

 if (GetCharacterLevel(oPC) <= 3){ // Change the number 3 to whatever level you wish

  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){ // Change the number 3 to be the same level that you set in your OnEnter

  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.