Jump to content
Mattiewagg

[Graduate Thread] Trivia - Matthiaswagg

Recommended Posts

Alright. Let's get this started. I believe you have but if you haven't please install the Creation Kit (found under Library>Tools in Steam).
We'll be covering scripting first, as it'll make creation of small and large scriots for use in quests easier, and has a variety of applications not just for quests but also dungeons, NPCs, bosses (unique boss fights), etc.
Now, please read thesetwo tutorials on scripting I linked, if you haven't already. It should help you understand the basics, so what I say should be a little bit comprehensible.  :P
Part 1
Part 2
For scripting, I don't recommend using the built in Creation Kit script editor. It's not all that fun to work with. Especially because if the CK crashes during your writing of a 500 line script, you'll lose all that. If the CK built in editor even lets you write that much. Often it won't. The majority of scripting is done in an exterior program from the CK, except for hooking up your scripts to the game.
Also, syntax highlighting (pretty colors for your code) and auto complete (as you start to write a function or something it'll allow you to autocomplete it, including parameters) and quick compiling will save your life.
So I'm going to highly recommend you install a good text editor for this. Notepad++ and SublimeText 2 are the most well supported editors for Papyrus (Skyrim's scripting language). They're both absolutely free. Sublime Text will ask for you to verify and pay after a free trial, every month or so, but it's not needed to actually pay ever. It's not at all annoying and just a quick Ok every month. I'll briefly outline the pros and cons for you. I'm currently using ST2 though I used NP++ in the past:
Notepad++:
Pros:
- Good support for Skyrim scripting, as well as SKSE functions and SkyUI
- Easy to use
- Nice interface, clean look and good syntax highlighting
- Auto complete is great. Also includes definitions of functions - so it will autocomplete, tell you which mod/script the function is from, what it does (not all definitions are complete but many), and possibly how it's used. This feature is mainly what I miss for NP.
Cons:
- Sort of a pain to set up the quick compiler, which allows you to compile directly from NP++ rather than writing there and then pasting in CK and then compiling there. Note it may just be because I suck really really bad at using the command line/stuff you need to set it up. Some people find it very was, I didnt.
- Can't change color scheme - a few syntax colors to choose from but none radically different
- No extra plugins
Set it up for the CK here: Linky
SublimeText 2:
Pros:
- Super easy to set up
- Support for SKSE, SkyUI, and almost all other SKSE plugins (syntax and autocomplete)
- Changeable color themes
- Autocomplete
- Syntax
- Plugins and more color themes are downloadable with the (free) Package Control. Plugins can be helpful for greater editing of scripts, and color themes are fun to play around with.
Cons:
- Autocomplete doesn't support definitions.
Setup for Sublime Text 2: Linky
Whenever you've got that set up, tell me (along with which text editor you've decided to use). Be sure to associate .psc files, which can be found in Data/Scripts/Source with your text editor of choice and when we do begin be sure to create your scripts and then edit by right clicking and selecting Open in External Editor.
Then tell me anything you were confused about on the tutorials and we'll begin from there. I'll explain what was confusing and we'll begin on a task of sorts - your first script. If you have any preference on what you want the script to do (unrelated to quests for now), please tell me. I'll take it into account as a first or later script to do, depending on complexity. Examples are a series of messageboxes w/ choices, a script on an activator to spawn a creature, a trigger box that when entered will disable a wall (or move the wall if we use a hidden door, but it has to contain the animations for this). There are many more, just tell me what comes to mind.

Edited by Mattiewagg

Share this post


Link to post
Share on other sites

Okay, I think I've got everything set up now. I went with Notepad++ as I already had it installed for editing behavior files.

I think I understood the basic concepts okay overall (though it might take me a bit to get it all sorted out in my head :) ), except for the odd thing here and there.

I'm a little fuzzy on events. I mean I get what an event is and why it's needed, I'm just not quite clear about their syntax/parameters. Like what's the "ak" prefix for? Is it short for "aktor?"  :P

Also is there a particular reason object references should be avoided? Is it an instability/crashing issue? Just inefficient? Or is it just less flexible/easier to break if something gets changed afterward?

And "if" is like a quick "check if these conditions are met" thing but "while" is more "keep doing this thing continuously until the conditions are no longer met?"

As for scripts I'm fine starting with whatever, though I'm sure I'll think of something more specific eventually.

Share this post


Link to post
Share on other sites

