DMH-Online

Dungeon Masters Helper · Est. 2005

Resting Scripts

NWN Script: resting_006.htm

Author Sticky: Post Working Scripts Here
agem Posted: Thursday, 25 July 05:26PM
Yes, yes I know this has been done several times, but the scripts I have seen up to now only let you rest next to the Bedroll or Throw Rug, so here comes…

Script name: Improved Bedroll Rest v1.0 and Bedroll Sleep beta v0.9

Improved Bedroll Rest v1.0:

Designed for: Useable Bedrolls(Placeables) -> Event OnUsed

What it does (visually): Lets Player run up to Bedroll. Sit down on the middle of the Bedroll right way round and then Rest.

What it does (technically): OnUsed Player runs to Bedroll then ForcesMoves to approximated middle off bedroll (done by looking in which Quadrant (Q1, Q2, Q3, Q4) of the coordinate system the Player is relative to the Bedroll. Then increasing the direction Location from which the Player is coming). This may sound complicated but is quite simple see code. Then Player gets aligned with bedroll so he can feel more comfortable when resting .
Then Rests.

Improved Bedroll Rest v1.0:
NWScript:
//::///////////////////////////////////////////////
//:: pl_rest_bedroll
//:://////////////////////////////////////////////
/*
  Goto middle of bedrolls, rugs ... and then turn
  Player in same direction then (animation) Rest.
*/
//:://////////////////////////////////////////////
//:: Created By: Hikade (nick: agem)
//:://////////////////////////////////////////////
void main()
{
object oPC = GetLastUsedBy();                       // Get Player using object
object oTarget = GetArea(OBJECT_SELF);              // Get Area Target is in
location lTarget = GetLocation(OBJECT_SELF);        // Needed to get vector
location lSource = GetLocation(oPC);                // Needed to get vector
vector vTarget = GetPositionFromLocation(lTarget);  // Needed to recalc Position to run to
vector vSource = GetPositionFromLocation(lSource);  // Needed to recalc Position to run to
float fFacing = GetFacingFromLocation(lTarget);     // Needed for final facing of PC
// Fix final Position to stand (x-coordinate)
if (vSource.x < vTarget.x)
{vTarget.x += 0.1f;}
else
{vTarget.x -= 0.1f;}
// Fix final Position to stand (x-coordinate)
if (vSource.y < vTarget.y)
{vTarget.y += 0.1f;}
else
{vTarget.y -= 0.1f;}
// Set final Standing Location
lTarget =  Location(oTarget,vTarget,fFacing);
// Enable PC to go recalced Location
AssignCommand(oPC,ActionForceMoveToLocation(lTarget));
// Wait until there and turn player in same direction bed is facing
DelayCommand(1.4f,AssignCommand(oPC, SetFacing(fFacing+180.0f)));
DelayCommand(1.3f,AssignCommand(oPC,ActionRest()));
//:: if you only want resting animation deativate line above and avtivate line bellow
//DelayCommand(1.3f,AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS,1.0f,300.0f)));
}



Bedroll Sleep beta v0.9

Designed for: Useable Bedrolls(Placeables) -> Event OnUsed

What it does (visually): Lets Player run up to Bedroll. Sit down on the middle of the Bedroll right way round and then play the sleep animation. And elf and Co. meditate instead off sleep as they should.

What it does (technically): Its based on the above Improved Bedroll Rest v1.0.

I am not totally satisfied with this script therefore the v0.9. It is because of the following 3 things I couldn’t find out till now. MAYBE SOME KNOWS SOME ADVICE ON THIS
 


     

  • Cant find a way to instant Rest e.g. (RESTORE SPELLS or SPECIAL ABILLITIES) without ACTIONREST(). Neither have I found a way to replace the ACTIONREST() animation by script.
     
  • Has anyone a LOOP script up his sleeve that is not dependant on the OnHeartBeat Event nor is CPU dependant?
     
  • Has anyone some advice how I could play the EffectVisualEffect (VFX_IMP_SLEEP) continuously as long as the sleeps without the OnHeartBeat event?
     



NWScript:
//::///////////////////////////////////////////////
//:: pl_sleep_bedroll
//:://////////////////////////////////////////////
/*
  Goto middle of bedrolls, rugs ... and then turn
  Player in same direction then (animation) Rest.
*/
//:://////////////////////////////////////////////
//:: Created By: Hikade (nick: agem)
//:://////////////////////////////////////////////
void main()
{
object oPC = GetLastUsedBy();                       // Get Player using object
object oTarget = GetArea(OBJECT_SELF);              // Get Area Target is in
location lTarget = GetLocation(OBJECT_SELF);        // Needed to get vector
location lSource = GetLocation(oPC);                // Needed to get vector
vector vTarget = GetPositionFromLocation(lTarget);  // Needed to recalc Position to run to
vector vSource = GetPositionFromLocation(lSource);  // Needed to recalc Position to run to
float fFacing = GetFacingFromLocation(lTarget);     // Needed for final facing of PC
int nDuration = 2;                                  // Duration of sleeping period
effect eSleep = EffectSleep();                      // assign effect to have
effect eVis = EffectVisualEffect(VFX_IMP_SLEEP);    // assign visuals (zzzZZZ)

// Fix final Position to stand (x-coordinate)
if (vSource.x < vTarget.x)
{vTarget.x += 0.1f;}
else
{vTarget.x -= 0.1f;}
// Fix final Position to stand (x-coordinate)
if (vSource.y < vTarget.y)
{vTarget.y += 0.1f;}
else
{vTarget.y -= 0.1f;}
// Set final Standing Location
lTarget =  Location(oTarget,vTarget,fFacing);
// Enable PC to go recalced Location
AssignCommand(oPC,ActionForceMoveToLocation(lTarget));
// Wait until there and turn player in same direction bed is facing
DelayCommand(1.4f,AssignCommand(oPC, SetFacing(fFacing)));
// Check if Player is immune to sleep
if (GetIsImmune(oPC,FEAT_IMMUNITY_TO_SLEEP) == TRUE || GetHasFeat(FEAT_IMMUNITY_TO_SLEEP,oPC) == TRUE)
    {
    FloatingTextStringOnCreature("",oPC);
    FloatingTextStringOnCreature("*Meditating*",oPC);           // Because Elf's don't sleep but instead meditate
    //DelayCommand(1.3f,AssignCommand(oPC,ActionRest()));
    //:: if you only want resting animation deativate line above and avtivate line bellow or visa versa
    DelayCommand(1.3f,AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS,1.0f,300.0f)));
    }
    else
    {
    // Do assigned effects and animations
    DelayCommand(2.0f,ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSleep, oPC, RoundsToSeconds(nDuration)));
    DelayCommand(4.6f,ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oPC, RoundsToSeconds(nDuration)));
    }
}



Insperations very welcome!ˇ!

⌂ All Scripts ← Previous 👁 Category List

All Resting Scripts

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