Jump to content

Toggle if a workshop item can be powered via script


cypher2012

Recommended Posts

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

You are looking for SetOpen() https://www.creationkit.com/fallout4/index.php?title=SetOpen_-_ObjectReference

Sounds 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

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.

 

DQ07vFdWkAAM423.jpg

Ah that's interesting.

 

Can I just straight up use pGameHour?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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