Zumbs' Blog

The truth may be out there, but lies are inside your head

FOMM and FOMODs for Dummies 7: Load Order Magicks

Posted by Zumbs on November 13, 2009

FOMM and FOMODs for Dummies

  1. Installing Mods
  2. Making FOMODS
  3. Basic FOMOD Scripting I
  4. Basic FOMOD Scripting II
  5. Working with Forms I
  6. Working with Forms II
  7. Load Order Magicks

In a earlier tutorial, installation of compatibility patches were controlled by the mod user. It would, however, be nice if we could detect if the player had a mod installed, so we could set a good default. If a compatibility patch is to be installed, we may also want to manipulate the load order so that it is correct, instead of pushing the responsibility onto the shoulders of the mod user.

Simple manipulations

If your mod requires that the plugins are placed in a particular order w.r.t. each other, but can be loaded anywhere, the easiest way to control the load order is to use InstallFromFOMOD in the correct order. So if your mods must have the order

foobar.esm
foobar.esp
foobar-addon1.esp
foobar-addon2.esp
foobar-addon3.esp

simply install them in the correct order

InstallFromFOMOD("foobar.esm");
InstallFromFOMOD("foobar.esp");
InstallFromFOMOD("foobar-addon1.esp");
InstallFromFOMOD("foobar-addon2.esp");
InstallFromFOMOD("foobar-addon3.esp");

FOMM load order functions

FOMM comes with a number of functions to manipulate load order:

public static void SetPluginActivation(string pluginName, bool activate);

This function allows you to activate or deactivate a particular plugin.

public static string[] GetActivePlugins();
public static string[] GetAllPlugins();

These functions returns an in-order string array of either all active plugins or all plugins in the data folder.

public static void SetLoadOrder(int[] plugins);
public static void SetLoadOrder(int[] plugins, int position);

These two functions can be used to set the load order. The first one forces a load order, and the other moves the mods at the index positions specified in plugins to the position. There are, however, a number of cavities. Both functions work on the full list of mods (GetAllPlugins), and they use indexes. So, to use them, you would need to call GetAllPlugins(), search the list for the mods that you wish to move and record their index, and then perform the move.

Usually, we want to ensure that a particular mod is loaded before or after another. As an example, our mod somemod.esp had conflicts with FOOK2. This can be solved with a compatibility patch “somemod-FOOK2-compatibility-patch.esp”. Thus, we would like a load order of the form

somemod.esp
FOOK2 – Main.esp
somemod-FOOK2-compatibility-patch.esp

Detecting plugins

The following function can be used to investigate if a function is active:

public static bool IsPluginActive(String pluginName)
{
    string[] loadOrder = GetActivePlugins();
    for (int i = 0; i < loadOrder.Length; ++i)
    {
        if (loadOrder[i].Equals(pluginName, StringComparison.InvariantCultureIgnoreCase))
             return true;
    }
    return false;
}

This could be used to set a reasonable default value, such as

InstallFookCompatibilityCheckBox.Checked = IsPluginActive("FOOK2 - Main.esp")

Adjusting load order

As noted above, FOMMs default functions for manipulating load order are somewhat clunky to work with. What we want is something like

if(IsPluginActive("fook2 - main.esp"))
{
    PlaceBeforePlugin("FOOK2 - Main.esp", "mod-base.esp");
    PlaceAfterPlugin("FOOK2 - Main.esp", "mod-FOOK2-compatibility-patch.esp");
}

The functions needed, are shown below:

public static int GetPluginIndex(String pluginName)
{
    string[] loadOrder = GetAllPlugins();
    for (int i = 0; i < loadOrder.Length; ++i)
    {
        if (loadOrder[i].Equals(pluginName, StringComparison.InvariantCultureIgnoreCase))
            return i;
    }
    return -1;
}
public static void PlaceAtPlugin(String targetPlugin, String pluginToMove, int offset)
{
    int targetPluginIndex = GetPluginIndex(targetPlugin);
    int pluginToMoveIndex = GetPluginIndex(pluginToMove);
    if (targetPluginIndex != -1 && pluginToMoveIndex != -1)
    {
        int[] pluginIdxArray = { pluginToMoveIndex };
        SetLoadOrder(pluginIdxArray, targetPluginIndex + offset);
    }
}
public static void PlaceAfterPlugin(String targetPlugin, String pluginToMove)
{
    PlaceAtPlugin(targetPlugin, pluginToMove, 1);
}
public static void PlaceBeforePlugin(String targetPlugin, String pluginToMove)
{
    PlaceAtPlugin(targetPlugin, pluginToMove, 0);
}

These functions allow us to place one or more mods at a reasonable place in the load order of the user.

6 Responses to “FOMM and FOMODs for Dummies 7: Load Order Magicks”

  1. Sean Ramsey said

    This is an outstanding piece of work! Thank you, so very much! FOMM – like OBMM before it – is a superb example of programming genius. I can’t imagine the dedication that one must have, to pull it off!
    My only question, Zumb, is why isn’t this included with Timeslip’s release? At least a link pointing to your blog…

    This is, indeed, an extraordinary contribution to the Fallout 3 community! You deserve many kudos for all of the hard work and time that went into this! Again, my sincere thanks!

    Sean.

    • Zumbs said

      Thanks alot! While it did take some work figuring out how stuff worked, there were a few scripts out there earlier that helped me a lot. Notably the install scripts for DarNs UI and Breezes male bodies. Also, I had the fortune of significant C# and .NET experience, so getting a grip on this weren’t as difficult as it sounds.
      My only question, Zumb, why isn’t this included with Timeslip’s release? At least a link pointing to your blog…
      There is a link from the FOMM page at Fallout3Nexus, and I posted links to the tutorials in the Help forum at Sourceforge, so it should be possible to find them :) FYI, karburke has taken over development of FOMM ;)

  2. ladyshade said

    Where can we see the actual API for fomm.Scripting? Rather than just copying and pasting commands used by other people I’d like to see what the rules are for everything and what the parameters actually mean.

    • Zumbs said

      Back when this post was written, the only real option was to download the source code from sourceforge. I learned from looking at other peoples install scripts and making my own, many experiences richer. As there was little documentation, I ended up compiling this series of posts to help others (who may not have the same background as I have) to make simple installers.

      • ladyshade said

        Well I’m certainly happy for what you’ve provided. And I had to do the same as far as checking the source code in the repo. I just feel like I missing some aspects here or there and I’m not always sure which of the methods I see in the source code are in scope when the scripts execute. Perhaps we could team up and provide some official reference for the functions.

        Another big issue is that not everything seems to be supported in the Nexus Mod Manager vs. Fallout Mod Manager.

        • Zumbs said

          A number of tools were removed, e.g. the BSA browser/creator, TES snip and interaction with some of the other tools out there. I’m unsure to which degree the scripting engine has changed – I have only been a mod user for New Vegas and Skyrim, so I haven’t used the scripting capabilities.

          It is my impression that some of the later versions of FOMM also included the ability to specify install options in a handy xml format, similar to the one used by MMM and FO3 Wanderers Edition. Again, I am unsure how much got into NMM. It’s on sourceforge, so I guess it is possible to take a look at the source code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: