Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
imported>DarkWolfModding
imported>Langerz82
Line 772: Line 772:
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.
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
'''To make this work''':  Download and copy the [https://gist.github.com/Langerz82/bfe7ddf921b1ebc00ad4 TimedObjRef.psc] file to your Skyrim/Data folder.
The following is an example of the script in action.
 
<source lang="papyrus">ScriptName jlTimedLock2 extends TimedObjRef


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 sEnabledMessage Auto ; Optional Message when enabled.
String Property sDisabledMessage Auto ; Optional Message when disabled.
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()
; Override the original function
Function ObjectActive()
if (sEnabledMessage != "")
if (sEnabledMessage != "")
Debug.MessageBox(sEnabledMessage)
Debug.MessageBox(sEnabledMessage)
Line 845: Line 792:
; End Custom Code.
; End Custom Code.


bEnabled = true
EndFunction
EndFunction


Function ObjectDisable()
; Override the original function
Function ObjectInactive()
If (sDisabledMessage != "")
If (sDisabledMessage != "")
Debug.MessageBox(sDisabledMessage)
Debug.MessageBox(sDisabledMessage)
Line 857: Line 804:
Self.Lock(FALSE, TRUE)
Self.Lock(FALSE, TRUE)
; End Custom Code.
; End Custom Code.
 
EndFunction
bEnabled = false
</source>
EndFunction</source>


= Adding a spell when you shout =
= Adding a spell when you shout =
Anonymous user

Navigation menu