JustPaste.it

scriptName k747AutoDyndoLightSwitchScript extends ObjectReference
{Controls a set of lights with a master enable parent marker with this script attached to turn on and off at the times of the day specified by the properties LightsOffTime and LightsOnTime}

;-- Properties --------------------------------------
float property LightsOffTime = 7.00000 auto
{The time at which lights should be turned off}
float property LightsOnTime = 18.0000 auto
{The time at which lights should be turned on}

;-- Variables ---------------------------------------
ObjectReference MyMaster = None
;-- Functions ---------------------------------------

float function GetCurrentHourOfDay() global
{Returns the current time of day in hours since midnight}

float Time = utility.GetCurrentGameTime()
Time -= math.Floor(Time) as float
Time *= 24 as float
return Time
endFunction

; Skipped compiler generated GotoState

; Skipped compiler generated GetState

function OnInit()

if AutomaticLightSwitchScript.GetCurrentHourOfDay() > LightsOffTime
self.GotoState("LightsOff")
else
self.GotoState("LightsOn")
endIf
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 = AutomaticLightSwitchScript.GetCurrentHourOfDay()
if GameTime < CurrentTime
GameTime += 24 as float
endIf
self.RegisterForSingleUpdateGameTime(GameTime - CurrentTime)
endFunction

;-- State -------------------------------------------
state lightson

function OnBeginState()

self.Enable(false)
self.RegisterForSingleUpdateGameTimeAt(LightsOffTime)
endFunction

function OnUpdateGameTime()

self.GotoState("LightsOff")
endFunction
endState

;-- State -------------------------------------------
state lightsoff

function OnBeginState()

self.Disable(false)
self.RegisterForSingleUpdateGameTimeAt(LightsOnTime)
endFunction

function OnUpdateGameTime()

self.GotoState("LightsOn")
endFunction
endState

if (MyMaster == None) && (SKSE.GetScriptVersionRelease() >= 48) && (PapyrusUtil.GetVersion() >= 30)
MyMaster = Game.GetFormFromFile(JsonUtil.IntListGet("DynDOLOD_" + JsonUtil.GetStringValue("DynDOLOD_Worlds", StringUtil.Substring(Game.GetPlayer().GetWorldspace() as string, 13, StringUtil.Find(Game.GetPlayer().GetWorldspace() as string, "(") - 14), "None") as string, "master", 0), "DynDOLOD.esp") As ObjectReference
endIf
if (MyMaster != None) && (StorageUtil.GetIntValue(None, "DynDOLOD_Active", 0) == 1)
Utility.Wait(1)
(MyMaster as SHESON_DynDOLOD_Master).IBowToTheev2(StorageUtil.GetFormValue(MyMaster, "DynDOLOD_MyActiveFirstborn", None) As ObjectReference, (MyMaster as SHESON_DynDOLOD_Master).MyCurrentFirstbornList, (MyMaster as SHESON_DynDOLOD_Master).MyCurrentMinionList, TRUE, TRUE)
endIf