Using Activated Object Reference

From the CreationKit Wiki
Jump to navigation Jump to search

Overview[edit | edit source]

Activated Object Reference is a very generic script, that enables users to implement two-state Objects in a fairly straight-forward manner without having to know much about how states work. The use of states can be pretty powerful but for the vast majority of scripts the User will only have to add basic functionality to an Object and this takes care of that generic pattern. Two-State Objects could be something thats turned ON/OFF, OPEN/CLOSED etc. The example below locks a door between specified times, this example has been derived from here because thats where the idea emerged.

Instructions[edit | edit source]

First you should copy the Activated Object Reference into the Skyrim\Data\Scripts folder.

Take a look at the file and read the comments.

Float Property fCheckActiveInterval Auto ; Desired Update check time/5.0 ex.
  • This property is how often the script is going to check the users conditions measured in real-time seconds.
;/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ OVERRIDE FUNCTIONS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/;

; Override Function - Is the Object Active?
Bool Function isObjectActive()
	return true
EndFunction

; Override Function - Is the Object InActive?
Bool Function isObjectInactive()
	return true
EndFunction

; Override Function - When Object becomes Active.
Function ObjectActive()
EndFunction

; Override Function - When Object becomes Inactive.
Function ObjectInactive()
EndFunction
  • The isObjectActive and isObjectInactive are the conditional functions you should override if you want to check something before the ObjectActive and ObjectInactive functions are called respectively. Return true when you want it to trigger the Object Active/Inactive functions, and false if you dont.
  • Ok next you need to provide your script that extends from the ActivatedObjectReference file. For this example we have a script that locks an object at a specified time. Copy the Timed Lock Example to your Skyrim/Data/Scripts/Source folder.
  • The following overrides the Conditionals to take into account day and time for the door Object to lock and unlock.
; Overrided Function.
Bool Function IsObjectActive()
		If (fDayOfWeek && fDayOfWeek != GetDayOfWeek())
			return false
		EndIf

		Float fTime = GameHour.GetValue()
		If (fHourClosed < fHourOpen)
			; Fix to take into account times over the 24-hour period.
			If (fTime <= fHourClosed || fTime >= fHourOpen) 
				return true
			EndIf
		Else
			If (fTime >= fHourOpen && fTime <= fHourClosed)
				return true
			EndIf
		EndIf
		return false
EndFunction

; Overrided Function.
Bool Function IsObjectInActive()
		Float fTime = GameHour.GetValue()
		If (fHourClosed < fHourOpen)
			; Fix to take into account times over the 24-hour period.
			If (fTime > fHourClosed && fTime < fHourOpen) 
				return true
			EndIf
		Else
			If (fTime < fHourOpen || fTime > fHourClosed)
				return true
			EndIf
		EndIf
		return false
EndFunction
  • The following overides the Active/Inactive function by locking and unlocking the door respectively and showing a message to the Users when a Line-Of-Sight and the Conditions hold true.
; Overrided Function.
Function ObjectActive()
	Debug.MessageBox(sDoorOpen)

	Self.Lock(TRUE, TRUE)
EndFunction

; Overrided Function.
Function ObjectInactive()
	Debug.MessageBox(sDoorClosed)

	Self.Lock(FALSE, TRUE)
EndFunction
  • Find the jlTimedLock3 in the Creation Kit, under the Main menus Gameplay >> Papyrus Script Manager, look for jlTimedLock.
  • Attach it to a door object you wish to use as an example. PapyrusScriptManagerTimedLock.jpg
  • Set the following Properties for the script.

TimedLock Properties.jpg

  • Save the Mod file and run and test in-game.