Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2015
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. Scriptname BALSController extends ObjectReference
  2. {Cipscis and M3rvin's Automatic Light Switch adapted for buildable lights.
  3. 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.}
  4.  
  5. float Property LightsOffTime = 6.0 auto
  6. {The time at which lights should be turned off}
  7. float Property LightsOnTime = 18.0 auto
  8. {The time at which lights should be turned on}
  9. ObjectReference Property MarkerLightsOn auto
  10. {The marker controlling the "lights on" object references}
  11. ObjectReference Property MarkerLightsOff auto
  12. {The marker controlling the "lights off" object references}
  13. ObjectReference Property BuildMarker auto
  14. {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.}
  15. MiscObject Property CraftItem Auto
  16. {This targets the item the BALSCraftItem script is attached to so it may be removed from your inventory}
  17.  
  18. float Function GetCurrentHourOfDay() global
  19. {Returns the current time of day in hours since midnight}
  20.  
  21. float Time = Utility.GetCurrentGameTime()
  22. Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit
  23. Time *= 24 ; Convert from fraction of a day to number of hours
  24. Return Time
  25.  
  26. EndFunction
  27.  
  28. Function RegisterForSingleUpdateGameTimeAt(float GameTime)
  29. {Registers for a single UpdateGameTime event at the next occurrence
  30. of the specified GameTime (in hours since midnight)}
  31.  
  32. float CurrentTime = GetCurrentHourOfDay()
  33. If (GameTime < CurrentTime)
  34. GameTime += 24
  35. EndIf
  36.  
  37. RegisterForSingleUpdateGameTime(GameTime - CurrentTime)
  38.  
  39. EndFunction
  40.  
  41. Function LightsBuiltCheck()
  42. {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.}
  43.  
  44. If (BuildMarker.IsEnabled())
  45. If (GetCurrentHourOfDay() > LightsOffTime)
  46. GoToState("LightsOff")
  47. Else
  48. GoToState("LightsOn")
  49. EndIf
  50. Else
  51. GoToState("LightsNotBuilt")
  52. EndIf
  53.  
  54. EndFunction
  55.  
  56. Event OnInit()
  57.  
  58. LightsBuiltCheck()
  59.  
  60. EndEvent
  61.  
  62. State LightsOff
  63.  
  64. Event OnBeginState()
  65. MarkerLightsOn.Disable(True)
  66. MarkerLightsOff.Enable(True)
  67. RegisterForSingleUpdateGameTimeAt(LightsOnTime)
  68. EndEvent
  69.  
  70. Event OnUpdateGameTime()
  71. GoToState("LightsOn")
  72. EndEvent
  73.  
  74. EndState
  75.  
  76. State LightsOn
  77.  
  78. Event OnBeginState()
  79. MarkerLightsOff.Disable(True)
  80. MarkerLightsOn.Enable(True)
  81. RegisterForSingleUpdateGameTimeAt(LightsOffTime)
  82. EndEvent
  83.  
  84. Event OnUpdateGameTime()
  85. GoToState("LightsOff")
  86. EndEvent
  87.  
  88. EndState
  89.  
  90. State LightsNotBuilt
  91. Event OnBeginState()
  92. MarkerLightsOn.Disable(True)
  93. MarkerLightsOff.Disable(True)
  94. EndEvent
  95.  
  96. EndState
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement