enderalse/source/scripts/_00e_lockandunlockdoors.psc

65 lines
1.4 KiB
Plaintext

Scriptname _00E_LockAndUnlockDoors extends ObjectReference
float Property LockDoorsTime = 7.0 auto
{The time at which lights should be turned off}
float Property UnlockDoorsTime = 18.0 auto
{The time at which lights should be turned on}
float Function GetCurrentHourOfDay() global
{Returns the current time of day in hours since midnight}
float Time = Utility.GetCurrentGameTime()
Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit
Time *= 24 ; Convert from fraction of a day to number of hours
Return Time
EndFunction
Function RegisterForSingleUpdateGameTimeAt(float GameTime)
{Registers for a single UpdateGameTime event at the next occurrence
of the specified GameTime (in hours since midnight)}
float CurrentTime = GetCurrentHourOfDay()
If (GameTime < CurrentTime)
GameTime += 24
EndIf
RegisterForSingleUpdateGameTime(GameTime - CurrentTime)
EndFunction
Event OnInit()
If (GetCurrentHourOfDay() > LockDoorsTime)
GoToState("LightsOff")
Else
GoToState("LightsOn")
EndIf
EndEvent
State LightsOff
Event OnBeginState()
self.Lock()
RegisterForSingleUpdateGameTimeAt(UnlockDoorsTime)
EndEvent
Event OnUpdateGameTime()
GoToState("LightsOn")
EndEvent
EndState
State LightsOn
Event OnBeginState()
self.Lock(False)
RegisterForSingleUpdateGameTimeAt(LockDoorsTime)
EndEvent
Event OnUpdateGameTime()
GoToState("LightsOff")
EndEvent
EndState