Citizenbari Posted March 6, 2020 Share Posted March 6, 2020 Hi, i need help... The following script from creationkit.com does not work (compile) for Fallout 4. I think it is caused by the "RegisterForSingleUpdateGameTimeAt" functionthat is not compatible with Fallout 4. I have no scripting experience, only know how to attach them, add properties and undertsand little bit how they work, but cant script by myself.If someone knows how this script should look like or has an funtioning script that turns lights on/off depending on ingame time i would be very very happy!!!! ScriptName TimedLightSwitch extends ObjectReference{Controls a set of lights with a master enable parent marker with thisscript attached to turn on and off at the times of the day specifiedby the properties LightsOffTime and LightsOnTime} float Property LightsOffTime = 7.0 auto{The time at which lights should be turned off}float Property LightsOnTime = 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 occurrenceof the specified GameTime (in hours since midnight)} float CurrentTime = GetCurrentHourOfDay() If (GameTime < CurrentTime) GameTime += 24 EndIf RegisterForSingleUpdateGameTime(GameTime - CurrentTime) EndFunction Event OnInit() If (ShouldLightsBeOff()) GoToState("LightsOff") Else GoToState("LightsOn") EndIf EndEvent State LightsOff Event OnBeginState() Disable() RegisterForSingleUpdateGameTimeAt(LightsOnTime) EndEvent Event OnUpdateGameTime() If (ShouldLightsBeOff()) RegisterForSingleUpdateGameTimeAt(LightsOnTime) Else GoToState("LightsOn") EndIf EndEvent EndState State LightsOn Event OnBeginState() Enable() RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndEvent Event OnUpdateGameTime() If (ShouldLightsBeOff()) GoToState("LightsOff") Else RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndIf EndEvent EndState bool Function ShouldLightsBeOff(){Validate the light state based on current time of day} float CurrentTime = GetCurrentHourOfDay() If (CurrentTime >= LightsOffTime) && (CurrentTime < LightsOnTime) return true Else return false EndIf EndFunction Link to comment Share on other sites More sharing options...
DieFeM Posted March 6, 2020 Share Posted March 6, 2020 Try this one, I didn't tested it, but it compiles. ScriptName TimedLightSwitch 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} float Property LightsOffTime = 7.0 auto {The time at which lights should be turned off} float Property LightsOnTime = 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 StartTimerGameTime(GameTime - CurrentTime) EndFunction Event OnInit() If (ShouldLightsBeOff()) GoToState("LightsOff") Else GoToState("LightsOn") EndIf EndEvent State LightsOff Event OnBeginState(string asOldState) Disable() RegisterForSingleUpdateGameTimeAt(LightsOnTime) EndEvent Event OnTimerGameTime(int aiTimerID) If (ShouldLightsBeOff()) RegisterForSingleUpdateGameTimeAt(LightsOnTime) Else GoToState("LightsOn") EndIf EndEvent EndState State LightsOn Event OnBeginState(string asOldState) Enable() RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndEvent Event OnTimerGameTime(int aiTimerID) If (ShouldLightsBeOff()) GoToState("LightsOff") Else RegisterForSingleUpdateGameTimeAt(LightsOffTime) EndIf EndEvent EndState bool Function ShouldLightsBeOff() {Validate the light state based on current time of day} float CurrentTime = GetCurrentHourOfDay() If (CurrentTime >= LightsOffTime) && (CurrentTime < LightsOnTime) return true Else return false EndIf EndFunction Link to comment Share on other sites More sharing options...
Citizenbari Posted March 6, 2020 Author Share Posted March 6, 2020 I test it and give you feedback!! Link to comment Share on other sites More sharing options...
Citizenbari Posted March 6, 2020 Author Share Posted March 6, 2020 So i tested that script and it seems to function :dance: :dance: :dance:Only be careful when using (for testing...) "set gamehour to" this will break/irritate the script and causes CTD when loading another savegame again. @DieFeM thank you really for your help here, it helped me really a lot on realizing my new mod i am currently working on :smile: !!!!I will do a longtime test, but dont think that any serious things will happen (hopefully), if so i will report them! Link to comment Share on other sites More sharing options...
DieFeM Posted March 6, 2020 Share Posted March 6, 2020 Use passtime instead of set gamehour to.Example (wait 12 hours):passtime 12 Link to comment Share on other sites More sharing options...
Citizenbari Posted March 6, 2020 Author Share Posted March 6, 2020 Ok, i test with passtime! Link to comment Share on other sites More sharing options...
Recommended Posts