Complete Example Scripts: Difference between revisions
Jump to navigation
Jump to search
m
Formatting so that people can link to individual scripts better from other articles.
imported>JustinOther m (→Cycle Through a List of Objects and Perform an Action on Each Object(Linked Ref Chain): Wups. Wasn't extraneous.) |
imported>David Brasher m (Formatting so that people can link to individual scripts better from other articles.) |
||
| Line 1: | Line 1: | ||
=Complete Example Scripts= | |||
==Script Instantiation== | |||
Please remember that few example scripts will be complete by themselves, you must 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. | Please remember that few example scripts will be complete by themselves, you must 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. | 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. | 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= | |||
==Creating a Simple Toggle== | |||
<source lang="papyrus">ScriptName SimpleToggle Extends ObjectReference | <source lang="papyrus">ScriptName SimpleToggle Extends ObjectReference | ||
| Line 34: | Line 34: | ||
'''To make this script work''': Attach this script to an activator such as a button, lever, or container. | '''To make this script work''': Attach this script to an activator such as a button, lever, or container. | ||
==A Quest item you can drop and pick up again and set or reset objectives and Stages.== | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
| Line 86: | Line 86: | ||
ObjectiveToHideOnDrop: 20 | ObjectiveToHideOnDrop: 20 | ||
==A Trigger That Detects When The Player Enters== | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname ExampleTrigger extends ObjectReference | Scriptname ExampleTrigger extends ObjectReference | ||
| Line 123: | Line 123: | ||
* 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) | * 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) | ||
==Cycle Through a List of Objects and Perform an Action on Each Object(FormLists)== | |||
This example script cycles through a List of objects, known as a [[Formlist]], and enables them all if they are disabled, and disables them if they are enabled, each time the player character walks through a chosen trigger volume. | This example script cycles through a List of objects, known as a [[Formlist]], and enables them all if they are disabled, and disables them if they are enabled, each time the player character walks through a chosen trigger volume. | ||
If you use a [[Formlist]] of special effects, this would cause all the many special effects you have in the formlist to disappear or reappear each time you walk through the trigger volume. | If you use a [[Formlist]] of special effects, this would cause all the many special effects you have in the formlist to disappear or reappear each time you walk through the trigger volume. | ||
| Line 166: | Line 166: | ||
Enjoy! | Enjoy! | ||
== Cycle Through a List of Objects and Perform an Action on Each Object(Linked Ref Chain) == | |||
This script will cycle through all the references in a linked ref chain and perform an action on each of them. In this example, the action would be to move each reference up by 16 units when you activate any one of them. Basically, it's the same thing as the FormList version, except you create a linked ref chain instead of a FormList. | This script will cycle through all the references in a linked ref chain and perform an action on each of them. In this example, the action would be to move each reference up by 16 units when you activate any one of them. Basically, it's the same thing as the FormList version, except you create a linked ref chain instead of a FormList. | ||
| Line 195: | Line 195: | ||
** If your linked ref chain links back to itself, then you could put this script on each of the objects | ** If your linked ref chain links back to itself, then you could put this script on each of the objects | ||
==Move an Object to a Specific Location Without Fade== | |||
You can use this script to make an activator or actor move without fading out in any way (moveTo and setPosition cause fading to occur). | You can use this script to make an activator or actor move without fading out in any way (moveTo and setPosition cause fading to occur). | ||
| Line 242: | Line 242: | ||
Get used to these basics and you will find Papyrus much more powerful than prior scripting languages. | Get used to these basics and you will find Papyrus much more powerful than prior scripting languages. | ||
==A Fully Functional Dwemer Button== | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname DwemerButtonExampleScript extends ObjectReference | Scriptname DwemerButtonExampleScript extends ObjectReference | ||
| Line 297: | Line 297: | ||
==Set Quest Stage When Picked Up By Player== | |||
<source lang="papyrus">ScriptName SetStageOnPlayerPickUp extends ObjectReference | <source lang="papyrus">ScriptName SetStageOnPlayerPickUp extends ObjectReference | ||
| Line 318: | Line 318: | ||
==Good Usage of Properties to Make Scripts Compact== | |||
In this example you can see how to use a simple script property to reduce the number of scripts you need to write and thus the amount of properties you need to set, which can be time-consuming. | In this example you can see how to use a simple script property to reduce the number of scripts you need to write and thus the amount of properties you need to set, which can be time-consuming. | ||
| Line 430: | Line 430: | ||
* Then you will need to chose for each instance of the script whether the boolean property should be false or true, this setting process shows up a simple checkmark box in the editor | * Then you will need to chose for each instance of the script whether the boolean property should be false or true, this setting process shows up a simple checkmark box in the editor | ||
== A helper script with functions to get the current moonphase, sync between the two moons and day of the week == | |||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname ExtendedUtility | Scriptname ExtendedUtility | ||
| Line 586: | Line 586: | ||
*Call it's functions in other scripts either by import and call by function name or by using ExtendedUtility.<FunctionName>() | *Call it's functions in other scripts either by import and call by function name or by using ExtendedUtility.<FunctionName>() | ||
== Script to make an item cast a spell == | |||
<Source lang="Papyrus"> | <Source lang="Papyrus"> | ||
| Line 671: | Line 671: | ||
== Script for a quest with time limit == | |||
<Source lang="Papyrus"> | <Source lang="Papyrus"> | ||
| Line 715: | Line 715: | ||
==Making a Cool Cut-Scene== | |||
<Source lang="Papyrus"> | <Source lang="Papyrus"> | ||
| Line 749: | Line 749: | ||
== Script a container that only accepts certain types of items == | |||
'''How to use this script''': Fill the FormList, AcceptedItemFLST, with only the item(s) you want the container to accept. | '''How to use this script''': Fill the FormList, AcceptedItemFLST, with only the item(s) you want the container to accept. | ||
<Source lang="Papyrus"> | <Source lang="Papyrus"> | ||