DMH-Online

Dungeon Masters Helper · Est. 2005

Resting Scripts

NWN Script: resting_004.htm

Author Sticky: Post Working Scripts Here
Sinister_Urge Posted: Thursday, 11 July 03:29AM
Script Name: Restricted Rest

What it does: Prevents PC's from resting anywhere they choose. Instead, the module designer can flag areas as restable (either an entire NWN Area, or a smaller area, such as a roadside campsite, defined by a trigger.

Notes: Integration with some sort of wandering monster script should probably also be added. Basically, an area can have a flag, SAFE_REST, indicating the option of the rest being interrupted by a wandering monster. But for my initial run, this is good enough.

First, place this script in your Module's OnResting event:

NWScript:
//::///////////////////////////////////////////////
//:: Name restricted_rest 1.0
//:: Copyright (c) 2002 Forest Zachman
//:://////////////////////////////////////////////
/*
*/
//:://////////////////////////////////////////////
//:: Created By: Forest Zachman
//:: Created On: 7/10/02
//:://////////////////////////////////////////////

void main()
{
    int iRestEvent = GetLastRestEventType();
    //Check to see if the PC is starting to rest
    if (iRestEvent == REST_EVENTTYPE_REST_STARTED) {
        object oRestingPC = GetLastPCRested();
        // This variable is set either by a trigger around a "campsite"
        // or in the OnEnter event of an Area.
        int iAllowedToRest = GetLocalInt(oRestingPC, "ALLOWED_TO_REST");
        if (iAllowedToRest == 0) {
            // This area is off limits for resting
            // and the character is not in a rest area.
            AssignCommand(oRestingPC, ClearAllActions());
            FloatingTextStringOnCreature("You are not allowed to rest here.", oRestingPC, FALSE);
        }
    }
}



This basically disallows rest everywhere in your module. Now, two scripts will allow a player to rest. One goes in the OnEnter of a Trigger (around a campsite for example) or Area (on the entire second floor of an Inn containing rooms or a secluded glade for example) and the other goes in the OnExit of the same Trigger/Area.

OnEnter:

NWScript:
void main()
{
    object oPC = GetEnteringObject();
    if (GetIsPC(oPC)) {
        SetLocalInt(oPC, "ALLOWED_TO_REST", 1);
    }
}



OnExit:

NWScript:
void main()
{
    object oPC = GetExitingObject();
    if (GetIsPC(oPC)) {
        DeleteLocalInt(oPC, "ALLOWED_TO_REST");
    }
}



Voila

⌂ All Scripts ← PreviousNext → 👁 Category List

All Resting Scripts

📄 rest_001 📄 rest_002 📄 rest_003 📄 resting 📄 resting_004 📄 resting_005 📄 resting_006