Jump to content

[LE] Script Help


Recommended Posts

I am using a script I found on the CK wiki to turn objects off and on at certain set times. For instance, turn campfire on at night at 1900 hrs and off at 0700; set up a breakfast and dinner table to activate and deactivate at certain times.

 

Now what I'm seeing is that these effects will not take effect until the 2nd cycle that player is in the cell. For instance, I have a breakfast and dinner set up to come on and go off at certain times. When I first enter the cell, both breakfast and dinner is on the table and will not go off until the next cycle comes around and, thereafter, will function properly. Obviously, I'd like it to work automatically and not have to wait for a whole cycle to pass before working properly. The clock on this cycle appears to begin once I enter the cell.

 

I do not know how to write scripts but maybe someone can help me out with setting this up properly? Help appreciated. Script below.

 

 

Scriptname EP_TimedDinnerSwitch extends ObjectReference
{Controls Objects with a master parent enable marker with script attached to turn off on certain time of day}

float Property LightsOffTime = 20.0 auto
{The time at which lights should be turned off}
float Property LightsOnTime = 19.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

 

 

Link to comment
Share on other sites

I had the same problem. I know the script and tried to use it for setting up two different place setting. It is called a time switch. I couldn't use it because it didn't always synchronize correctly. It does work well for outside lamps turn on and off auto.

We've traveled the same road then. It does work well for outdoor lighting and also for objects, such as lit fires coming on and going off at set time. Which is why I don't understand why it's not working for other objects such as dinner plates. It will work though, as long as you ignore the first 24 hours in the cell where everything is not working. After that, it seems to work fine.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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