Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname BALSController extends ObjectReference
- {Cipscis and M3rvin's Automatic Light Switch adapted for buildable lights.
- You need four marker objects for this script: three to act as described in the variable declaration comments, and a fourth that is permanently enabled and has this script attached to it.}
- float Property LightsOffTime = 6.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}
- ObjectReference Property MarkerLightsOn auto
- {The marker controlling the "lights on" object references}
- ObjectReference Property MarkerLightsOff auto
- {The marker controlling the "lights off" object references}
- ObjectReference Property BuildMarker auto
- {The marker that is enabled when the lights are "crafted"at a house workbench. Specifically, this is enabled by a script attached to the miscitem given by the house crafting recipe.}
- MiscObject Property CraftItem Auto
- {This targets the item the BALSCraftItem script is attached to so it may be removed from your inventory}
- 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
- RegisterForSingleUpdateGameTime(GameTime - CurrentTime)
- EndFunction
- Function LightsBuiltCheck()
- {Checks to see if BuildMarker object ref is enabled, and if it is, cycles between the "LightsOn"/"LightsOff" states. If it is disabled, it will go to the LightsNotBuilt State.}
- If (BuildMarker.IsEnabled())
- If (GetCurrentHourOfDay() > LightsOffTime)
- GoToState("LightsOff")
- Else
- GoToState("LightsOn")
- EndIf
- Else
- GoToState("LightsNotBuilt")
- EndIf
- EndFunction
- Event OnInit()
- LightsBuiltCheck()
- EndEvent
- State LightsOff
- Event OnBeginState()
- MarkerLightsOn.Disable(True)
- MarkerLightsOff.Enable(True)
- RegisterForSingleUpdateGameTimeAt(LightsOnTime)
- EndEvent
- Event OnUpdateGameTime()
- GoToState("LightsOn")
- EndEvent
- EndState
- State LightsOn
- Event OnBeginState()
- MarkerLightsOff.Disable(True)
- MarkerLightsOn.Enable(True)
- RegisterForSingleUpdateGameTimeAt(LightsOffTime)
- EndEvent
- Event OnUpdateGameTime()
- GoToState("LightsOff")
- EndEvent
- EndState
- State LightsNotBuilt
- Event OnBeginState()
- MarkerLightsOn.Disable(True)
- MarkerLightsOff.Disable(True)
- EndEvent
- EndState
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement