Skyrim

Overview
In Time Flies version 2.0, big changes have been made to the code structure.
I implemented a "framework" in order to make it easier to add support for other mods, so you don't have to mess with the main script or care about stuffs other than the mod you want to support.

At the moment, Time Flies consists of these quests (and scrpits in brackets):

  • TimeFlies (TimeFliesMain, TimeFliesMCM, TimeFliesPlayerAlias)
  • TimeFliesModHandler (TimeFliesMods)
  • TimeFliesSupportForHearthfire (TFHearthfire)
  • TimeFliesSupportForCampfire(TFCampfire)
  • TimeFliesSupportForINeed(TFiNeed)

Quest TimeFlies contains core functions and MCM UI stuffs. Quest TImeFliesModHandler works as a middleware, or a "framework", controlling all mod support scripts. And the others provide support for Hearthfire, Campfire (Frostfall 3) and iNeed.

So if you want to add support for a mod, you need to do these steps:
  • Add a new quest containing the mod supporting script, add properties linked to TimeFlies.
  • Edit this script with all the stuffs related to that mod in a certain way (explained later) and compile it.
  • Add a new property linked to your quest in TimeFliesModHandler.
  • Edit TimeFliesMods.psc to call functions from your script and compile it.
  • Done. Enjoy!

Requirements
Of course you always need Creation Kit (or Crashation Kit) to compile scripts and edit esp file itself.
Other than that, you need SkyUI SDK (I use 5.1) and FISS. (FISSFactory.pex and FISSInterface.pex seem to be enough for compiling)

Write Your Script Step by Step
Let's take the Campfire supporting as an example. (Check TFCampfire.psc)

New Quest and New Script
First of all, create the quest with any name you like and then attach a new script.
Then add 2 properties with types of TimeFliesMain and TimeFliesMCM to this script, name them main and mcm, fill them both with the quest TimeFlie. You need those 2 properties to access functions from main script later.

Prepare Variables
Usually, you need a variable to store the index number of the mod you want to support. In TFCampfire.psc, that's int prefix.
Then you need some variables to store some settings like how long should it takes to made a tent or a backpack. These could be float, bool or int. For example, float small_tent_crafting_hour.
And you need some UI elements like slider or checkbox to access them in MCM. MCM stores those elements' ids as integers. For example, the id of the slider to change the time needed to make a small tent, int small_tent_crafting_hour_id.
Also, if you get a item from crafting, you need to know whether it comes from that mod or not. In TFCampfire.psc, I used many Form variables like Form cook_pot, Form[] backpacks and etc.
In the case of Campfire, I also need to know if player is separating backpack or removing a bed roll from tent. So I added some bools to store those states.

Function initialize()
In this function, you should acquire the mod index number by calling main.get_prefix(), initialize those state-related bools and fill those Form variables.

Function load_defaults()
Define your default settings in this function. Fill the related variables.

bool Function handle_added_item(Form item)
Called when player gets an item through crafting.
Check if the item comes from the mod you want to support. If it does, check exactly what it is and then pass the proper length of time.
If the item is handled here, return True; else return False and let others handle it.

bool Function handle_removed_item(Form item)
Called when player loses an item through crafting.
Usually you don't need to implement this function.
In TFCampfire.psc, I determine whether player is separating a backpack by checking if a backpack with amulet is removed.
If the item is handled here, return True; else return False and let others handle it.

Function save_settings()
Use mcm.fiss to save setting-related variables' values to an xml file.

Function load_settings()
Use mcm.fiss to load varaibles' values from an xml file.

bool Function handle_page(string page)
Draw your MCM page in this function.
But first, check if player does enter the page of the related mod.
If yes, use mcm to add UI elements, then return True at the end.
If no, return False and let others handle this page.

bool Function handle_option_selected(int option)
Called when a checkbox or button-like string is clicked.
Check if this option belongs to this part and then do related stuffs.
If the option is handled here, return True; else return False and let others handle it.

bool Function handle_option_slider_opened(int option)
Called when a slider box is open.
Check if this option belongs to this part and then do related stuffs.
If the option is handled here, return True; else return False and let others handle it.

bool Function handle_option_accepted(int option)
Called when a slider box is closed and player accepted the value changing.
Check if this option belongs to this part and then do related stuffs.
If the option is handled here, return True; else return False and let others handle it.

bool Function handle_option_set_default(int option)
Called when player resets a option to its default value.
Check if this option belongs to this part and then do related stuffs.
If the option is handled here, return True; else return False and let others handle it.

bool Function handle_option_highlighted(int option)
Called when player moves cursor to an option item.
Check if this option belongs to this part and then do related stuffs.
If the option is handled here, return True; else return False and let others handle it.

Edit TimeFliesModHandler and TimeFliesMods.psc
Job almost done.
Now add a property with the type of that supporting script you just wrote in quest TimeFliesModHandler's script, that is TimeFliesMods.psc, and link it to the quest you created above.
Open TImeFliesMods.psc, in prepare_pages(), add a MCM page with a name related to the mod you want to support. Then call your functions from TimeFliesMod.psc's related parts with other mods.
You don't need to implement update() unless you want a "smooth" updating experience. In that case, you need to increase the version number in TimeFliesMCM.psc's GetVersion() function and call your initialize() and load_defaults() in update(), which you can easily achieve by clicking "Load Defaults" or "Reinitialize" in MCM or initializing those variable with values from the begining.

Save TimeFlies.esp and Compile Scripts
It's finally over. Enjoy yourself!

Article information

Added on

Edited on

Written by

dfxyz1

0 comments