141
edits
imported>Qqqbbb m (→typo) |
RobinHood70 (talk | contribs) m (Convert source tags to syntaxhighlight) |
||
| (23 intermediate revisions by 8 users not shown) | |||
| Line 18: | Line 18: | ||
=Creating a Simple Toggle= | =Creating a Simple Toggle= | ||
< | <syntaxhighlight lang="papyrus">ScriptName SimpleToggle Extends ObjectReference | ||
Bool bToggle | Bool bToggle | ||
| Line 29: | Line 29: | ||
; Undo stuff | ; Undo stuff | ||
Endif | Endif | ||
EndEvent</ | 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.= | ||
< | <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. | ||
</ | </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= | ||
< | <syntaxhighlight lang="papyrus"> | ||
ScriptName ExampleTrigger Extends ObjectReference | ScriptName ExampleTrigger Extends ObjectReference | ||
| Line 97: | Line 97: | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
'''To Make This Script Work''' | '''To Make This Script Work''' | ||
| Line 106: | Line 106: | ||
* A orange box should appear around the object you selected. | * A orange box should appear around the object you selected. | ||
* Now edit the new orange box you created and add the script above. | * Now edit the new orange box you created and add the script above. | ||
| Line 127: | 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. | ||
< | <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 145: | Line 140: | ||
EndWhile | EndWhile | ||
EndIf | EndIf | ||
EndEvent</ | 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 169: | 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. | ||
< | <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 186: | Line 181: | ||
Function PerformActionOn(ObjectReference Target) | Function PerformActionOn(ObjectReference Target) | ||
Target.MoveTo(Target, 0, 0, 16) | Target.MoveTo(Target, 0, 0, 16) | ||
EndFunction</ | EndFunction</syntaxhighlight> | ||
'''To Make This Script Work''' | '''To Make This Script Work''' | ||
| Line 204: | 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. | ||
< | <syntaxhighlight lang="papyrus">ScriptName MoveObjExample extends ObjectReference | ||
Actor Property PlayerREF Auto | Actor Property PlayerREF Auto | ||
| Line 213: | 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 </ | EndEvent </syntaxhighlight> | ||
'''To Make This Script Work''' | '''To Make This Script Work''' | ||
| Line 224: | Line 219: | ||
=A Fully Functional Dwemer Button= | =A Fully Functional Dwemer Button= | ||
< | <syntaxhighlight lang="papyrus">Scriptname DwemerButtonExampleScript extends ObjectReference | ||
Actor Property PlayerREF Auto | Actor Property PlayerREF Auto | ||
| Line 241: | 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</ | EndEvent</syntaxhighlight> | ||
'''To Make This Script Work''' | '''To Make This Script Work''' | ||
| Line 253: | Line 248: | ||
=Set Quest Stage When Picked Up By Player= | =Set Quest Stage When Picked Up By Player= | ||
< | <syntaxhighlight lang="papyrus">ScriptName SetStageOnPlayerPickUp Extends ObjectReference | ||
Actor Property PlayerREF Auto | Actor Property PlayerREF Auto | ||
| Line 268: | Line 263: | ||
State Taken | State Taken | ||
; Do nothing | ; Do nothing | ||
EndState</ | EndState</syntaxhighlight> | ||
=Usage of Arrays to Make Scripts Compact= | =Usage of Arrays to Make Scripts Compact= | ||
| Line 275: | 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. | ||
< | <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 290: | Line 285: | ||
EndWhile | EndWhile | ||
EndIf | EndIf | ||
EndEvent</ | 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 | 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. | ||
'''How to Make This Script Work''' | '''How to Make This Script Work''' | ||
| Line 298: | 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 = | ||
< | <syntaxhighlight lang="papyrus"> | ||
Scriptname ExtendedUtility | Scriptname ExtendedUtility | ||
| Line 438: | Line 433: | ||
EndFunction | EndFunction | ||
</ | </syntaxhighlight> | ||
'''How to make this script work''' | '''How to make this script work''' | ||
| Line 445: | Line 440: | ||
= Script to make an item cast a spell = | = Script to make an item cast a spell = | ||
< | <syntaxhighlight lang="Papyrus">Scriptname SpellZapScript extends ObjectReference | ||
import Utility | import Utility | ||
| Line 488: | Line 483: | ||
RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate)) | RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate)) | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
How to make this script work: | How to make this script work: | ||
| Line 502: | Line 497: | ||
= Script for a quest with time limit = | = Script for a quest with time limit = | ||
< | <syntaxhighlight lang="Papyrus"> | ||
Scriptname LH_TimeLimitedQuest extends Quest | Scriptname LH_TimeLimitedQuest extends Quest | ||
| Line 540: | Line 535: | ||
EndIf | EndIf | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
=Making a Cool Cut-Scene= | =Making a Cool Cut-Scene= | ||
< | <syntaxhighlight lang="Papyrus"> | ||
ScriptName Cutscene Extends ObjectReference | ScriptName Cutscene Extends ObjectReference | ||
| Line 568: | Line 563: | ||
Game.EnablePlayerControls() | Game.EnablePlayerControls() | ||
EndIf | EndIf | ||
EndEvent</ | EndEvent</syntaxhighlight> | ||
'''How to use this script''': Make a new trigger box, and then add this script to it. Make 3 XMarkers, and define them in the Properties Window. Enter your new trigger, and see your cool cut-scene! | '''How to use this script''': Make a new trigger box, and then add this script to it. Make 3 XMarkers, and define them in the Properties Window. Enter your new trigger, and see your cool cut-scene! | ||
| Line 574: | Line 569: | ||
= Script a container that only accepts certain types of items = | = 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. | ||
< | <syntaxhighlight lang="Papyrus"> | ||
ScriptName ExampleContainerScript Extends ObjectReference | ScriptName ExampleContainerScript Extends ObjectReference | ||
| Line 587: | Line 582: | ||
EndIf | EndIf | ||
Endif | Endif | ||
EndEvent</ | EndEvent</syntaxhighlight> | ||
= Maintenance/update code which runs once per save load and shows a message when a mod is updated or first loaded = | = Maintenance/update code which runs once per save load and shows a message when a mod is updated or first loaded = | ||
*Requires Skyrim v1.6+: All event based, so no polling is necessary. For this method to work, two scripts are needed as [[OnPlayerLoadGame - Actor|OnPlayerLoadGame]] will not fire from a Quest script. | *Requires Skyrim v1.6+: All event based, so no polling is necessary. For this method to work, two scripts are needed as [[OnPlayerLoadGame - Actor|OnPlayerLoadGame]] will not fire from a Quest script. | ||
< | <syntaxhighlight lang="Papyrus">ScriptName YourQuestScript extends Quest | ||
Float fVersion | Float fVersion | ||
| Line 614: | Line 609: | ||
Event OnPlayerLoadGame() | Event OnPlayerLoadGame() | ||
QuestScript.Maintenance() | QuestScript.Maintenance() | ||
EndEvent</ | EndEvent</syntaxhighlight> | ||
*Does not require Skyrim v1.6+: Has to poll, but will work reliably and can be fit in with existing, reiterating code. | *Does not require Skyrim v1.6+: Has to poll, but will work reliably and can be fit in with existing, reiterating code. | ||
< | <syntaxhighlight lang="Papyrus">ScriptName YourQuestScript extends Quest | ||
Float fVersion | Float fVersion | ||
| Line 646: | Line 641: | ||
Return False | Return False | ||
EndIf | EndIf | ||
EndFunction</ | EndFunction</syntaxhighlight> | ||
= Summon Spell = | = Summon Spell = | ||
*The below will summon YourSummonREF from wherever they are to the player. In this example, it's dealt with by a spell, but the function could be placed and/or called | *The below will summon YourSummonREF from wherever they are to the player. In this example, it's dealt with by a spell, but the function could be placed and/or called elsewhere. If as a spell, be sure to set the cooldown time to about 3.0 seconds so the caster can't cast it again until it's worked itself out. | ||
< | <syntaxhighlight lang="Papyrus">ScriptName RepeatableSummonEffectScript extends ActiveMagicEffect | ||
Actor Property YourSummonREF Auto ; An ObjectReference will also work with the summon function | Actor Property YourSummonREF Auto ; An ObjectReference will also work with the summon function | ||
| Line 675: | Line 670: | ||
Utility.Wait(0.6) | Utility.Wait(0.6) | ||
EndWhile | EndWhile | ||
EndFunction</ | EndFunction</syntaxhighlight> | ||
= Show Gift Inventory and Identify Items Given = | = Show Gift Inventory and Identify Items Given = | ||
| Line 681: | 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. | ||
< | <syntaxhighlight lang="papyrus"> | ||
Actor Property PlayerREF Auto | Actor Property PlayerREF Auto | ||
FormList Property FoodList Auto | FormList Property FoodList Auto | ||
| Line 700: | Line 695: | ||
EndIf | EndIf | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
= Enable/Disable an object on a schedule = | = Enable/Disable an object on a schedule = | ||
| Line 706: | 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. | ||
< | <syntaxhighlight lang="papyrus">ScriptName YourScript Extends ObjectReference | ||
Actor Property PlayerREF Auto ; <-- Imperative for expedience | Actor Property PlayerREF Auto ; <-- Imperative for expedience | ||
| Line 749: | Line 744: | ||
EndIf | EndIf | ||
EndIf | EndIf | ||
EndFunction</ | 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: | ||
< | <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 765: | 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</ | EndFunction</syntaxhighlight> | ||
= Enable/Disable Lock on object based on hours of day = | |||
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. | |||
This script section now uses a new Timed Object Reference which no longer performs polling in order to check the times. Instead it make use of the WaitGameTime function which means less overhead and more accurate timing. | |||
'''To make this work''': Download and copy the [https://gist.github.com/Langerz82/976c172ce04f074bea91 TimedObjRef2.psc] file to your Skyrim/Data folder. | |||
The following is an example of the script in action. | |||
<syntaxhighlight lang="papyrus">ScriptName jlTimedLock2 extends TimedObjRef2 | |||
String Property sEnabledMessage Auto ; Optional Message when enabled. | |||
String Property sDisabledMessage Auto ; Optional Message when disabled. | |||
; Override the original function | |||
Function ObjectActive() | |||
if (sEnabledMessage != "") | |||
Debug.MessageBox(sEnabledMessage) | |||
EndIf | |||
; Insert Custom Code. | |||
; Example - Timed Locking. | |||
Self.Lock(TRUE, TRUE) | |||
; End Custom Code. | |||
EndFunction | |||
; Override the original function | |||
Function ObjectInactive() | |||
If (sDisabledMessage != "") | |||
Debug.MessageBox(sDisabledMessage) | |||
EndIf | |||
; Insert Custom Code. | |||
; Example - Timed Unlocking. | |||
Self.Lock(FALSE, TRUE) | |||
; End Custom Code. | |||
EndFunction | |||
</syntaxhighlight> | |||
Don't forget to set the properties once you have attached the script to an Object Reference. | |||
For more examples like this see [[Using Activated Object Reference]] for advanced functionality. | |||
= Adding a spell when you shout = | |||
[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. | |||
<syntaxhighlight lang=papyrus> | |||
Scriptname DSerFireBreathMonitorScript extends activemagiceffect | |||
Spell Property YourAbility Auto | |||
Event OnEffectStart(Actor akTarget, Actor akCaster) | |||
RegisterForAnimationEvent(Game.GetPlayer(), "BeginCastVoice") | |||
Debug.Notification("Waiting on Shout") | |||
EndEvent | |||
Event OnAnimationEvent(ObjectReference akSource, string asEventName) | |||
if (akSource == Game.GetPlayer()) && (asEventName == "BeginCastVoice") | |||
Debug.Notification("Fire Breath Shout Cast") | |||
Game.GetPlayer().AddSpell(YourAbility,false) | |||
Utility.Wait(10) | |||
Game.GetPlayer().RemoveSpell(YourAbility) | |||
EndIf | |||
EndEvent | |||
</syntaxhighlight> | |||
= Enabling ReferenceAliases using an array = | |||
'''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. | |||
That's easy to do with an array. | |||
<syntaxhighlight lang=papyrus> | |||
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! | |||
; Can optionally have them enable on a specific quest stage of a quest that is different from the alias' parent quest. Requires that abSpecificQuest is set to the true. | |||
int MyArrayLength = myAliasArray.length | |||
if abSpecifyQuest == false | |||
While (myArraylength) | |||
myArrayLength -= 1 | |||
myAliasArray[myArrayLength].GetReference().Enable() | |||
debug.trace("References that have been enabled:" !myAliasArray[myArrayLength].GetReference().IsDisabled()) | |||
EndWhile | |||
else | |||
if (akQuest.GetCurrentStageID() == aiStage) | |||
While (myArrayLength) | |||
myArrayLength -= 1 | |||
myAliasArray[myArrayLength].GetReference().Enable() | |||
debug.trace("References that have been disabled:" !myAliasArray[myArrayLength].GetReference().IsDisabled()) | |||
EndWhile | |||
endif | |||
endif | |||
EndFunction | |||
</syntaxhighlight> | |||
=Resurrect an Enemy on Death Script= | |||
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. | |||
<syntaxhighlight lang=papyrus> | |||
Scriptname ResurrectEnemySCRIPT Extends Actor | |||
import game | |||
import utility | |||
import debug | |||
Actor Property PlayerREF Auto | |||
int Property MaxDeathCount auto | |||
Int Property CurrentDeathCount Auto ;DO NOT Change | |||
Event OnDeath(Actor akKiller) | |||
AddToCurrentDeathCount() | |||
If (CurrentDeathCount <= MaxDeathCount) ;If Death count is lower than MaxDeathCount do the next bit of code | |||
wait(2); Wait 2 Seconds real time | |||
Self.PlaceAtMe(GetFormFromFile(0x0007CD55, "Skyrim.ESM"));Place Summon FX at dead NPC | |||
Self.Resurrect() ;Resurrect Dead NPC | |||
EndIf | |||
EndEvent | |||
Function AddToCurrentDeathCount() | |||
CurrentDeathCount += 1 ;CurrentDeathCount = CurrentDeathCountValue + 1 | |||
EndFunction | |||
</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. | |||
--[[User:DarkWolfModding|DarkWolfModding]] ([[User talk:DarkWolfModding|talk]]) 2014-12-03T11:42:37 (EST) | |||
{{Languages}} | {{Languages}} | ||
[[Category: Papyrus]] | [[Category: Papyrus]] | ||
edits