Complete Example Scripts: Difference between revisions

m
Convert source tags to syntaxhighlight
imported>JustinOther
m (Removed '> 0' from a few While loops as iIndex will be 'False' when counted down to 0, ending the loop/Added a few spaces around operators for greater legibility/floatified an int to avoid unnecessary auto-cast)
m (Convert source tags to syntaxhighlight)
 
(42 intermediate revisions by 11 users not shown)
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 45: Line 45:
If UncompleteEnable
If UncompleteEnable
FromQuest.SetObjectiveCompleted(ObjectiveToCompleteOnPickup, False)
FromQuest.SetObjectiveCompleted(ObjectiveToCompleteOnPickup, False)
EndiI
EndIf
If StageToSetOnDrop >= 0
If StageToSetOnDrop >= 0
FromQuest.SetStage(StageToSetOnDrop)
FromQuest.SetStage(StageToSetOnDrop)
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 106: Line 106:


* A orange box should appear around the object you selected.
* 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.
* 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.
<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 145: 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.
* Remember to add this example script to the trigger volume object that you create, so you have an actual instance of this script in your level.
* Remember to add this example script to the trigger volume object that you create, so you have an actual instance of this script in your level.
* You must create a formlist of the objects you want to cycle through in this script example.  
* You must create a formlist of the objects you want to cycle through in this script example.  
[[Image:Formlist_making_a_formlist_and_populating_it.jpg]]
[[Image:Formlist_populating.png]]


1. Go to the miscellaneous section of the Object Window and click on FormLists,  
1. Go to the miscellaneous section of the Object Window and click on FormLists,  
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.


<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 186: 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 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.
<source lang="papyrus">ScriptName MoveObjExample extends ObjectReference   
<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 </source>
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=
<source lang="papyrus">Scriptname DwemerButtonExampleScript extends ObjectReference   
<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</source>
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=
<source lang="papyrus">ScriptName SetStageOnPlayerPickUp Extends ObjectReference
<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</source>
EndState</syntaxhighlight>


=Usage of Arrays to Make Scripts Compact=
=Usage of Arrays 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. Below I was having to do things to things to about 30 different draugrs:
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. Below I was having to do things to about 30 different draugrs:
* turn their AI on and make them visible
* turn their AI on and make them visible
* 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 290: 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 Draurg as the enable parent of the other 29 and enable/disable him, 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.


'''How to Make This Script Work'''
'''How to Make This Script Work'''
* You will need to fill the array elements in the Creation Kit with the chosen creatures.
* You will need to fill the array elements in the Creation Kit with the chosen creatures.
* 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 choose 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 =
= 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 312: Line 307:


Int Function GetPassedGameDays() Global
Int Function GetPassedGameDays() Global
Int GameTime
Float GameDaysPassed
Float GameDaysPassed
GameTime = GetCurrentGameTime()
GameDaysPassed = GetCurrentGameTime()
GameDaysPassed = GameTime As Int
Return GameDaysPassed As Int
Return GameDaysPassed
EndFunction
EndFunction


Line 328: Line 321:


Int Function GetPassedGameHours() Global
Int Function GetPassedGameHours() Global
Int GameTime
Float GameTime
Float GameHoursPassed
Float GameHoursPassed
GameTime = GetCurrentGameTime()
GameTime = GetCurrentGameTime()
GameHoursPassed = ((GameTime - (GameTime As Int)) * 24) As Int
GameHoursPassed = ((GameTime - (GameTime As Int)) * 24)
Return GameHoursPassed
Return GameHoursPassed As Int
EndFunction
EndFunction


Line 433: Line 426:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/;


Int Function GetDayOfWeek()
Int Function GetDayOfWeek() Global
Int GameDaysPassed
Int GameDaysPassed
Line 440: Line 433:
EndFunction
EndFunction


</source>
</syntaxhighlight>


'''How to make this script work'''
'''How to make this script work'''
Line 447: Line 440:


= Script to make an item cast a spell =
= Script to make an item cast a spell =
<Source lang="Papyrus">Scriptname SpellZapScript extends ObjectReference   
<syntaxhighlight lang="Papyrus">Scriptname SpellZapScript extends ObjectReference   


import Utility
import Utility
Line 490: Line 483:
     RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate))
     RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate))
EndEvent
EndEvent
</Source>
</syntaxhighlight>


How to make this script work:
How to make this script work:
Line 504: Line 497:
= Script for a quest with time limit =
= Script for a quest with time limit =


