Jump to content

Dream/Sleep Papyrus Script Help


Mattiewagg

Recommended Posts

Somebody asked for help with a script on my website, but in trying to answer it, I realized I wasn't entirely sure how to do it. Their question was this:

 

Hey so I was hoping someone can help me out with a quest mod I'm trying to do. I want it so when the player sleeps in a bed, he has a "Dream" and is sent into another world space to complete his dream quest and is then moved back to where he has slept. I'm new to modding but have fiddle around in the creation kit for a bit but I'm not sure where to start with this. Any help would be appreciated a lot.

So I was wondering how this could be done. I looked at the Dark brotherhood quests for some reference, but it wasn't quite what I was looking for. I cobbled together this script in a few minutes, but it doesn't work entirely.

Scriptname SleepTestScriptDream extends ReferenceAlias
{Attach this script to a reference alias in your quest pointing to the player}

ObjectReference Property XMarkerDreamStart Auto
ObjectReference Property XMarkerPlayerLoc Auto

Event OnInit()	
     RegisterForSleep()	
EndEventEvent 

OnSleepStart(Float afSleepStartTime, Float afDesiredSleepEndTime)

     If GetOwningQuest().GetStage() == 10			

          XMarkerPlayerLoc.MoveTo(Game.GetPlayer(), 10)		
          Game.GetPlayer().MoveTo(XMarkerDreamStart)		             
          Game.DisablePlayerControls(true, true, true, false, true, true, true, false)		
          Debug.Notification("Scene would be here...")		              
          Utility.Wait(5.0)		      
          Game.GetPlayer().MoveTo(XMarkerPlayerLoc)                       
          Game.EnablePlayerControls()		UnregisterForSleep()		      
          GetOwningQuest().SetStage(20)		Debug.Notification("Dream ended.")			

     EndIf	

EndEvent
It's attached to a playeralias on the quest I had for the dream. The quest was activated (set to stage 10) on reading a book, and the idea was that once you went to sleep, if the proper conditions were met, then a marker would move to where the player was (the bed), somewhat near them. Then, the player would move to another marker somewhere else, their controls would be disabled, and a scene would play at that location. Then, the player would move back to the marker that was near where they were. While the XMarkerPlayerLoc would have been buggy, and possibly end up with players in the walls, I'm too tired to think of a better way. If you've got a better idea for sending the player back to the bed they went to sleep in, that would be helpful.

 

What ended up happening is I went to sleep, woke up with my controls disabled, the notification played, I stood there for five seconds next to the bed, and then was released from the "cutscene".

 

How would you go about doing this?

Edited by Matthiaswagg
Link to comment
Share on other sites

Strangely enough, I am also testing this same predicament. Except in my particular scenario, the player will return after reading a book. It's almost spooky! If I find a solution, I will post it here for the good of all future google hunters.
Link to comment
Share on other sites

Strangely enough, I am also testing this same predicament. Except in my particular scenario, the player will return after reading a book. It's almost spooky! If I find a solution, I will post it here for the good of all future google hunters.

 

Thank you! I did get some advice here to fix my actual script, but my scene wouldn't start, so I would just wait around endlessly.

Link to comment
Share on other sites

Just a thought, and forgive me if its teaching a grandmother to suck eggs. But have you tried dividing this up in to separate stages? I know that stages will definitely trigger scenes and move to's. I wonder if the scene should be simply triggered by a setstage, and then a separate stage should trigger the return. It maybe simpler to just have the sleep event set the first stage rather than doing so much leg work. The main concern is after all is to mark player loc whilst moving them elsewhere ar the same time. This is just a thought. I'm not going to get a chance to try this out until later tonight, so let me know if you agree or disagree. Cheers matey
Link to comment
Share on other sites

Just a thought, and forgive me if its teaching a grandmother to suck eggs. But have you tried dividing this up in to separate stages? I know that stages will definitely trigger scenes and move to's. I wonder if the scene should be simply triggered by a setstage, and then a separate stage should trigger the return. It maybe simpler to just have the sleep event set the first stage rather than doing so much leg work. The main concern is after all is to mark player loc whilst moving them elsewhere ar the same time. This is just a thought. I'm not going to get a chance to try this out until later tonight, so let me know if you agree or disagree. Cheers matey

 

What I ended up doing was having this script start when the player on the player:

ObjectReference Property XMarkerDreamStart Auto
ObjectReference Property XMarkerPlayerLoc Auto

Event OnInit()	
     RegisterForSleep()	
EndEventEvent 

OnSleepStart(Float afSleepStartTime, Float afDesiredSleepEndTime)

     If GetOwningQuest().GetStage() == 10			

          XMarkerPlayerLoc.MoveTo(Game.GetPlayer(), 10)		
          Game.GetPlayer().MoveTo(XMarkerDreamStart)		             
          Game.DisablePlayerControls(true, true, true, false, true, true, true, false)	 
          GetOwningQuest().SetStage(20)					

     EndIf	

EndEvent

Then in Stage 20 I had:

MyScene.Start()

With the property filled. Then at the end of my scene I had a small Wait timer with a script on it like this:

GetOwningQuest().SetStage(25)

Then in Stage 25 I had the following:

Game.GetPlayer().MoveTo(XMarkerPlayerLoc)
Game.EnablePlayerControls()
SetStage(30)

However, while most everything worked properly, the scene itself wouldn't start so I just sat there. I'm not all that great at scenes, but I had the packages set up for the two actors in the script to travel to a designated XMarker, and then have some dialogue, but they didn't travel.

Link to comment
Share on other sites

Do you have more than one package on the scene actors? It's always caused problems for me when I've had a new package activate too soon after my initial travel one. I tend to use the first package for more than one phrase, it seems to work. Sometimes its also useful to make a new test scene; more to there and say that... If that doesn't work, then at least its easier to try and figure out.
Link to comment
Share on other sites

Do you have more than one package on the scene actors? It's always caused problems for me when I've had a new package activate too soon after my initial travel one. I tend to use the first package for more than one phrase, it seems to work. Sometimes its also useful to make a new test scene; more to there and say that... If that doesn't work, then at least its easier to try and figure out.

 

True. I'll probably make test scene in a bit.

Link to comment
Share on other sites

Cool. I will be testing this myself later. It's kind of my end game for my current mod, so its fairly important to make it work. In my case however, I am merely concerned with the mark and recall aspect triggered by sleep.
Link to comment
Share on other sites

Cool. I will be testing this myself later. It's kind of my end game for my current mod, so its fairly important to make it work. In my case however, I am merely concerned with the mark and recall aspect triggered by sleep.

Just to confirm, using stages to do all the leg work is a successful method (if not as cool as a "do it all" script). Simply create an alias that points to the player and attach this script to it (using your own stages of course):

Scriptname YOURSCRIPTNAME extends ReferenceAlias  

event OnSleepStart(float afSleeptStartTime, float afDesiredSleepEndTime)
        
        If GetOwningQuest().GetStage() == 30				 
          GetOwningQuest().SetStage(32)
EndIf
endevent 

Then do this with stages (again with your own stage numbers..):

Stage (30) Alias_Player.RegisterForSleep()
Stage (32) ReturnMarker.MoveTo(Game.GetPlayer(), 10)		
           Game.GetPlayer().MoveTo(DreamMarker)
Stage (35) Game.GetPlayer().MoveTo(ReturnMarker)

Yes I know it's a fairly simplistic approach, but why spend hours trying to peel potatoes when you have a bag of McCains in the freezer!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...