Skip to content

How do you restrict player resting to a specific location on the map?

Hi, I know how to click the "no rest" checkbox in area properties (which disables resting in that entire area). But I've also seen modules where resting is only prohibited in certain areas of the map. (Such as modules that only allow resting inside of bedrooms). Can anyone show me how to do this? Thanks.

Comments

  • ProlericProleric Member Posts: 1,281
    edited April 2022
    You can add custom code to the end of the module OnRest script. Something like this:
        if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
        {
          if  (GetLocalInt(oPC, "NoRest") == 1)
            {
              SendMessageToPC(oPC, "You may not rest at this time.");
              AssignCommand(oPC, ClearAllActions());  // Cancel rest
              return;
            }
        }
    
    You might, for example, use the area OnEnter and OnExit scripts to set and clear NoRest. The bedroom area might contain a trigger that does the opposite (or clicking a bed might clear the flag temporarily).

    There is a snag with area and trigger OnEnter scripts - they fire again when a saved game is loaded. You can detect this, though. In the OnClientEnter script
      if (GetLocalInt(oPC, "ModuleEnteredBefore"))
        {
          SetLocalInt(oPC, "Reload", TRUE); // This tells area and trigger OnEnter scripts that we are loading a saved game
          return;
        }
    
      SetLocalInt(oPC, "ModuleEnteredBefore", TRUE);
    
    then in the area or trigger OnEnter script
      if (GetLocalInt(oPC, "Reload") && (GetTag(oArea) == GetLocalString(oPC, "AreaEntered")))
        {
          SetLocalInt(oPC, "Reload", FALSE);
          return;
        }
    

    This might seem complicated, but as long as you use generic scripts, you only have to write this code once to cover every eventuality. Of course, there might be cases where you need to code to fire when loading a saved game, but these are rare, at least for single player.
  • Nic_MercyNic_Mercy Member Posts: 418
    Another thing you can do is have areas set to no rest but use a placeable with an on use script that makes the user rest. I've seen PW's that do this so resting can only be done in a specific places in an area that are designated for resting.
Sign In or Register to comment.