Jump to content

MCM Tutorials?


Recommended Posts

Alrighty, had a shot at this, but it seems that something is wrong, it does not fire.

Scriptname ImmersiveContentLightMasterParent 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 = 6.0 auto
{The time at which lights should be turned off}
float Property LightsOnTime = 20.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 BadWeatherCheck()
  RegisterForSingleUpdate(30.0) ; Give us a single update in 30 second
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() > LightsOffTime)
		GoToState("LightsOff")
	Else
		GoToState("LightsOn")
	EndIf
 
EndEvent

Event OnUpdate()
;Checks for bad weather, only updates every 30 seconds to prevent savegame bloating.
	Bool bKeepUpdating = True
		If Weather.GetCurrentWeather().GetClassification() >= 2
			GoToState("LightsOn")
		Else
			GoToState("LightsOff")
		EndIf

	If bKeepUpdating
		RegisterForSingleUpdate(30.0)
	EndIf
EndEvent

State LightsOff
 
	Event OnBeginState()
		Disable()
		RegisterForSingleUpdateGameTimeAt(LightsOnTime)
	EndEvent
 
	Event OnUpdateGameTime()
		GoToState("LightsOn")
	EndEvent
 
EndState
 
State LightsOn
 
	Event OnBeginState()
		Enable()
		RegisterForSingleUpdateGameTimeAt(LightsOffTime)
	EndEvent
 
	Event OnUpdateGameTime()
		GoToState("LightsOff")
	EndEvent
 
EndState

maybe add a "bKeepUpdating = False" function in the LightsOn state so the script does not need poll when the lights are going to be on anyway.

Found to little info on the "bKeepUpdating", but i have gathered that it will stop the "OnUpdate" event from polling continously, but thats all i know about it. Using "bKeepUpdating = true" and "bKeepUpdating=false" in the same event creates errors.

 

I probably need to start using another thread for this, not exactly about MCM tutorials anymore.

Although it would be fancy to add a button in the MCM that can turn on and off the weather part of the script.

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...