Modding (Civ6)/Basic Mod/DLC Compatibility

Sometimes when you are making changes to the game, you need to make sure that your mod will work with other mods. Some people might have other mods or not have a DLC (which the game interprets as a mod,) and you want to make sure that your mod will work for your user no matter what they have.
Sometimes its obvious that your mod is an addition to another mod/DLC and it requires the other to be loaded. Otherwise, in many cases you can add some basic mod compatibility into your mod using SQLite Triggers. These are pieces of code that will only be run after something you specify happens. Create a new SQL file for your mod project. Here is the command we will be using:
CREATE TRIGGER SomeNameForYourTrigger
AFTER INSERT ON Table
WHEN New.Column1=A
BEGIN
<Commands to do when trigger is fired>
END;
Let's look at how this statement is constructed:
CREATE TRIGGER SomeName This just creates the trigger and assigns it a name. Make sure the name is unique.
AFTER INSERT ON Table This is what causes the trigger to be fired and when to perform the operation. In this case, the trigger fires after a new row is inserted into 'Table'. Alternatively, you can have the trigger do something before the operation occurs, with BEFORE INSERT ON Table. You can also have the trigger fire before/after an UPDATE on the table, but in the case of mod compatibility its usually after inserts.
WHEN New.Column1=A This further specifies that the trigger should only fire when the new row inserted into the table has a value of A for column 'Column1'.
BEGIN <Statements> END; These are the statements you want to execute when the conditions for the trigger are met. The statements can include the usual basic queries:
INSERT INTO Table (Column1, Column2) VALUES (A, B);
UPDATE Table SET Column1=A, Column2=B WHERE Column3=C;
DELETE FROM Table WHERE Column1=A;
Example 1 (Mod): Lets say we are removing missionaries from the game, just like in the example for removing base game content. Many people have another mod that adds a bunch of cool stuff to the game. However, one part of this mod also adds missionaries to a new ability class. If people try to load this mod and our mod at the same time, it won't work because we deleted the missionary data from the game tables in our mod! We can solve this issue by having SQLite triggers handle the inserts of the other mod:
-- In this trigger, we insert the missionary back into types right before the other mod tries to reference the type to avoid an error.
CREATE TRIGGER CNO_OnIncompatibleMod_Before -- It's not a bad idea to put your initials on variable names
BEFORE INSERT ON TypeTags -- Will trigger EACH time before a row shows up in the TypeTags table in some XML or SQL database, either in the game, DLC, or mod.
WHEN New.Type = 'UNIT_MISSIONARY' -- But only actually triggers when the new row has 'UNIT_MISSIONARY' in it's Type column.
BEGIN INSERT OR REPLACE INTO Types(Type, Kind) VALUES ('UNIT_MISSIONARY', 'KIND_UNIT'); END;-- Insert (or overwrite) the missionary Type back into the database because the mod will try to reference it.
-- In this trigger, we re-delete stuff right after the game/DLC/mod's change.
CREATE TRIGGER CNO_OnIncompatibleMod_After
AFTER INSERT ON TypeTags -- This time, we are doing something right after.
WHEN New.Type = 'UNIT_MISSIONARY
BEGIN
DELETE FROM Types WHERE Type='UNIT_MISSIONARY'; -- Delete it from Types table again.
DELETE FROM TypeTags WHERE Type='UNIT_MISSIONARY'; -- And undo the mod's changes.
END;
Now with these triggers, people who have your mod enabled will also be able to load the other mod and enjoy all of its other features.
Example 2 (DLC): Lets say that we are adding a unit with a new type of ability class. Most of our mod deals with base game content, but for our new unit's ability class, we want to give it the ability to receive the Spear of Fionn ability from going next to the natural wonder. However, this is a wonder that was added in a DLC. If we just add this directly to our mod, then users of our mod that don't have the Vikings DLC won't be able to load the mod! We can handle this with an SQLite trigger:
-- Add Spear of Fionn Ability if Vikings DLC is enabled.
CREATE TRIGGER CNO_onVikingsDLC
AFTER INSERT ON Types -- Once whatever we need is defined in Types, we can reference it in our mod.
WHEN NEW.Type = 'ABILITY_SPEAR_OF_FIONN -- The type reference we need.
BEGIN
INSERT INTO TypeTags (Type,Tag) VALUES ('ABILITY_SPEAR_OF_FIONN', 'CLASS_NEW_UNIT'); -- Attach the ability to our new unit class (see UnitAbilities.xml).
END;
Now people with the Vikings DLC will have the new unit able to gain this ability, while people without the Vikings DLC will still be able to load your mod and enjoy its other features.
It takes some digging through the other mod's files and some testing to make your mod compatible with it, but its worth it if people can use your mod with other mods that they enjoy.
Category:Modding (Civ6)