Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
Added potentially useful script from forum topic.
imported>Kotep
m (More readable image)
imported>JustinOther
(Added potentially useful script from forum topic.)
Line 703: Line 703:
EndEvent
EndEvent
</source>
</source>
= Enable/Disable an object on a schedule =
Given: You have a pedestal with a magical statue placed on it which is to enable at 6am every morning and disable at 6pm every evening. Glue the below to the pedestal which must always be enabled, filling the properties in the Creation Kit ensuring kYourObject is either renamed to match the EditorID of your statue upon auto-fill or manually pointed to it.
<source lang="papyrus">ScriptName YourScript Extends ObjectReference
Actor Property PlayerREF Auto ; <-- Imperative for expedience
Bool Property bEnableStuff Auto ; Leave as default or 'False'
Float Property fHourToDisable Auto ; Desired enable time
Float Property fHourToEnable Auto ; Desired enable time
Float Property fUpdateInterval Auto ; 15.0 works well
GlobalVariable Property GameHour Auto ; Pointed to engine maintained, special GlobalVariable
ObjectReference Property kYourObject Auto ; Pointed to your statue or object that is to enable
Event OnInit()
RegisterForSingleLOSGain(PlayerREF, Self)
bEnableStuff = !kYourObject.IsDisabled()
ToggleEnableStateIfApplicable()
EndEvent
Event OnGainLOS(Actor akViewer, ObjectReference akTarget)
RegisterForSingleLOSLost(PlayerREF, Self)
RegisterForSingleUpdate(fUpdateInterval)
ToggleEnableStateIfApplicable()
EndEvent
Event OnLostLOS(Actor akViewer, ObjectReference akTarget)
RegisterForSingleLOSGain(PlayerREF, Self)
UnregisterForUpdate()
ToggleEnableStateIfApplicable()
EndEvent
Event OnUpdate()
SnappyFunctionNameNotFound()
RegisterForSingleUpdate(fUpdateInterval)
EndEvent
Function ToggleEnableStateIfApplicable()
Float fTime = GameHour.GetValue()
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
bEnableStuff = !bEnableStuff
If bEnableStuff
kYourObject.Enable()
Else
kYourObject.Disable()
EndIf
EndIf
EndFunction</source>
If the statue is only to enable on Thursdays, add a check to the above like so:
<source lang="papyrus">Function ToggleEnableStateIfApplicable()
Float fTime = GameHour.GetValue()
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
bEnableStuff = !bEnableStuff
If bEnableStuff && GetDayOfWeek() == 5 ; Turdas
kYourObject.Enable()
Else
kYourObject.Disable()
EndIf
EndIf
EndFunction
Int Function GetDayOfWeek() Global ; ) ; 0 : Sundas :: 5 : Turdas, etc.
Return ((GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7
EndFunction</source>


{{Languages}}
{{Languages}}
[[Category: Papyrus]]
[[Category: Papyrus]]
Anonymous user

Navigation menu