Sleep Script Help

Post » Thu Aug 07, 2014 2:21 am

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:


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. It compiles, but it doesn't work.

Scriptname SleepTestScriptDream extends ReferenceAlias  {Attach this script to a reference alias in your quest pointing to the player}ObjectReference Property XMarkerDreamStart AutoObjectReference Property XMarkerPlayerLoc AutoEvent 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)		UnregisterForSleep()                EnablePlayerControls()		GetOwningQuest().SetStage(20)		Debug.Notification("Dream ended.")			EndIf	EndEvent			

All properties are filled correctly.

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?

User avatar
Siobhan Thompson
 
Posts: 3443
Joined: Sun Nov 12, 2006 10:40 am

Post » Thu Aug 07, 2014 7:05 am

Your script is almost unreadable if you haven't noticed. Could you correct that? :)

Apart from that it looks like it should work. I presume you've filled the properties? Else you could perhaps try to replace OnSleepStart with OnSleepStop, except that would probably start the script too late.

User avatar
Robert Garcia
 
Posts: 3323
Joined: Thu Oct 11, 2007 5:26 pm

Post » Thu Aug 07, 2014 4:47 am

Sorry, when I copied and pasted it it looked alright, but evidently not anymore. I fixed it.

All of the properties are filled. Is there any reason OnSleepStart wouldn't work? It's what I would like to use.

User avatar
Maddy Paul
 
Posts: 3430
Joined: Wed Feb 14, 2007 4:20 pm

Post » Thu Aug 07, 2014 1:33 pm

Just remember to re-enable the player controls where needed. It wont "reset" itself.

User avatar
xemmybx
 
Posts: 3372
Joined: Thu Jun 22, 2006 2:01 pm

Post » Thu Aug 07, 2014 2:51 am

Oh, I did fix that. I just forgot to put the updated script, fixing that now.

Is this the best way to do the script, or is there a better way? Especially for putting the player back where they were. Is there a way where I can send them back where they were that's better than the method I'm currently using?

User avatar
Johnny
 
Posts: 3390
Joined: Fri Jul 06, 2007 11:32 am

Post » Thu Aug 07, 2014 1:04 pm

You can move them back but you can't move them back to the bed, as it is bugged for GetPlayer(). So you need to designate a safe point of return instead, using an xmarker.

There are other ways, but for your situation MoveTo is best. The other methods are for more complicating placement situations.

User avatar
lacy lake
 
Posts: 3450
Joined: Sun Dec 31, 2006 12:13 am

Post » Thu Aug 07, 2014 5:55 am

Alright then. Thank you.

EDIT: Okay, I got it working! The script ended up like this:

Scriptname SleepTestScriptDream extends ReferenceAlias  {Attach this script to a reference alias in your quest pointing to the player}ObjectReference Property XMarkerDreamStart AutoObjectReference Property XMarkerPlayerLoc AutoScene Property MyScene AutoEvent OnInit()	RegisterForSleep()	EndEventEvent OnSleepStart(Float afSleepStartTime, Float afDesiredSleepEndTime)	If GetOwningQuest().GetStage() == 10			XMarkerPlayerLoc.MoveTo(Game.GetPlayer(), 5)		Game.GetPlayer().MoveTo(XMarkerDreamStart)		Game.DisablePlayerControls(true, true, true, false, true, true, true, false)		MyScene.Start()		Game.GetPlayer().MoveTo(XMarkerPlayerLoc)		UnregisterForSleep()		Game.EnablePlayerControls()		GetOwningQuest().SetStage(20)			EndIf	EndEvent				

Thank you guys for your help.

User avatar
Blessed DIVA
 
Posts: 3408
Joined: Thu Jul 13, 2006 12:09 am


Return to V - Skyrim