<Source lang="Papyrus">
<syntaxhighlight lang="Papyrus">
Scriptname LH_TimeLimitedQuest extends Quest   
Scriptname LH_TimeLimitedQuest extends Quest   


Line 542: Line 535:
EndIf
EndIf
EndEvent
EndEvent
</Source>
</syntaxhighlight>


=Making a Cool Cut-Scene=
=Making a Cool Cut-Scene=


<Source lang="Papyrus">
<syntaxhighlight lang="Papyrus">
ScriptName Cutscene Extends ObjectReference
ScriptName Cutscene Extends ObjectReference


Line 570: Line 563:
Game.EnablePlayerControls()
Game.EnablePlayerControls()
EndIf
EndIf
EndEvent</Source>
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 576: 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.
<Source lang="Papyrus">
<syntaxhighlight lang="Papyrus">
ScriptName ExampleContainerScript Extends ObjectReference
ScriptName ExampleContainerScript Extends ObjectReference


Line 589: Line 582:
EndIf
EndIf
Endif
Endif
EndEvent</Source>
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.
<Source lang="Papyrus">ScriptName YourQuestScript extends Quest
<syntaxhighlight lang="Papyrus">ScriptName YourQuestScript extends Quest


Float fVersion
Float fVersion
Line 616: Line 609:
Event OnPlayerLoadGame()
Event OnPlayerLoadGame()
QuestScript.Maintenance()
QuestScript.Maintenance()
EndEvent</source>
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.
<Source lang="Papyrus">ScriptName YourQuestScript extends Quest
<syntaxhighlight lang="Papyrus">ScriptName YourQuestScript extends Quest


Float fVersion
Float fVersion
Line 648: Line 641:
Return False
Return False
EndIf
EndIf
EndFunction</Source>
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 elsweyr. 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.
*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.
<Source lang="Papyrus">ScriptName RepeatableSummonEffectScript extends ActiveMagicEffect
<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 677: Line 670:
                 Utility.Wait(0.6)
                 Utility.Wait(0.6)
         EndWhile
         EndWhile
EndFunction</source>
EndFunction</syntaxhighlight>


= Show Gift Inventory and Identify Items Given =
= Show Gift Inventory and Identify Items Given =
Line 683: 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 702: Line 695:
EndIf
EndIf
EndEvent
EndEvent
</source>
</syntaxhighlight>
 
= Enable/Disable an object on a schedule =
 
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
Bool Property bEnableStuff Auto ; Leave as default or 'False'
Float Property fHourToDisable Auto ; Desired enable time/18.0 for example's sake
Float Property fHourToEnable Auto ; Desired enable time/6.0 for example's sake
Float Property fUpdateInterval Auto ; 15.0 works well and isn't too frantic.
GlobalVariable Property GameHour Auto ; Pointed to engine maintained, special GlobalVariable
ObjectReference Property kYourObject Auto ; Pointed to your statue or object that is to enable
 
Event OnInit()
RegisterForSingleLOSGain(PlayerREF, Self)
bEnableStuff = !kYourObject.IsDisabled()
ToggleEnableStateIfApplicable()
EndEvent
 
Event OnGainLOS(Actor akViewer, ObjectReference akTarget)
RegisterForSingleLOSLost(PlayerREF, Self)
RegisterForSingleUpdate(fUpdateInterval)
ToggleEnableStateIfApplicable()
EndEvent
 
Event OnLostLOS(Actor akViewer, ObjectReference akTarget)
RegisterForSingleLOSGain(PlayerREF, Self)
UnregisterForUpdate() ; Stop polling
ToggleEnableStateIfApplicable()
EndEvent
 
Event OnUpdate()
ToggleEnableStateIfApplicable()
RegisterForSingleUpdate(fUpdateInterval)
EndEvent
 
Function ToggleEnableStateIfApplicable()
Float fTime = GameHour.GetValue()
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
bEnableStuff = !bEnableStuff
If bEnableStuff
kYourObject.Enable()
Else
kYourObject.Disable()
EndIf
EndIf
EndFunction</syntaxhighlight>
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()
If bEnableStuff != (fTime > fHourToEnable && fTime < fHourToDisable)
bEnableStuff = GetDayOfWeek() == 5 ; Turdas
If bEnableStuff
kYourObject.Enable()
Else
kYourObject.Disable()
EndIf
EndIf
EndFunction
 
Int Function GetDayOfWeek() Global ; 0 : Sundas :: 5 : Turdas, etc.
Return ((Game.GetFormFromFile(0x00000039, "Skyrim.ESM") As GlobalVariable).GetValue() As Int) % 7
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]]