Complete Example Scripts: Difference between revisions
Jump to navigation
Jump to search
→Enable/Disable an object on a schedule
imported>Terra Nova2 |
imported>Langerz82 |
||
| Line 765: | Line 765: | ||
Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc. | Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc. | ||
Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7 | Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7 | ||
EndFunction</source> | |||
= Enable/Disable Lock on object based on hours of day = | |||
Say you have a door or treasure chest you want to have a timed lock on it, here you can. You can also send a Message to the users when it Enables/Disables. Similar to above. You could use it for a template for a variety of things not just a lock Mechanism, however this is a straight-forward basic example. | |||
<source lang="papyrus">ScriptName jlTimedLock Extends ObjectReference | |||
Float Property fHourToEnable Auto ; Desired enable time/10.0 for example's sake | |||
Float Property fHourToDisable Auto ; Desired disable time/11.0 for example's sake | |||
String Property sEnabledMessage Auto ; Optional Message when enabled. | |||
String Property sDisabledMessage Auto ; Optional Message when disabled. | |||
Float Property fUpdateInterval Auto ; 15.0 works well and isn't too frantic. | |||
Actor Property PlayerREF Auto ; <-- Imperative for expedience | |||
GlobalVariable Property GameHour Auto ; Pointed to engine maintained, special GlobalVariable | |||
Bool bEnabled = false | |||
Event OnInit() | |||
RegisterForSingleLOSGain(PlayerREF, Self) | |||
EndEvent | |||
Event OnGainLOS(Actor akViewer, ObjectReference akTarget) | |||
;Debug.Notification("jlTimedLock - GainLOS") | |||
CheckTime() | |||
RegisterForSingleLOSLost(PlayerREF, Self) | |||
RegisterForSingleUpdate(fUpdateInterval) | |||
EndEvent | |||
Event OnLostLOS(Actor akViewer, ObjectReference akTarget) | |||
;Debug.Notification("jlTimedLock - LostLOS") | |||
CheckTime() | |||
RegisterForSingleLOSGain(PlayerREF, Self) | |||
UnregisterForUpdate() ; Stop polling | |||
EndEvent | |||
Event OnUpdate() | |||
CheckTime() | |||
RegisterForSingleUpdate(fUpdateInterval) | |||
EndEvent | |||
Function CheckTime(); | |||
Float fTime = GameHour.GetValue() | |||
;Debug.Notification("jlTimedLock - CheckTime: " + fTime) | |||
If (fHourToDisable < fHourToEnable) | |||
; Fix to take into account times over the 24-hour period. | |||
If ((fTime >= fHourToEnable && fTime <= 24) || (fTime >= 0 && fTime <= fHourToDisable)) | |||
If (!bEnabled) | |||
ObjectEnable() | |||
EndIf | |||
Else | |||
If (bEnabled) | |||
ObjectDisable() | |||
EndIf | |||
EndIf | |||
Else | |||
If (fTime >= fHourToEnable && fTime <= fHourToDisable) | |||
If (!bEnabled) | |||
ObjectEnable() | |||
EndIf | |||
Else | |||
If (bEnabled) | |||
ObjectDisable() | |||
EndIf | |||
EndIf | |||
EndIf | |||
EndFunction | |||
Function ObjectEnable() | |||
if (sEnabledMessage != "") | |||
Debug.MessageBox(sEnabledMessage) | |||
EndIf | |||
; Insert Custom Code. | |||
; Example - Timed Locking. | |||
Self.Lock(TRUE, TRUE) | |||
; End Custom Code. | |||
bEnabled = true | |||
EndFunction | |||
Function ObjectDisable() | |||
If (sDisabledMessage != "") | |||
Debug.MessageBox(sDisabledMessage) | |||
EndIf | |||
; Insert Custom Code. | |||
; Example - Timed Unlocking. | |||
Self.Lock(FALSE, TRUE) | |||
; End Custom Code. | |||
bEnabled = false | |||
EndFunction</source> | EndFunction</source> | ||