Open main menu
Home
Random
Log in
Settings
About the CreationKit Wiki
Disclaimers
the CreationKit Wiki
Search
Editing
Complete Example Scripts
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Enable/Disable an object on a schedule = Say 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. If the pedestal is not applicable, use an L_LOS collision marker. <syntaxhighlight 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/18.0 for example's sake Float Property fHourToEnable Auto ; Desired enable time/6.0 for example's sake Float Property fUpdateInterval Auto ; 15.0 works well and isn't too frantic. 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() ; Stop polling ToggleEnableStateIfApplicable() EndEvent Event OnUpdate() ToggleEnableStateIfApplicable() 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</syntaxhighlight> If the statue is only to enable on Thursdays, add a check to the above like so: <syntaxhighlight lang="papyrus">Function ToggleEnableStateIfApplicable() Float fTime = GameHour.GetValue() If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable) bEnableStuff = GetDayOfWeek() == 5 ; Turdas If bEnableStuff kYourObject.Enable() Else kYourObject.Disable() EndIf EndIf EndFunction Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc. Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7 EndFunction</syntaxhighlight>
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)