Jump to content

Problems with Papyrus Scripting


gamerdad5862

Recommended Posts

Having problems trying to get a script to work. New to modding, and especially to papyrus scripting. Trying to get this script to work:

 

Scriptname TimedLightSwitch extends ObjectReference

{Controls a set of lights with a master enable parent marker with this script attached to turn lights 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 the lights should turn off}

float Property LightsOnTime = 18.0 auto

{The time at which the lights should turn 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(string asOldState)

Disable()

RegisterForSingleUpdateGameTimeAt(LightsOnTime)

EndEvent

 

Event OnUpdateGameTime()

GoToState("LightsOn")

EndEvent

 

EndState

 

State LightsOn

 

Event OnBeginState(string asOldState)

Enable()

RegisterForSingleUpdateGameTimeAt(LightsOffTime)

EndEvent

 

Event OnUpdateGameTime()

GoToState("LightsOff")

EndEvent

 

EndState

 

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

I don't have time to look over the script carefully, but for anyone else here it is indented:

Scriptname TimedLightSwitch extends ObjectReference
{Controls a set of lights with a master enable parent marker with this script attached to turn lights 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 the lights should turn off}

float Property LightsOnTime = 18.0 auto
{The time at which the lights should turn 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(string asOldState)
        Disable()
        RegisterForSingleUpdateGameTimeAt(LightsOnTime)
    EndEvent

    Event OnUpdateGameTime()
        GoToState("LightsOn")
    EndEvent

EndState

State LightsOn

    Event OnBeginState(string asOldState)
        Enable()
        RegisterForSingleUpdateGameTimeAt(LightsOffTime)
    EndEvent

    Event OnUpdateGameTime()
        GoToState("LightsOff")
    EndEvent

EndState

Edit: Also this is not the correct forum, for next time you want the Fallout 4 Creation Kit and Modders forum.

 

Edit 2: I would suggest putting some debug notifications in there to see what is / isn't firing and what the functions are returning.

Edited by Reneer
Link to comment
Share on other sites

  • Recently Browsing   0 members

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