Tutorial Old Creating a LeaderLib Integration Script - LaughingLeader-DOS2-Mods/LeaderLib GitHub Wiki
This guide assumes you know your way around story scripting. If you need help getting started, check out this tutorial: Your First Story Script.
Additionally, mod menu registeration requires the mod itself be registered to LeaderLib, so be sure to check out the previous tutorial if you haven't set that up.
Now that your mod is properly registered to the central mods database, you can add a dependency-free integration with LeaderLib by registering an active goal and a mod menu.
Like the last tutorial, our sample mod is called "TestMod_GithubExample", and the author name is "CodeBuddy".
We'll start by creating a new goal called "TestMod_GithubExample_LeaderLib", parented under our main goal.
Thankfully, this script will be even easier than the updater script, as we really need to only register one time.
The easiest way to add support if LeaderLib is installed, it to listen for the main event called "LeaderLib_Initialized". It's safe to assume that if this event is never called, that LeaderLib is not installed.
KB:
IF
StoryEvent(_, "LeaderLib_Initialized")
AND
NOT DB_TestMod_GithubExample_RegisteredLeaderLibSettings(_)
THEN
DB_TestMod_GithubExample_RegisteredLeaderLibSettings(1);
IF
DB_TestMod_GithubExample_RegisteredLeaderLibSettings(1)
THEN
DB_LeaderLib_ModApi_RegisterActiveGoal("TestMod_GithubExample", "CodeBuddy", "TestMod_GithubExample_ZZZ_Updater");
DB_LeaderLib_ModApi_RegisterMenu("CodeBuddy_TestMod_GithubExample", "[TestMod - Github Example] Menu", ""TestMod_GithubExample_MainMenu", "TestMod_GithubExample", "CodeBuddy");
Using two ModApi databases, we can register a menu and active goal to LeaderLib painlessly, and with no strict dependency. The parameters for these databases are:
DB_LeaderLib_ModApi_RegisterActiveGoal(_ModName, _AuthorName, _Goal)
_Goal
is the name of the goal you want to register. This goal should be one that's always active, as LeaderLib will use it to see if your mod is currently running (mods that were registered, and then later disabled, don't have actively running goals)
DB_LeaderLib_ModApi_RegisterMenu(_MenuID, _DisplayName, _Dialog, _ModName, _Author)
This database registers a mod menu with LeaderLib. _MenuID
should be a unique string to your mod (combining the mod name and author name is pretty safe). _DisplayName
is what's displayed in the Mod Menu list, and _Dialog
is the name of the dialog to start when your menu is selected.
The sample script for this tutorial is available here: TestMod_GithubExample_LeaderLib.txt