Where can I find the player rest script?

Hi experts,
I’m a newbie and when reading NWN Lexicon on OnPlayerRest this part attracts my attention:

Begin Quote:

A summary of what happens on rest:

  • Rest start:
    • Fires OnPlayerRest with REST_EVENTTYPE_REST_STARTED - at this point it could be cancelled and the rest not do anything (so saves magical effects etc. from being lost)
    • Removal of all magical effects, temporary effects (of any subtype) and temporary magical item properties cast by the rester (on self and others).
    • Poison is applied
    • Animation begins; sit on floor
  • A gradual replacement of spell slots over the duration (doesn’t start instantly and goes up in level so level 0 spells are replenished, then 1, etc.)
  • A gradual replacement of HP (eg; starting on 20 of 100 means you gain 80 over the time sitting down)
  • Rest end:
    • Removal of all effects on the rester except SupernaturalEffect ones applied with DURATION_TYPE_PERMANENT.
    • All dominated creatures are released from the rester
    • Diseases propagate
    • Animation sit on floor is cancelled
    • Event: OnPlayerRest with REST_EVENTTYPE_REST_FINISHED

End Quote

I digged into the script file x2_mod_def_rest as well as x2_inc_restsys and only found a few lines that seem to be relevant, and the most suspicious one is:

effect eSleep = EffectVisualEffect(VFX_IMP_SLEEP);
ApplyEffectToObject(DURATION_TYPE_INSTANT,eSleep, oPC);

I have two questions:

  1. How do I find out what eSleep does and can I edit the script inside?

  2. In general, if I want to have a custom rest system, let’s say whenever the player clicks “R”, he/she must go through a series of conversions with a “DM” character, and only have a X% chance to memorize each spell, where should I hook the code into? Is putting everything in Module’s OnPlayerRest a good choice?

Thanks in advance~~

The Lexicon will tell you what functions and their related constants do, for example

https://nwnlexicon.com/index.php?title=EffectVisualEffect

In this case, all it’s doing is applying the visual effect.

To discover whether a function can be edited, look for the include file in the Lexicon. In this case, there isn’t one. You will find the function in the master include nwscript.nss, which means it’s an engine function you can’t change.

What you can (and must) change is the module’s OnPlayerRest script, because that is called when the player presses the rest button.

Since you’ve read the Lexicon, you will know that the same script is called by three different events, so you have to provide for all three cases.

Whether you put all the code inline, or split some out as functions, or package some in other events, is a matter of preference and general best practice.

For example, I have a conversation in which the boss curses the player to be restless. The ActionTaken script sets a flag. The only change to the rest script is to terminate with a message if that flag is set. The boss OnDeath event clears the flag.

1 Like

Thanks a lot! I’ll play with it and see what I can do. I did manage to print a message to the console but it looks like there is no way to call, say, the function that renders the “Resting…” dialog, as it’s hardcoded somewhere.

You can make a PC rest by issuing it ActionRest action:

// Makes first PC sit down and rest a bit
void main()
{
    object oPC = GetFirstPC();

    AssignCommand(oPC, ClearAllActions());
    AssignCommand(oPC, ActionRest());
}

You can also use ForceRest(oPC) to rest quickly (get all effects without showing the rest window / progress). it can be (and often is) called from within OnPlayerRest.

You cannot prevent spell memorization, but you can use DecrementRemainingSpellUses after the rest is finished.

1 Like