Jump to content

Scripting: get number of hours spent sleeping?


Mansh00ter

Recommended Posts

So I need to get the number of hours player has spent sleeping and have run into a problem:

 

OnSleepStop event doesn't return anything like that. OnSleepStart event returns floats which are basically unreadable (you get something like 0.486658 representing the full date and game time). If I knew how these were constructed I could calculate at least the number of hours the player wanted to sleep. But I don't even know where to look.

I hoped that the existing script responsible for giving rested bonuses would have a timer of some sorts, but it doesn't (and yeah, you can get a well rested bonus for one hour of sleeping, funny).

 

So anyone has any idea how to tackle this? Is there a direct means of getting the number of hours spent sleeping?

And are there any string operations for Papyrus, like substring or string to number? Then I could use substring to extract the data from the Utility.GameTimeToString return result, turn that back into number format and do calculations with that.

 

Cause without a reliable way to get the number of hours spent sleeping, there is no way to do a proper Sleep component of basic needs... and since those worked just fine in older games I am assuming I simply am missing something. So... heeeeeeelp!

Link to comment
Share on other sites

Heh, just figured that one out while poking around the CK Wiki - it works just fine.

 

So if anyone has the same problem, what you do is RegisterForSleep() in your script, then use Game.QueryStat("Hours Slept") to get the number of hours slept, both on the OnSleepStart and OnSleepStop events. The difference between the two is the number of hours spent sleeping. Works like a charm. :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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