Difference between revisions of "Bethesda Tutorial Basic Quest Scripting"

m
imported>Henning
 
imported>Lmstearn
 
(9 intermediate revisions by 5 users not shown)
Line 19: Line 19:
The scripting language used by the Creation Kit is called Papyrus (after the material on which scrolls are printed). Papyrus scripts are normal text files that get turned into a bytecode that the game executes at runtime.  
The scripting language used by the Creation Kit is called Papyrus (after the material on which scrolls are printed). Papyrus scripts are normal text files that get turned into a bytecode that the game executes at runtime.  


::{|style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0"
{{NewFeature|The new system is similar to the old TESScript, but requires a slightly different way of thinking. You can no longer directly manipulate objects in the world; it's now threaded so your script might be interrupted mid-run; it's more of a stickler for things like parentheses. In short, it's much more similar to "real" programming languages like [http://lua.org Lua] or [http://python.org Python]. If you're familiar with TESScript, you'll want to look at our [[Differences_from_Previous_Scripting|transition guide]].}}
|-
|style="border-style: solid; border-width: 0"|[[Image:NewFeature.jpg|48px]]
|style="border-style: solid; border-width: 0"|The new system is similar to the old TESScript, but requires a slightly different way of thinking. You can no longer directly manipulate objects in the world; it's now threaded so your script might be interrupted mid-run; it's more of a stickler for things like parentheses. In short, it's much more similar to "real" programming languages like [http://lua.org Lua] or [http://python.org Python]. If you're familiar with TESScript, you'll want to look at our [[Differences_from_Previous_Scripting|transition guide]].
|}


The first thing we're going to do is add a script to the thief so that when it's killed, the quest updates appropriately.  
The first thing we're going to do is add a script to the thief so that when it's killed, the quest updates appropriately.  
Line 68: Line 64:
<source lang="papyrus">
<source lang="papyrus">
Event OnDeath(Actor killer)
Event OnDeath(Actor killer)
        TutorialQuest.SetObjectiveDisplayed(20)
TutorialQuest.SetStage(20)
TutorialQuest.SetStage(20)
EndEvent
EndEvent
</source>
</source>
Once again, ignore the <code>SetObjectiveDisplayed(20)</code>


If you're familiar enough with programming or scripting that what you just pasted made sense to you, feel free to skip ahead to the "Scripting the Amulet" section. For everyone else, we'll go through line by line.  
If you're familiar enough with programming or scripting that what you just pasted made sense to you, feel free to skip ahead to the "Scripting the Amulet" section. For everyone else, we'll go through line by line.  
Line 88: Line 87:
If you see anything else in there, you typed something wrong. Try again!  
If you see anything else in there, you typed something wrong. Try again!  


Once you're done, close the script windows and the actor window, and save your plugin. Now it's time to script the amulet itself.  
Once you're done, close the script windows and the actor window, and save your plugin. Now it's time to script the amulet itself.


=Scripting the Amulet=
=Scripting the Amulet=
Line 106: Line 105:
Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
if (newContainer == Game.GetPlayer())
if (newContainer == Game.GetPlayer())
                GSQ01.SetObjectivedisplayed(30)
GSQ01.SetStage(30)
GSQ01.SetStage(30)
endif
endif
EndEvent
EndEvent
</source>
</source>
Ignore it once again. It will be explained in the section about objectives.


There a few things to note in this script:
There a few things to note in this script:
Line 121: Line 123:
You can now play through the quest from start to finish, checking the console with [[ShowQuestVars|SQV]] to see its stage changing.  
You can now play through the quest from start to finish, checking the console with [[ShowQuestVars|SQV]] to see its stage changing.  


Players can't use the console, though, so we'll learn how to give them better feedback about the quest in the next chapter.  
Players can't be expected to use the console, though, so we'll learn how to give them better feedback about the quest in the next chapter.  


::{|style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0"
{{ProTip|The scripts for Skyrim are just text files that live in your data directory before they get compiled into bytecode. This means that if you've got a favorite text editor, you can use it to work on scripts. We've included setups for both [[Sublime Text Setup|Sublime Text]] and [[Notepad++ Setup|Notepad++]] that provide syntax highlighting, some basic autocompletion, and compilation shortcuts. If you're going to get heavily into scripting, these tools can make your life a lot easier.}}
|-
|style="border-style: solid; border-width: 0"|[[Image:Protip.jpg|48px]]
|style="border-style: solid; border-width: 0"|The scripts for Skyrim are just text files that live in your data directory before they get compiled into bytecode. This means that if you've got a favorite text editor, you can use it to work on scripts. We've included setups for both [[Sublime Text Setup|Sublime Text]] and [[Notepad++ Setup|Notepad++]] that provide syntax highlighting, some basic autocompletion, and compilation shortcuts. If you're going to get heavily into scripting, these tools can make your life a lot easier.  
|}


=Notes=


{{Template:Tutorial_Bottom_Bar
* Papyrus boxes can be [http://forums.bethsoft.com/topic/1513334-no-viable-alternative-at-input/ temperamental] after the wrong code is inserted. Okaying the form and returning to it and possibly restarting the CK can resolve.
 
* Removing a saved script from a papyrus box may not automatically remove the associated compiled pex in the script folder, which has an impact on testing in-game.
 
{{Tutorial_Bottom_Bar
|Prev=Bethesda_Tutorial_Creating_an_Item
|Prev=Bethesda_Tutorial_Creating_an_Item
|Next=Bethesda_Tutorial_Quest_Objectives
|Next=Bethesda_Tutorial_Quest_Objectives
}}
}}
{{Languages}}
Anonymous user