OnPlayerRest
The script attached to this event fires when a player attempts to rest, cancels resting, or resting is finished. It can be used to spawn some creatures around the PC to constantly badger him or her and prevent a successful rest in some areas or prevent natural healing altogether from a curse bestowed upon the player.
Trigger
When the player presses the "Rest" button (starting or cancelling a rest) or when the rest is finished. ActionRest will fire this, but ForceRest will not.
Function(s)
- GetLastPCRested returns the last PC to have rested, although may be invalid if they have quit the game mid-rest.
- GetLastRestEventType() returns one of the REST_EVENTTYPE_REST_* constants to determine what part of the rest caused this event to fire.
Remarks
If you want to control when a PC can rest, capture this event when GetLastRestEventType() returns REST_EVENTTYPE_REST_STARTED; then use AssignCommand() on the PC to ClearAllActions(). This prevents the attempted rest from completing. This event fires twice: once when the rest event begins, and again when it ends. Therefore, any scripts used for this event will execute twice, and any effects created by them will be duplicated. Use the GetLastRestEventType() function and the REST_EVENTTYPE_REST_* constants to determine which stage of the resting event is taking place.
To gain the effects of resting instantly, use ForceRest(). This is especially useful for cutscenes and during battles (if required!) and ignores all conditions of ActionRest() for failure.
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
While no "real time" actually passes the Poison and Disease events evidently imply some time has passed. Using SetTime after a rest is possible but may cause further disease events.
Example
// period
void main()
{
object oPC = GetLastPCRested();
// capture begin rest attempts
if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
// fun, fun, fun!
AssignCommand(oPC, ClearAllActions());
}
}
See Also
functions: |