Shrine of Kynareth

Oblivion. 10% Playing, 90% Modding.

Easy check OBSE function for mods

February 18, 2019 Modding Guides

This is probably old news for everyone dealing with OBSE scripts, but anyway. A lot of mods require OBSE. If the game isn't launched with OBSE, scripts compiled with OBSE functions will not run at all and all kinds of not-so-pretty things can happen. It's a good thing to warn the user that stuff isn't going as planned.
The problem is, if you just add the OBSE function to a normal script to check if OBSE is installed, and OBSE is not installed, the script won't run at all and can't give the user a hint as to what is wrong.

This solution (or rather, a similar one) is used across many popular mods.

1) Create a new quest and name it xxxCheckObseQuest, where xxx should be the name or initials of your mod. For example MyMostFancyModCheckObseQuest.

2) Make sure the quest has set the flag "allow repeated stages".

3) Create a new quest stage and a new log entry. Leave the log entry text empty.

4) Create a new quest script:

scn xxxCheckObseQuestScript

float fQuestDelayTime
short version
short revision

begin gamemode

    if fQuestDelayTime != 60
        set fQuestDelayTime to 60
    set version to 0
    set revision to 0
    SetStage xxxCheckObseQuest 0

    if ( version < 21 )
        MessageBox "YOUR MOD NAME requires OBSE to run. OBSE has not been detected. Exit the game and start it with OBSE."

Again, xxx should be replaced by the same name or initials as before, so for example MyMostFancyModCheckObseQuestScript. You should also replace YOUR MOD NAME with your actual mod name.
I set the fQuestDelayTime high so the script isn't running constantly. The first call after installing the mod will happen in 5 seconds. Most of the time once the user sets up OBSE, they will not suddenly stop using it. You can certainly put the delay time lower, to make sure the user is notified sooner if they suddenly start the game without OBSE.

If you want to stop your mod when OBSE is not detected, you can do that in the same if as the warning MessageBox. If your mod uses arrays or strings that would be destroyed when saving without OBSE (since the .obse cofile would not exist for that save), you might want to make the warning much stronger and boop the user's nose on having to close the game and fix it now.

5) Go back to your quest. Assign the quest script to your quest.

6) Go back to your quest stage. Add a result script:

set xxxCheckObseQuest.version to GetOBSEVersion
set xxxCheckObseQuest.revision to GetOBSERevision

Of course, once again, replace the xxx and don't forget to compile.

7) That's it.
The script giving the error message contains no OBSE functions and only on a successful call of the GetOBSEVersion command in the result script will the error message be suppressed. 

8) Oh this paragraph telling you OBSE will never change aged like milk. OBSE is under development again, so if you are using any new features or fixes that have been added with, for example, xOBSE 22.4, it isn't enough to just check for the OBSE version. You also need to declare a variable for & check for the OBSE revision (that is, the number after the dot). I have added the variable and the check in the quest result script in bold to the code above. You can copy it as it is, even if not using revision check, don't worry.
I have, however, not added it to the the "if version < 21" line. But why?
This is supposed to be a simple script, and for most simple uses, version 21 will still be enough. If you want to add the check for a specific revision, for example 22.4, replace that line with:

if ( version < 22 ) || ( version == 22 && revision < 4 )

In this case, you must absolutely make sure to only check for revision < 4 on version 22. If you would only check for version < 22 || revision < 4, it would also fail for any future xOBSE versions with low revision numbers, like 23.1. Unfortunately there are a bunch of mods that implemented it like this and now, 10 years later, those mods don't work with xOBSE. Don't be like those mods!

9.) Another small note: The OBSE Check Quest will probably be pulled into the Bashed Patch, because it has a stage and no icon, and Wrye Bash has an option to add default icons to records missing them. Perhaps your mod is really tiny and has no reason to be merged and you want to be able to disable it without having to rebuild the patch? Just add "Quest\" as icon path (easiest done in Tes4Edit, because then you don't need to actually have a file at this location).

2021-08-28: Added note about OBSE revision because of xOBSE.


Welcome to my little place where I talk about playing Oblivion, and about modding Oblivion, and about making mods for Oblivion and about ...