Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Cipscis

Ambassadors
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Cipscis

  1. Don't forget we have actual states now, they can be really convenient. I've written a similar light switch script that uses states, that I put up on the wiki a while ago - Light Switch

    Cipscis

    EDIT:

    Here's the actual light switch script:

    ScriptName ManualLightSwitch extends ObjectReference
    
    {Controls a set of lights with a master enable parent
    
    marker (EnableMarker) and a switch with this script
    
    attached to turn on and off when the switch is activated}
    
    
    ObjectReference Property EnableMarker auto
    
    {The marker set as the enable parent of all the lights}
    
    
    Event OnInit()
    
    
    	If (EnableMarker.IsDisabled())
    
    		GoToState("LightsOff")
    
    	Else
    
    		GoToState("LightsOn")
    
    	EndIf
    
    
    EndEvent
    
    
    State LightsOff
    
    
    	Event OnBeginState()
    
    		Disable()
    
    	EndEvent
    
    
    	Event OnActivate(ObjectReference akActionRef)
    
    		GoToState("LightsOn")
    
    	EndEvent
    
    
    EndState
    
    
    State LightsOn
    
    
    	Event OnBeginState()
    
    		Enable()
    
    	EndEvent
    
    
    	Event OnActivate(ObjectReference akActionRef)
    
    		GoToState("LightsOff")
    
    	EndEvent
    
    
    EndState
    Also, an automatic variation that works on a timer:
    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
    
    
    	RegisterForSingleUpdateGameTime(GameTime - CurrentTime)
    
    
    EndFunction
    
    
    Event OnInit()
    
    
    	If (GetCurrentHourOfDay() > LightsOffTime)
    
    		GoToState("LightsOff")
    
    	Else
    
    		GoToState("LightsOn")
    
    	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

    Cipscis

×
×
  • Create New...