Parameters don't really NEED to have that prefix. They can be whatever as long as they're in the proper order - the engine sends the data, you can name it how you like. I'm not really sure why there's ak, but I use it because I like it. :P ObjectReference properties are absolutely fine, but they DO make something persistent. This means it will ALWAYS be loaded, as long as the property is filled. You CAN clear the property, though it's not always prudent/possible to do so. But it's not a huge deal, really - there are hundreds upon hundreds of persistent items in the vanilla game, and its' not much of an issue.

And you're right on While/If.

You might be interested in this thread, though it's very doubtful you'll understand it all at this time:

http://forums.bethsoft.com/topic/1409991-best-practices-papyrus/

Give me a little and I'll figure out a script for you. :D

EDIT: Tomorrow morning. Going to bed now.

Edited by Matthiaswagg

Share this post


Link to post
Share on other sites

Okay, we'll be starting out with essentially the same schedule/lessons as Minerman. We'll have your first script, which I will write for you and explain, as well as show how to hook up and set up. This will show you a working, albeit relatively simple, example of scriots and their application. It should also provide a good overview of structure.

Then, well actually have a few lessons - one-two on functions, events, and accessing properties from other scripts. If there's something else you're interested in we'll also go over that. In between each lesson I'll have you write a bit of code pertaining to the lesson, so I'm sure you understand it. Then I'll have you make your own script from scratch, based off of what you've learned. If you need guidance with that I'll be able to help, but I'll not do it for you.

From there we'll go over more advanced methods, some other important stuff, and have you create a few more scripts along the way to solidify what you've learned and flesh out ideas of what you can do. And of course, I'll answer any questions and explain anything you're confused about along the way. Near the end of this scripting part (though of course you can ask me about it during the quest design part as well, though well not be focused on it), you can ask me about any scripts you want to create and I'll guide you through them. You can practice as long as you like during this time period to become proficient at scripting.

Sound good? I'll think on a script tonight and tomorrow morning.

Share this post


Link to post
Share on other sites

Okay, apologies this took so long. We're going to begin with a simplish script - one that will add an item to the player every time they click an activator, the amount of items being the amount of times the player has clicked the activator.

Will write up tomorrow, most likely. I've been very sick recently and sleeping a lot.

Share this post


Link to post
Share on other sites

Activator script depending on how many times the player has clicked

Step 1: Setting up the activator

First, find an activator you'd like to use. The easiest one for testing, which Beth used for testing purposes as well, is called WETempActivator. You can find it under WorldObjects>Activators and use the Object Window Filter to search for it by name.

Once you've found it, pull it into any cell in the world. It doesn't matter which, and no need to worry about compatibility. Double click the activator, and go to the scripts tab. You'll have to keep clicking the right arrow until you find the scripts tab.

Screenshot_165.png

Step 2: Making the Script

Once you get here, click Add. Wait a little on the CK, and when a window pops up, press [New Script]. Give your script a name, and keep the Extends part the same.  Then press OK. This will automatically create a script (source) file, which is the editable file, under Data/Scripts/Source. It will also create the "header" for your script:

Scriptname MyScriptName Extends WhatItExtends

So once you've created your script, right click the script on your activator, and press Open In External Editor.

Screenshot_166.png

Since you've associated .psc files with your text editor of choice, this should automatically open the script in that text editor.

Paste in this script, and we'll go over it:

Scriptname TriviaExampleScript extends ObjectReference  
ObjectReference Property ItemToGive Auto 
Int count 
Event OnActivate(ObjectReference akActionRef)
	count += 1
	akActionRef.AddItem(ItemToGive, count)
EndEvent

Firstly, do NOT overwrite your scriptname part (automatically made by the creation kit) with MY scriptname. Each scriptname is unique to the script, and MUST match the actual file name, or there will be compilation errors. Thus, unless you named your script TriviaExampleScript, this will not let your script compile if you outright pasted the entire script in. So replace my script name with your script name first.

So, we declare a property first. 

Type Property PropertyName Flags

The property type says what sort of thing/reference this property points to. You have to know what type of thing your reference is, or you won't be able to fill the property with it. It will simply not show up.

This tells the script it is a property and to treat it as such.

This is how the property is referred to in the script. Something short and sweet (and something that you can associate with the thing) is good here. 

You'll generally just want Auto here. This makes it a normal property which has a value that can be used, and set. No need to really worry about this yet. I'll explain it in a separate lesson.

