Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
m
Convert source tags to syntaxhighlight
imported>Rasikko
(Undo revision 51939 by Quindraco (talk) - Not syntactically correct.)
m (Convert source tags to syntaxhighlight)
Line 18: Line 18:
=Creating a Simple Toggle=
=Creating a Simple Toggle=


<source lang="papyrus">ScriptName SimpleToggle Extends ObjectReference
<syntaxhighlight lang="papyrus">ScriptName SimpleToggle Extends ObjectReference


Bool bToggle
Bool bToggle
Line 29: Line 29:
; Undo stuff
; Undo stuff
Endif
Endif
EndEvent</source>
EndEvent</syntaxhighlight>


'''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.
Line 35: Line 35:
=A Quest item you can drop and pick up again and set or reset objectives and Stages.=
=A Quest item you can drop and pick up again and set or reset objectives and Stages.=


<source lang="papyrus">
<syntaxhighlight lang="papyrus">
ScriptName DroppableQuestObject Extends ObjectReference
ScriptName DroppableQuestObject Extends ObjectReference


Line 71: Line 71:
Int Property ObjectiveToHideOnDrop  = -1 Auto ; Should be the same as ObjectiveToDisplayOnPickup, ideally.
Int Property ObjectiveToHideOnDrop  = -1 Auto ; Should be the same as ObjectiveToDisplayOnPickup, ideally.


</source>
</syntaxhighlight>


To use this script: attach it to the item you want to use, and set the properties accordingly, assigning the quest, Objectives, and Stages involved. For example, let's say that in the quest "StarsAndGarters", the garter belt of Wootazootamootagoota The Tense is set in stage 10 as Objective 10, and Displays Objective 20 "Place the belt on the statue", and sets stage 20 when picked up, and you want to go back to stage 10 if the player drops it. And after stage 30 (Player has put the belt on the statue) it no longer matters what happens to it. You would set your properties as follows:
To use this script: attach it to the item you want to use, and set the properties accordingly, assigning the quest, Objectives, and Stages involved. For example, let's say that in the quest "StarsAndGarters", the garter belt of Wootazootamootagoota The Tense is set in stage 10 as Objective 10, and Displays Objective 20 "Place the belt on the statue", and sets stage 20 when picked up, and you want to go back to stage 10 if the player drops it. And after stage 30 (Player has put the belt on the statue) it no longer matters what happens to it. You would set your properties as follows:
Line 86: Line 86:


=A Trigger That Detects When The Player Enters=
=A Trigger That Detects When The Player Enters=
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
ScriptName ExampleTrigger Extends ObjectReference
ScriptName ExampleTrigger Extends ObjectReference


Line 97: Line 97:
EndEvent
EndEvent


</source>
</syntaxhighlight>


'''To Make This Script Work'''
'''To Make This Script Work'''
Line 122: Line 122:
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.
<source lang="papyrus">ScriptName RamaFormListExampleScript extends ObjectReference
<syntaxhighlight lang="papyrus">ScriptName RamaFormListExampleScript extends ObjectReference


Actor Property PlayerREF Auto ; Least 'expensive' way to refer to the player
Actor Property PlayerREF Auto ; Least 'expensive' way to refer to the player
Line 140: Line 140:
EndWhile
EndWhile
EndIf
EndIf
EndEvent</source>
EndEvent</syntaxhighlight>
'''To Make This Script Work'''
'''To Make This Script Work'''
* This script runs on a OnTriggerEnter event, so you must create a trigger volume. See the [[Complete_Example_Scripts#A_Trigger_That_Detects_When_The_Player_Enters|script example above]] for details on this.
* This script runs on a OnTriggerEnter event, so you must create a trigger volume. See the [[Complete_Example_Scripts#A_Trigger_That_Detects_When_The_Player_Enters|script example above]] for details on this.
Line 164: Line 164:
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.


<source lang="papyrus">ScriptName LinkRefChainExample Extends ObjectReference
<syntaxhighlight lang="papyrus">ScriptName LinkRefChainExample Extends ObjectReference


Actor Property PlayerREF Auto ; Most efficient way to refer to the player
Actor Property PlayerREF Auto ; Most efficient way to refer to the player
Line 181: Line 181:
Function PerformActionOn(ObjectReference Target)
Function PerformActionOn(ObjectReference Target)
Target.MoveTo(Target, 0, 0, 16)
Target.MoveTo(Target, 0, 0, 16)
EndFunction</source>
EndFunction</syntaxhighlight>


'''To Make This Script Work'''
'''To Make This Script Work'''
Line 199: Line 199:
* To move something other than player, add a property of type ObjectReference and set it to the actor or activator that you want to move (I have not succeeded in moving statics, only activators and actors)
* To move something other than player, add a property of type ObjectReference and set it to the actor or activator that you want to move (I have not succeeded in moving statics, only activators and actors)
* Use different Events freely, this event is used for simplicity and easy demonstration.
* Use different Events freely, this event is used for simplicity and easy demonstration.
<source lang="papyrus">ScriptName MoveObjExample extends ObjectReference   
<syntaxhighlight lang="papyrus">ScriptName MoveObjExample extends ObjectReference   


Actor Property PlayerREF Auto
Actor Property PlayerREF Auto
Line 208: Line 208:
akActionRef.TranslateToRef(kDest, 500.0) ; 500 is the speed value, it's pretty fast
akActionRef.TranslateToRef(kDest, 500.0) ; 500 is the speed value, it's pretty fast
EndIf
EndIf
EndEvent </source>
EndEvent </syntaxhighlight>


'''To Make This Script Work'''
'''To Make This Script Work'''
Line 219: Line 219:


=A Fully Functional Dwemer Button=
=A Fully Functional Dwemer Button=
<source lang="papyrus">Scriptname DwemerButtonExampleScript extends ObjectReference   
<syntaxhighlight lang="papyrus">Scriptname DwemerButtonExampleScript extends ObjectReference   


Actor Property PlayerREF Auto
Actor Property PlayerREF Auto
Line 236: Line 236:
        Debug.MessageBox("Joy!") ; actual code for what button should do
        Debug.MessageBox("Joy!") ; actual code for what button should do
EndIf
EndIf
EndEvent</source>
EndEvent</syntaxhighlight>


'''To Make This Script Work'''
'''To Make This Script Work'''
Line 248: Line 248:


=Set Quest Stage When Picked Up By Player=
=Set Quest Stage When Picked Up By Player=
<source lang="papyrus">ScriptName SetStageOnPlayerPickUp Extends ObjectReference
<syntaxhighlight lang="papyrus">ScriptName SetStageOnPlayerPickUp Extends ObjectReference


Actor Property PlayerREF Auto
Actor Property PlayerREF Auto
Line 263: Line 263:
State Taken
State Taken
; Do nothing
; Do nothing
EndState</source>
EndState</syntaxhighlight>


=Usage of Arrays to Make Scripts Compact=
=Usage of Arrays to Make Scripts Compact=
Line 270: Line 270:
* turn their AI off and make them invisible
* turn their AI off and make them invisible
I have different conditions within my level for when each of these two actions should occur. I could divide this into two scripts, but instead I wrote one script and passed a property to the script with each instance of the script to determine which aspect of the script would run.
I have different conditions within my level for when each of these two actions should occur. I could divide this into two scripts, but instead I wrote one script and passed a property to the script with each instance of the script to determine which aspect of the script would run.
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Actor Property PlayerREF Auto
Actor Property PlayerREF Auto
Actor[] Property DraugrArray Auto ; Contains 30 elements filled in CK with the 30 Draugr
Actor[] Property DraugrArray Auto ; Contains 30 elements filled in CK with the 30 Draugr
Line 285: Line 285:
EndWhile
EndWhile
EndIf
EndIf
EndEvent</source>
EndEvent</syntaxhighlight>
Note that bEnableBeasts is a property so one can decide with each instance which way the script should work. One could use a FormList rather than an array or simply set one Draugr as the enable parent of the other 29 and enable/disable him, and thus all the children refs simultaneously.
Note that bEnableBeasts is a property so one can decide with each instance which way the script should work. One could use a FormList rather than an array or simply set one Draugr as the enable parent of the other 29 and enable/disable him, and thus all the children refs simultaneously.


Line 293: Line 293:


= A helper script with functions to get the current moonphase, sync between the two moons and day of the week =
= A helper script with functions to get the current moonphase, sync between the two moons and day of the week =
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Scriptname ExtendedUtility
Scriptname ExtendedUtility


Line 433: Line 433:
EndFunction
EndFunction


</source>
</syntaxhighlight>


'''How to make this script work'''
'''How to make this script work'''
Line 676: Line 676:
This is used for the Player to feed his animal companion.  The FormList is created in the CK and includes all the food (Potion & Ingredient) items I want to consider food for the animal.
This is used for the Player to feed his animal companion.  The FormList is created in the CK and includes all the food (Potion & Ingredient) items I want to consider food for the animal.


<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Actor Property PlayerREF Auto
Actor Property PlayerREF Auto
FormList Property FoodList Auto
FormList Property FoodList Auto
Line 695: Line 695:
EndIf
EndIf
EndEvent
EndEvent
</source>
</syntaxhighlight>


= Enable/Disable an object on a schedule =
= Enable/Disable an object on a schedule =
Line 701: Line 701:
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.
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.


<source lang="papyrus">ScriptName YourScript Extends ObjectReference
<syntaxhighlight lang="papyrus">ScriptName YourScript Extends ObjectReference


Actor Property PlayerREF Auto ; <-- Imperative for expedience
Actor Property PlayerREF Auto ; <-- Imperative for expedience
Line 744: Line 744:
EndIf
EndIf
EndIf
EndIf
EndFunction</source>
EndFunction</syntaxhighlight>
If the statue is only to enable on Thursdays, add a check to the above like so:
If the statue is only to enable on Thursdays, add a check to the above like so:
<source lang="papyrus">Function ToggleEnableStateIfApplicable()
<syntaxhighlight lang="papyrus">Function ToggleEnableStateIfApplicable()
Float fTime = GameHour.GetValue()
Float fTime = GameHour.GetValue()
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
Line 760: Line 760:
Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc.
Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc.
Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7
Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7
EndFunction</source>
EndFunction</syntaxhighlight>




Line 771: Line 771:
The following is an example of the script in action.
The following is an example of the script in action.


<source lang="papyrus">ScriptName jlTimedLock2 extends TimedObjRef2
<syntaxhighlight lang="papyrus">ScriptName jlTimedLock2 extends TimedObjRef2


String Property sEnabledMessage Auto ; Optional Message when enabled.
String Property sEnabledMessage Auto ; Optional Message when enabled.
Line 801: Line 801:
; End Custom Code.
; End Custom Code.
EndFunction
EndFunction
</source>
</syntaxhighlight>


Don't forget to set the properties once you have attached the script to an Object Reference.
Don't forget to set the properties once you have attached the script to an Object Reference.
Line 810: Line 810:
[http://forums.bethsoft.com/topic/1507702-adding-a-spell-when-you-shout/#entry23774668 Created by a modder named DServant]. The way this works, is when you use a shout, an ability is added. This will work while in combat or outside of it.  
[http://forums.bethsoft.com/topic/1507702-adding-a-spell-when-you-shout/#entry23774668 Created by a modder named DServant]. The way this works, is when you use a shout, an ability is added. This will work while in combat or outside of it.  


<source lang=papyrus>
<syntaxhighlight lang=papyrus>
Scriptname DSerFireBreathMonitorScript extends activemagiceffect   
Scriptname DSerFireBreathMonitorScript extends activemagiceffect   


Line 828: Line 828:
EndIf
EndIf
EndEvent
EndEvent
</source>
</syntaxhighlight>
= Enabling ReferenceAliases using an array =
= Enabling ReferenceAliases using an array =
'''Requires basic knowledge in Quest creation.'''
'''Requires basic knowledge in Quest creation.'''
Say you want to enable currently disabled ReferenceAliases in the quest but you don't feel like a ton of typing and need more than one to be enabled.
Say you want to enable currently disabled ReferenceAliases in the quest but you don't feel like a ton of typing and need more than one to be enabled.
That's easy to do with an array.
That's easy to do with an array.
<source lang=papyrus>
<syntaxhighlight lang=papyrus>
Function EnableActorsArray(ReferenceAlias[] myAliasArray, Bool abSpecifyQuest=false, Quest akQuest=none, int aiStage=0)  
Function EnableActorsArray(ReferenceAlias[] myAliasArray, Bool abSpecifyQuest=false, Quest akQuest=none, int aiStage=0)  
; Enable aliases when needed. Make sure "ALLOW DISABLED" box checked, and the REFERENCE's "Initially Disabled" box is checked!
; Enable aliases when needed. Make sure "ALLOW DISABLED" box checked, and the REFERENCE's "Initially Disabled" box is checked!
Line 860: Line 860:
endif
endif
EndFunction
EndFunction
</source>
</syntaxhighlight>


=Resurrect an Enemy on Death Script=
=Resurrect an Enemy on Death Script=
Created by [http://www.nexusmods.com/skyrim/users/6211524/? DarkWolfModding].
Created by [http://www.nexusmods.com/skyrim/users/6211524/? DarkWolfModding].
This is a script that will resurrect an enemy for a defined amount of times.
This is a script that will resurrect an enemy for a defined amount of times.
<source lang=papyrus>
<syntaxhighlight lang=papyrus>
Scriptname ResurrectEnemySCRIPT Extends Actor
Scriptname ResurrectEnemySCRIPT Extends Actor
import game
import game
Line 887: Line 887:
     CurrentDeathCount += 1 ;CurrentDeathCount = CurrentDeathCountValue + 1
     CurrentDeathCount += 1 ;CurrentDeathCount = CurrentDeathCountValue + 1
EndFunction
EndFunction
</source>
</syntaxhighlight>
Once you compile the script just attach the script to an enemy actor and set the value of MaxDeathCount to the desired max amount of deaths.
Once you compile the script just attach the script to an enemy actor and set the value of MaxDeathCount to the desired max amount of deaths.


Navigation menu