Created
December 5, 2014 05:00
-
-
Save Langerz82/bfe7ddf921b1ebc00ad4 to your computer and use it in GitHub Desktop.
This script can time ObjectReferences so the occur at certain hours of the day or at a certain day.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
+ This script can time ObjectReferences so the occur at certain hours of | |
+ the day or at a certain day. Override the ObjectActive and | |
+ ObjectInactive functions into order modify the ObjectReference when | |
+ the time period occurs. | |
+ | |
+ Hours Conversion: | |
+ 9.0 for 9:00 | |
+ 11.5 for 11:30 | |
+ 10.25 for 10:15 | |
+ 23.0 for 23:00 | |
+ | |
+ Days of Week conversion: | |
+ 0 - Sundas (Sunday) | |
+ 1 - Morndas | |
+ 2 - Tirdas | |
+ 3 - Middas | |
+ 4 - Turdas | |
+ 5 - Fredas | |
+ 6 - Loredas (Saturday) | |
+ | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/; | |
ScriptName TimedObjRef extends ObjectReference | |
Int Property fDayOfWeek Auto ; Desired day day/1.0 Morndas for example. | |
Float Property fHourToActive Auto ; Desired enable time/10.0 for example's sake | |
Float Property fHourToInactive Auto ; Desired disable time/11.0 for example's sake | |
Float Property fUpdateInterval Auto ; Desired Update check time/5.0 for example's sake | |
GlobalVariable Property GameHour Auto ; The Games Hour leave default. | |
; Object gets Toggled. | |
Function ObjectToggle() | |
EndFunction | |
; Override Function - Object becomes Active due to time. | |
Function ObjectActive() | |
EndFunction | |
; Override Function - Object becomes Inactive due to time. | |
Function ObjectInactive() | |
EndFunction | |
State Active | |
Event OnBeginState() | |
;Debug.Notification("TimedObjRef(state:Active,func:OnBeginState)") | |
ObjectActive() | |
EndEvent | |
Function ObjectToggle() | |
;Debug.Notification("TimedObjRef(state:Active,func:ObjectToggle)") | |
If (Self.isDisabled()) | |
return | |
EndIf | |
Float fTime = GameHour.GetValue() | |
If (fHourToInactive < fHourToActive) | |
; Fix to take into account times over the 24-hour period. | |
If (fTime > fHourToInactive && fTime < fHourToActive) | |
GoToState("Inactive") | |
EndIf | |
Else | |
If (fTime < fHourToActive || fTime > fHourToInactive) | |
GoToState("Inactive") | |
EndIf | |
EndIf | |
EndFunction | |
EndState | |
Auto State Inactive | |
Event OnBeginState() | |
;Debug.Notification("TimedObjRef(state:Inactive,func:OnBeginState)") | |
ObjectInactive() | |
EndEvent | |
Function ObjectToggle() | |
;Debug.Notification("TimedObjRef(state:Inactive,func:ObjectToggle)") | |
If (Self.isDisabled()) | |
return | |
EndIf | |
If (fDayOfWeek && fDayOfWeek != GetDayOfWeek()) | |
return | |
EndIf | |
Float fTime = GameHour.GetValue() | |
If (fHourToInactive < fHourToActive) | |
; Fix to take into account times over the 24-hour period. | |
If (fTime <= fHourToInactive || fTime >= fHourToActive) | |
GoToState("Active") | |
EndIf | |
Else | |
If (fTime >= fHourToActive && fTime <= fHourToInactive) | |
GoToState("Active") | |
EndIf | |
EndIf | |
EndFunction | |
EndState | |
Event OnUpdate() | |
;Debug.Notification("TimedObjRef - OnUpdate") | |
RegisterForSingleUpdate(fUpdateInterval) | |
ObjectToggle() | |
EndEvent | |
Event OnInit() | |
;Debug.Notification("TimedObjRef(func:OnInit)") | |
RegisterForSingleLOSGain(Game.GetPlayer(), Self) | |
ObjectToggle() | |
EndEvent | |
Event OnGainLOS(Actor akViewer, ObjectReference akTarget) | |
;Debug.Notification("TimedObjRef(func:OnGainLOS)") | |
RegisterForSingleLOSLost(Game.GetPlayer(), Self) | |
RegisterForSingleUpdate(fUpdateInterval) | |
ObjectToggle() | |
EndEvent | |
Event OnLostLOS(Actor akViewer, ObjectReference akTarget) | |
;Debug.Notification("TimedObjRef(func:OnLostLOS)") | |
RegisterForSingleLOSGain(Game.GetPlayer(), Self) | |
UnregisterForUpdate() ; Stop polling | |
EndEvent | |
; Get the day of the week. | |
Int Function GetDayOfWeek() | |
return ((Utility.GetCurrentGameTime() as Int) % 7) as Int | |
EndFunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment