Results 1 to 2 of 2

Thread: Scripted Mod Compatibility Guide

  1. #1

    Default Scripted Mod Compatibility Guide

    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.

    Spoiler Alert, click show to read: 
    my_scripted_mods = {["basic_estate_mod.pack"] = 0,
    ["more_war_weariness.pack"] = 0,
    ["locked_tech_mod.pack"] = 0}


    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".

  2. #2

    Default Re: Scripted Mod Compatibility Guide

    Very interesting and useful for compatibility!

    ----> Website -- Patreon -- Steam -- Forums -- Youtube -- Facebook <----

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •