Thrones of Britannia outputs a text file called "used_mods.txt" that lists all the mods currently being used. I have written a script file that searches through this list and requires only the scripts that are currently being used. This allows modders to easily make all their scripted mods compatible with one another and doesnt require the user to keep track of which mods are currently enabled.
function fileExists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
function checkLines(file)
if not fileExists(file) then return {} end
for line in io.lines(file) do
local mod_string = SplitString(line,'"')
checkLoadedMod(mod_string[2])
end
end
function checkLoadedMod(mod_string)
for mod, loaded in pairs(my_scripted_mods) do
if mod_string == mod then
my_scripted_mods[mod] = 1
end
end
end
function requireMod()
for mod, loaded in pairs(my_scripted_mods) do
if loaded == 1 then
local string_to_split = SplitString(mod,".")
require_string = "lua_scripts."..string_to_split[1]
require(require_string)
end
end
end
function SplitString(str, delim)
local res = { };
local pattern = string.format("([^%s]+)%s()", delim, delim);
while (true) do
line, pos = str:match(pattern, pos);
if line == nil then break end;
table.insert(res, line);
end
return res;
end
checkLines("used_mods.txt")
requireMod()
if my_scripted_mods["locked_tech_mod.pack"] == 0 then
require("vik_tech_locks");
require("vik_tech_unlocks");
end
In order to use this script for your own mods change the table 'my_scripted_mods' to have keys which correspond to the name of your scripted mods. You will also need to create a lua script in the file lua_scripts with the same name as the mod. In that script you can require all the other files that you need.
The final 'if' statement is necessary to require some of the vanilla mods that one of my mods needs to remove. If you want to make your mods compatible with mine you can require this script and comment out the requirement for "vik_tech_locks" and "vik_tech_unlocks".