Then we have our variable. We use an integer variable, because we're just counting numbers with "count", thus the Int part. The name of the variable is count. We didn't make a property, because we didn't need one. If you can easily use a variable instead of a property, you always want to. There's nothing bad about properties, but unless you can't get the reference of something in the script with a variable or you need to use the value of the property from a separate script, you'll want to use a variable. Properties take up more space, and in the case of ObjectReferences, can make an object persistent. There are a few exceptions to this rule, but we'll go over optimization and persistence at a later date.

Our Event is onActivate. This event will be run EVERY TIME this particular activator, WETempActivator in whatever cell you chose, is activated. The stuff in parentheses is a parameter. It is a variable, which you can reference in the script. The variable contains the "value" of the actor that clicked on/activated the activator. We could probably assume this is the player, but just to be safe and because there's no reason not to here, we'll just use the variable akActionRef to reference who did the activating.

The name doesn't have to be akActionRef - you can name it whatever you want, as long as it's in the same order and prefixed with ObjectReference (the type of variable).

Within that event "block", is everything between Event and EndEvent. All this code will be executed when this event is "called" (in this case, when our object is activated). So first, we SET the value of count to the current value of count, + 1.

+= 1 is the same as count = count + 1, just short hand. So we're adding 1 to count. You can find info on other operators here.

Then, we call the function AddItem ON akActionRef. AddItem is a function that will add the specified item (in parentheses), and the amount of items is also specified in parentheses. The . after akActionRef says that this function is being called ON the reference that is akActionRef. The function AddItem is being called ON an ObjectReference, and an Actor is an ObjectReference, thus adding the specified object to the Actor/ObjectReference the function is being called on.

In simple terms, the akActionRef. part says that the item is getting added to the actor that is akActionRef. :)

There are multiple parameters for AddItem. They are:

AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false)

akItemToAdd is of type Form, meaning it could be almost anything. An ObjectReference, a MiscObject, a Weapon, an Armor. This is what will be added to the ObjectReference the function is called on. aiCount is an integer parameter, and a default parameter. That = says that if you don't specify aiCount, it will be 1. abSilent is a boolean (true/false), and whether or not the function will display the little message "____ has been added to Player" when the item is added. By default, it will NOT be silent, thus displaying the message. abSilent is also a default parameter.

We put in this:

AddItem(ItemToAdd, count)

Since we increase count by 1 every time we activate the object, and declaring an int variable automatically defaults its value to 0 unless you set it otherwise, this means that it will add our object to the player the amount of times they've added the item.

If you want to add gold, change the type of our property to MiscObject. Gold is a MiscObject and will not show as an ObjectReference.

Step 3: Hooking up our script to Skyrim

Now compile your script. If you had no properties, then that would be all you needed to do. Since we DO have a property, there's one small, extra step. Go back to the CK, and right click our script on the activator. Rather than pressing Open in External Editor, press Edit Properties. Then, click on ItemToAdd in the window that pops up, and choose the item you want to add from the dropdown. 

Press OK, and go test out your script! 

Apologies for the length. If you feel you didn't need something so in-depth, tell me, or if you feel you need more details then tell me that as well. We may go more in-depth and make this a more complex script later on.

Tell me when you're done and if you have any questions.

Share this post


Link to post
Share on other sites

Ok, everything went as expected until I went to choose the item. It gave me this:

post-5510-0-75196100-1419629718_thumb.pn

So I tried changing the property type to "Book" and I got this:

post-5510-0-19307800-1419629719_thumb.pn

I tested it in game and it seemed to work as it should.

(I had tried the "Form" type as well, but it only gave me two choices: CommandingActorPersistenceForm and PapyrusPersistenceForm).

The last few days have been a bit brain-frying for me, so it's entirely possible I've missed something obvious.

Share this post


Link to post
Share on other sites

ObjectReferences need to be in game, as they're references. Unfortunately. However, you should be able to choose cell (any) and then choose your object as needed. 

Plus, I was incorrect in that property. It's most likely a different type of property. What are you tyring to add?

MiscObject

Book

Weapon

Armor

Share this post


Link to post
Share on other sites
I just set it to add the firebolt spell tome. Here's how the script ended up:
 
Scriptname TriviaScript01 extends ObjectReference  
 
Book Property ItemToGive Auto 
Int count 
 
Event OnActivate(ObjectReference akActionRef)
 
count += 1
akActionRef.AddItem(ItemToGive, count)
 
EndEvent

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×