Complete Example Scripts: Difference between revisions
Jump to navigation
Jump to search
Added Maintenance/Update examples
imported>David Brasher (Reformatting for the sake of better linking to individual scripts.) |
imported>JustinOther (Added Maintenance/Update examples) |
||
| Line 26: | Line 26: | ||
bToggle = !bToggle ; Set Bool to whatever it's not | bToggle = !bToggle ; Set Bool to whatever it's not | ||
If bToggle ; True | If bToggle ; True | ||
; Do stuff | |||
Else ; False | Else ; False | ||
; Undo stuff | |||
Endif | Endif | ||
EndEvent</source> | EndEvent</source> | ||
| Line 219: | Line 219: | ||
if (akActionRef == Game.GetPlayer()) | if (akActionRef == Game.GetPlayer()) | ||
akActionRef.TranslateToRef(dest,500) | akActionRef.TranslateToRef(dest,500) | ||
;500 is the speed value, it's pretty fast | |||
endif | endif | ||
| Line 406: | Line 406: | ||
;//End new version. | ;//End new version. | ||
</source> | </source> | ||
| Line 712: | Line 711: | ||
EndEvent | EndEvent | ||
</Source> | </Source> | ||
=Making a Cool Cut-Scene= | =Making a Cool Cut-Scene= | ||
| Line 746: | Line 743: | ||
'''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! | ||
= Script a container that only accepts certain types of items = | = Script a container that only accepts certain types of items = | ||
| Line 764: | Line 759: | ||
Endif | Endif | ||
EndEvent</Source> | EndEvent</Source> | ||
= Maintenance/update code which runs once per save load and shows a message when a mod is updated or first loaded = | |||
*With Skyrim v1.6+: All event based, so no polling is necessary. For this method to work, two scripts are needed as OnPlayerGameLoad will not fire from a Quest script. | |||
<Source lang="Papyrus">ScriptName YourQuestScript extends Quest | |||
Float fVersion | |||
Event OnInit() | |||
Maintenance() ; OnPlayerLoadGame will not fire the first time | |||
EndEvent | |||
Function Maintenance() | |||
If fVersion < 1.01 ; <--- Edit this value when updating | |||
fVersion = 1.01 ; and this | |||
Debug.Notification("Now running YourModName version: " + fVersion) | |||
; Update Code | |||
EndIf | |||
; Other maintenance code that only needs to run once per save load | |||
EndFunction | |||
;****************************************************** | |||
ScriptName YourPlayerAliasScript extends ReferenceAlias | |||
YourQuestScript Property QuestScript Auto | |||
Event OnPlayerLoadGame() | |||
QuestScript.Maintenance() | |||
EndEvent | |||
*Not using 1.6+: Has to poll, but will work reliably and can be fit in with existing, reiterating code. | |||
<Source lang="Papyrus">ScriptName YourQuestScript extends Quest | |||
Float fVersion | |||
Actor Property ActorFromYourMod Auto | |||
Event OnInit() | |||
RegisterForUpdate(10) | |||
EndEvent | |||
Event OnUpdate() | |||
If bGetGameLoaded(ActorFromYourMod, "BrainCondition") | |||
If fVersion < 1.01 | |||
fVersion = 1.01 | |||
Debug.Notification("Now running YourModName version: " + fVersion) | |||
; Update Code | |||
EndIf | |||
; Maintenance code | |||
Else | |||
; Other, reiterating code if needed | |||
EndIf | |||
EndEvent | |||
Bool Function bGetGameLoaded(Actor akActor, String asActorValue = "") | |||
If akActor.GetActorValue(asActorValue) | |||
akActor.SetActorValue(asActorValue, 0) | |||
Return True ; Will have reverted to 100 upon save load since BrainCondition is obsolete and not stored in saves | |||
Else | |||
Return False | |||
EndIf | |||
EndFunction</Source> | |||