Jump to content

Trying to reset a global variable when the player wakes up


macrophage001

Recommended Posts

I'm currently working on a mod that requires the player to sleep for a set amount of time, which resets some variables when the player wakes up. I'm having a hard time figuring out how to track the player sleeping though and was wondering if someone could help me out? Here is my script code which i "procured" some of from Gopher's Pumping Iron mod. It does exactly what I need but for some reason I can't seem to apply it to my mod:

Scriptname hw_SleepTrackerScript extends Quest

GlobalVariable Property hw_MaxExhaustionPoints Auto
GlobalVariable Property hw_ExhaustionPoints Auto
GlobalVariable Property hw_SleptCounter Auto

Float lastSlept
Float sleepTime
Float maxSleepHours = 8.0000
Float minTimeBetweenSleep = 0.5000

Float minTimesSlept = 7.0000

EVENT OnInit()
	RegisterForSleep()
ENDEVENT

EVENT OnSleepStart(Float afSleepStartTime, Float afDesiredSleepTime)
	If afSleepStartTime - lastSlept > minTimeBetweenSleep
		sleepTime = afDesiredSleepTime - afSleepStartTime
	Else
		sleepTime = 0.0000
	EndIf
ENDEVENT

EVENT OnSleepStop(Bool abInterrupted)
	lastSlept = Utility.GetCurrentGameTime()

	if sleepTime >= maxSleepHours / 24 as Float
		hw_ExhaustionPoints.SetValue(0)

		if hw_SleptCounter.GetValue() == minTimesSlept
			hw_MaxExhaustionPoints.Mod(1)
			hw_SleptCounter.SetValue(0)
		else
			hw_SleptCounter.Mod(1)
		endif
	EndIf
ENDEVENT

Any help would be greatly appreciated. Thank you!

Edited by macrophage001
Link to comment
Share on other sites

  • 4 weeks later...
  • Recently Browsing   0 members

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