cypher2012 Posted December 11, 2017 Share Posted December 11, 2017 Hey guys, I'm trying to create a work shop switch that turns on and off depending on the time of day. I've got the functionality that makes the script change state depending on what time it is. How to I make it so it stops transmitting power? Here is the code I have so far, which doesn't work: Scriptname SSS:SSS_SolarSwitch extends ObjectReference 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 Event OnTimer(int aiTimerID) StartTimer(10.0, 0) float fCurrentTime = GetCurrentHourOfDay() If (fCurrentTime > LightsOffTime && fCurrentTime < LightsOnTime) Debug.Notification(" Day time: " + fCurrentTime) GoToState("DayTimeState") Else Debug.Notification(" Night time: " + fCurrentTime) GoToState("NightTimeState") EndIf EndEvent Event OnInit() StartTimer(10.0, 0) If (GetCurrentHourOfDay() > LightsOffTime) GoToState("NightTimeState") Else GoToState("DayTimeState") EndIf EndEvent State NightTimeState Event OnBeginState(string sOldState) ActorValue PowerRadiation Self.ModValue(PowerRadiation, 500.0) Keyword WorkshopCanBePowered if(!HasKeyword(WorkshopCanBePowered)) Debug.MessageBox("Adding Keyword") AddKeyword(WorkshopCanBePowered) endif Debug.Notification("State changed to Lights on.") EndEvent EndState State DayTimeState Event OnBeginState(string sOldState) ActorValue PowerRadiation Self.ModValue(PowerRadiation, 0.0) Keyword WorkshopCanBePowered if(HasKeyword(WorkshopCanBePowered)) Debug.MessageBox("Removing Keyword") RemoveKeyword(WorkshopCanBePowered) endif Debug.Notification("State changed to Lights off.") EndEvent EndState Link to comment Share on other sites More sharing options...
deadbeeftffn Posted December 11, 2017 Share Posted December 11, 2017 You are looking for SetOpen() https://www.creationkit.com/fallout4/index.php?title=SetOpen_-_ObjectReferenceSounds strange but it works :nuke: Link to comment Share on other sites More sharing options...
cypher2012 Posted December 11, 2017 Author Share Posted December 11, 2017 You are looking for SetOpen() https://www.creationkit.com/fallout4/index.php?title=SetOpen_-_ObjectReferenceSounds strange but it works :nuke:Perfect. That was it! Thank you! Just had to change the Keywords so that they were correct also. Here is updated code: Scriptname SSS:SSS_SolarSwitch extends ObjectReference 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 Event OnTimer(int aiTimerID) StartTimer(10.0, 0) float fCurrentTime = GetCurrentHourOfDay() If (fCurrentTime > LightsOffTime && fCurrentTime < LightsOnTime) Debug.Notification(" Day time: " + fCurrentTime) GoToState("DayTimeState") Else Debug.Notification(" Night time: " + fCurrentTime) GoToState("NightTimeState") EndIf EndEvent Event OnInit() StartTimer(10.0, 0) If (GetCurrentHourOfDay() > LightsOffTime) GoToState("NightTimeState") Else GoToState("DayTimeState") EndIf EndEvent State NightTimeState Event OnBeginState(string sOldState) Self.SetOpen(false) Debug.Notification("State changed to Lights on.") EndEvent EndState State DayTimeState Event OnBeginState(string sOldState) Self.SetOpen(true) Debug.Notification("State changed to Lights off.") EndEvent EndState Link to comment Share on other sites More sharing options...
ThoraldGM Posted December 12, 2017 Share Posted December 12, 2017 I was looking up how to use PassTime and noticed several wiki pages casually mention GameHour in examples. It turns out that GameHour is actually a vanilla GlobalVariable in the CK. So to get hour all I'm doing is querying the value of that property. Link to comment Share on other sites More sharing options...
cypher2012 Posted December 13, 2017 Author Share Posted December 13, 2017 I was looking up how to use PassTime and noticed several wiki pages casually mention GameHour in examples. It turns out that GameHour is actually a vanilla GlobalVariable in the CK. So to get hour all I'm doing is querying the value of that property. Ah that's interesting. Can I just straight up use pGameHour? Link to comment Share on other sites More sharing options...
ThoraldGM Posted December 14, 2017 Share Posted December 14, 2017 I had to use Game.PassTime(MyDuration) for it to compile. I haven't tested yet. I have a (bad?) habit of doing long stretches of coding before checking in game. Edit: My CK prefixes a p onto properties auto filled from forms. Link to comment Share on other sites More sharing options...
Recommended Posts