Difference between revisions of "Complete Example Scripts"
imported>Evernewjoy |
imported>Cipscis (Tried to make the first section a bit clearer, and added titles to the section containing actual examples) |
||
Line 1: | Line 1: | ||
==Complete Example Scripts== | |||
== | ===Script Instantiation=== | ||
Please remember that few example scripts will be complete by themselves, attach a script to an object in the Creation Kit before it will run. The exception is for "library" scripts, such as the [[Utility Script]], which contain definitions of global functions for use in other scripts. | |||
===Property Setting=== | |||
And if the script has any properties, those properties must be set on the object to which the script is attached in the Creation Kit before the script will work correctly. | |||
===Script Name=== | |||
If you use any of these example scripts, you can change the name to anything else, but if you're creating the file outside of the Creation Kit you must make sure it also matches the name of your file. | |||
==Scripts== | |||
===A Trigger To Activate When Player Walks Through It=== | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname ExampleTrigger extends ObjectReference | Scriptname ExampleTrigger extends ObjectReference | ||
Line 43: | Line 34: | ||
</source> | </source> | ||
====To Make This Script Work==== | |||
Select an existing object in your cell | Select an existing object in your cell | ||
Line 60: | Line 51: | ||
* Then go in-game and walk into the space where this invisible box is. | * Then go in-game and walk into the space where this invisible box is. | ||
====Uses:==== | |||
* Create events that depend on player positioning | * Create events that depend on player positioning | ||
Line 70: | Line 60: | ||
===A Fully Functional Dwemer Button=== | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname DwemerButtonExampleScript extends ObjectReference | Scriptname DwemerButtonExampleScript extends ObjectReference | ||
Line 112: | Line 99: | ||
</source> | </source> | ||
====To Make This Script Work==== | |||
* You must create this script on a Activator object, probably a dwemer button :) | * You must create this script on a Activator object, probably a dwemer button :) |
Revision as of 06:37, 14 February 2012
Complete Example Scripts
Script Instantiation
Please remember that few example scripts will be complete by themselves, attach a script to an object in the Creation Kit before it will run. The exception is for "library" scripts, such as the Utility Script, which contain definitions of global functions for use in other scripts.
Property Setting
And if the script has any properties, those properties must be set on the object to which the script is attached in the Creation Kit before the script will work correctly.
Script Name
If you use any of these example scripts, you can change the name to anything else, but if you're creating the file outside of the Creation Kit you must make sure it also matches the name of your file.
Scripts
A Trigger To Activate When Player Walks Through It
Scriptname ExampleTrigger extends ObjectReference
Event onTriggerEnter(ObjectReference ObjRef)
;remove this if statement if you want
;other objects to activate the trigger
;also
if(ObjRef == game.getplayer())
Debug.MessageBox("Yippee!")
endif
endEvent
To Make This Script Work
Select an existing object in your cell
Click on the Trigger Volume button, the box with a T inside of it.
- A orange box should appear around the object you selected.
One reason the Creation Kit is more awesome than any prior editor I've used is this feature!
If you know you need a large trigger volume, select a large object before pressing the T-box button!
- Now edit the new orange box you created and add the script above.
- Then go in-game and walk into the space where this invisible box is.
Uses:
- Create events that depend on player positioning
- You could eliminate the player if statement above and have other actors like draugr or companions activate things as well
- Non-player triggers can be used by changing the == to a != in the script above, to do things to other actors like restoring their health or moving them around (but not affecting player if player walks through the trigger)
A Fully Functional Dwemer Button
Scriptname DwemerButtonExampleScript extends ObjectReference
objectReference property objSelf auto hidden
sound property QSTAstrolabeButtonPressX auto
;==================
;this event runs when cell is loaded containing
;this scripted object
event onCellAttach()
objSelf = self as objectReference
playAnimation("Open")
endEvent
;==================
EVENT onActivate (objectReference triggerRef)
if(triggerRef == game.getplayer())
;--- sound and animation
playAnimationAndWait("Trigger01","done")
if QSTAstrolabeButtonPressX
QSTAstrolabeButtonPressX.play(objSelf)
endif
;actual code for what button should do
Debug.MessageBox("Joy!")
endif
endEVENT
To Make This Script Work
- You must create this script on a Activator object, probably a dwemer button :)
- You must then set the property for the QST sound effect property, the sound file has the same name as the property in the script above.
To make your own dwemer button and avoid messing with the original Skyrim scripts/activators:
- Extract the dwemer button .nif file from the Meshes.bsa and create a new activator using that .nif file (picking the mesh to use is an option in the activator edit window).
- You must put your extracted .nif file in the skyrim/Data/meshes directory structure if you want the Creation Kit to be able to find and use it.
To extract files from the Skyirm .BSA files you must download something like the Fallout3 Archive Utility, do a google search for this.