Jump to content

[Script Tutorial] Script initialization on game load


grey79

Recommended Posts

Here is how you have your script run when the game is started

 

So you have a script that needs to be run?

An example of this could be:

 

Scriptname MyModsInstallScript extends Quest

Function Init()
; My code runs here ...
Debug.MessageBox("The mod has been installed")
EndFunction

How do we get the game to run this? We create an empty quest.

 

1. In the Object Window, go to Character>Quest and create a new quest.

2. You'll be on the "Quest Data" tab first - create a unique ID here for the quest. Leave everything else as the default - no need to enter a quest name.

3. Go to the last tab - Scripts - and include MyModsInstallScript. NOTE: It is important that your script extends Quest, or it wont work.

4. Go to "Quest Stages" and create a new index. The default of 0 is fine, then create a new "log entry".

5. Tick "Startup Stage" and "Complete Quest".

6. In the "Papyrus Fragment" section, choose MyModsInstallScript in the dropdown. kmyQuest is a variable that now holds your quest script reference (MyModsInstallScript) (if it is grayed out, save the quest and reopen).

7. In the text box below enter "kmyQuest.Init()" (without quotes) and press compile. If it doesn't complain, you can click OK.

8. Save, and run the game.

 

When you load your save you should get a popup saying "The mod has been installed".

There is no entry in the quest log of the quest ever existing.

 

Thats it.

 

Thanks goes to Ocyris for pointing me in the right direction

 

Ps. I've been told that if you don't tick "Complete Quest", the quest will run at every game start, and every game load. Can anyone verify this?

Edited by grey79
Link to comment
Share on other sites

Maybe it's a bug.

Sometimes you need to create an object and the reopen it (edit) for all the options to show up.

But if you are saying that it crashes when you do that, I suggest you take an existing quest - copy it, and then just change everything to your liking.

Link to comment
Share on other sites

Aye, yer right. Had to create a new quest, click OK, then re-open it and then do your steps :3

 

Edit: I get these errors when I click compile :

 

C:\Program Files\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\QF_AAAHungerQ_010012D1.psc(8,0): variable kmyQuest is undefined
C:\Program Files\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\QF_AAAHungerQ_010012D1.psc(8,9): none is not a known user-defined type
No output generated for QF_AAAHungerQ_010012D1, compilation failed.

 

What should I do? :P

Edited by GomuGomu64
Link to comment
Share on other sites

  • 1 month later...

When I use the method described here, it works when I load a fresh save without the mod. However, If I then save again AFTER the mod has been installed, and load that save with the mod again, it says "MyQuest Completed" in big letters on the screen and plays the quest complete sound.

 

Why is it completing the quest and how can I stop it from doing that?

Link to comment
Share on other sites

I think that if you don't tick "complete quest", but instead write in papyrus fragments stop(), the quest will stop running when reaching the stage 0.

 

So i think it will prevent from displaying "quest completed" and will also avoid having the message at every load.

 

I'm not sure about that, but using logic it may work

Link to comment
Share on other sites

  • 2 weeks later...
Thanks for the tutorial! I'm having a bit of trouble making my quest start when I load a pre-existing save. After following the above instructions, the quest will run when I start a new game, but I'm trying to make a quest that will start and run on any save game as long as the .esp is loaded. Any help would be greatly appreciated! Thanks.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...