Start Game Enabled Quest Script (or a script that just runs)

Post » Mon Jun 18, 2012 12:23 pm

So, this really baffled me at first:

How to create a start-game enabled Quest and attach a script that just runs...

I'm sure you've seen this in many mods for FO3 (and in all probability Oblivion, but I've never played that so I'll stick to referencing fo3/geck). Ok. In the Geck, to have a script that just runs and does stuff, we created a Quest, checked the Start Game Enabled Box and attached a script.

A script might look something like:

scriptname myScriptbegin GameModeshowmessage myAwesomeMessageend

But, as I'm sure many have discovered, things are just a little bit different in the CK...

Now, all this might be totally inefficient coding and go about things the wrong way (or not, I don't know at this stage). But the resulting script compiles without error and does what I wanted it to do. So, bear with me. Here we go...

So, in the CK, we create a new Quest:
  • In the Object Window, open the Character node (the "+" symbol) and click on Quest.
  • Right-Click in the right-hand pane, and select New.
  • This will open the Quest window.
  • Click in the ID box and give it an ID. For eg, aaTestQuest.
  • Do the same in the Quest Name box.
  • Ensure the Start Game Enabled box is ticked.
  • This Quest will now start when you start the game.
  • Hit OK to close the Quest window. Then reopen the Quest by double clicking it in the Object Window. If we don't do this now, we'll crash the CK later on after creating our script. Which is baaad... !
Next we need a script.
  • Click the "Scripts" button/tab.
  • Click Add.
  • After a brief pause a new window will pop up. Double click on [New Script].
  • An Add New Script window will pop up.
  • Give the script a name. For eg, aaTestQuestScript and hit OK.
  • Now we need to edit the script.
  • In our Scripts tab, we should now have an entry for the script we just created (aaTestQuestScript)
  • Right click on that and select Edit Source.
  • This brings up the Editing script window.
The script has already been started with:

Scriptname aaTestQuestScript extends Quest

Since the Quest we've created this script with is Start Game enabled, the script will run straight away. But to get things going for real, we need some initilization:

EVENT onInit()	registerForUpdate(3)	gotoState ("stuff")endEVENT

onInit (http://www.creationkit.com/OnInit) is the Event called when the script has been created (and when "properties are initialized" - whatever that means... - for now, don't worry about it).

registerForUpdate (http://www.creationkit.com/RegisterForUpdate_-_Form) lets us declare how often we want the script to run (in seconds). registerForUpdate(3) then, means the script will run every 3 seconds.

gotoState http://www.creationkit.com/States_%28Papyrus%29 appears to be a form of "goto" command. The script, when it gets to this line, will goto the State as defined in the brackets.

So we need to make a state called "stuff" and put stuff in it. :wink:

STATE stuff		EVENT onUpdate()					Debug.MessageBox("Hello, World!")	endEVENTendSTATE

So, here have a state called "stuff". Within that we have an onUpdate Event, which is executed as defined by our earlier registerForUpdate command. So, according to our script so far, every 3 seconds the code within EVENT onUpdate() will execute. http://www.creationkit.com/OnUpdate_%28Papyrus%29

Altogether, our code will look like this:

Scriptname aaTestQuestScript extends QuestEVENT onInit()	; This event will run once, when the script is initialized	registerForUpdate(3)	gotoState ("stuff")endEVENTSTATE stuff		EVENT onUpdate()					Debug.MessageBox("Hello, World!")	endEVENTendSTATE

Which you'll see when you get in game displays "Hello, World!" in a message box.
  • Anyway, from the Build menu of the Script Editor, select Compile (or hit Ctrl+f7).
  • The script compiles without error.
  • Goto the File menu and select Save (or hit Ctrl+S).
  • Close the Script Editor (File>Exit or hit the top-right corner close button).
  • Then hit OK on the Quest window.
  • From the Creation Kit menu, do File>Save.
  • Give the file a name "myAwesomeTestMod" or something, and hit Save.
  • Close the Creation Kit.
  • Then, Launch Skyrim.
  • Click Data Files in the Launcher and ensure "myAwesomeTestMod" (or whatever you called) has a tick next to it, and hit OK.
  • Click Play to launch the game.
As soon as you load a save, the Quest in the mod begins which runs the script, which displays a messagebox on the screen. Hit "Ok" on the message box, wait a few seconds, and the message displays again.

This will continue until you quit the game, so do that before it drives you mad (hit Ok then press Escape before it pops up again). :wink:

And we're done.

Hopefully, that made some kind of sense. But don't take this as written in stone. There may be other (better) ways to achieve the same thing. But at least it's a start.

~Xeph'
User avatar
Carlos Vazquez
 
Posts: 3407
Joined: Sat Aug 25, 2007 10:19 am

Post » Mon Jun 18, 2012 2:07 am

Thanks for posting this. It's the first thing a lot of people (read, I) will want to do, and the CK Wiki isn't helpful.
Fortunately for me, I managed to work it out eventually, and came up with much the same method as you did. Does that make it the optimal method? We can be wrong together.

I'd just like to add that if you want an event triggered, for example, every hour of game time, you can use registerForUpdateGameTime(x), where x is in fractions of an in-game hour.
Oh, another thing: I don't think the STATEs are actually necessary. It's probably good practice to use them, though.
User avatar
Sophie Louise Edge
 
Posts: 3461
Joined: Sat Oct 21, 2006 7:09 pm

Post » Mon Jun 18, 2012 11:49 am

Thanks I was looking for this. Me and a hundred million other people I bet.
User avatar
Nicholas C
 
Posts: 3489
Joined: Tue Aug 07, 2007 8:20 am

Post » Mon Jun 18, 2012 7:02 am

Excellent guide, was just looking for this today - this should go on the creation kit wiki
User avatar
Rebecca Dosch
 
Posts: 3453
Joined: Thu Jan 18, 2007 6:39 pm

Post » Mon Jun 18, 2012 12:40 am

:smile: Well, what do you know, Duckinabox is right - you don't actually need the "States" stuff to make this work (to be perfectly honest I don't actually know what they are... :q ).

I could have sworn that when I already tried without it, the script wouldn't compile/do anything, but I may have done something else wrong... :S

Anyway, I may have some other (basic) things to share later. :smile:

Edit: Oh, and it's probably much easier, if you don't close the Creation Kit (simply because it takes a while to load up again - which is just going to eat up time during development.
User avatar
Damien Mulvenna
 
Posts: 3498
Joined: Wed Jun 27, 2007 3:33 pm


Return to V - Skyrim