Gaming
 

Onplayerrest script

From NWNWiki


[edit] What it Does

This is a modified OnplayerRest Script, it allow's you to decide how often pc's may rest and whether you would like to save the character when they click rest.

[edit] Notes

This goes on your modules OnPlayerRest Event

[edit] The Script

// OnPlayerRest
// Written By Scarface
// Set the player resting time limit in minutes
const int RESTING_LIMIT = 5;
// Do you want players characters to be saved <span class="highlight">on</span> a full <span class="highlight">rest</span>?
const int SAVE_ON_REST = TRUE; //TRUE = YES   |   FALSE = NO
#include "x2_inc_switches"
void main()
{
    object oPC = GetLastPCRested(),
           oMod = GetModule();
    string sPlayerID = GetPCPlayerName(oPC) + GetName(oPC);
    effect eSleep = EffectVisualEffect(VFX_IMP_SLEEP);
    switch(GetLastRestEventType())
    {
        case REST_EVENTTYPE_REST_STARTED:
        {
            if (GetLocalInt(oMod, "REST_STATUS_" + sPlayerID))
            {
                AssignCommand(oPC, ClearAllActions());
                FloatingTextStringOnCreature("You may only <span class="highlight">rest</span> once per " +
                IntToString(RESTING_LIMIT) + " minutes.", oPC);
                DelayCommand(IntToFloat(RESTING_LIMIT) * 60,
                DeleteLocalInt(oMod, "REST_STATUS_" + sPlayerID));
                return;
            }
            else
            {
                SetLocalInt(oMod, "REST_STATUS_" + sPlayerID, TRUE);
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eSleep, oPC);
            }
            break;
        }
        case REST_EVENTTYPE_REST_CANCELLED:
        {
            break;
        }
        case REST_EVENTTYPE_REST_FINISHED:
        {
            if (SAVE_ON_REST)
            {
                ExportSingleCharacter(oPC);
                SendMessageToPC(oPC, "<c ó ><span class="highlight">Character</span> Saved</c>");
            }
            break;
        }
    }