Creating Mods - itb-community/ITB-ModLoader GitHub Wiki
Table of Contents
init.lua
Each mod is defined by its init.lua file. This file must exist in scripts/init.lua path in your mod's root directory, or mod loader will be unable to load it.
The file, when executed, must return a table with following fields:
| Field | Description |
|---|---|
id |
Mod id. A string that is supposed to uniquely identify your mod, and shouldn't change as you release updates to it. |
name |
Name of the mod displayed to the user. |
description |
Description of the mod displayed to the user. Optional. |
version |
A freeform string with mod's version. |
modApiVersion |
Minimum version of the mod loader the mod requires to function. Optional. |
requirements |
A table with mod ids of other mods. This will cause those mods to load before yours. |
submodFolders |
An optional table with paths relative to the root path of this mod, containing additional mods. Mainly to be used for modpacks or for organizing mods. |
enabled |
Whether the mod should be enabled by default. Optional, true by default. |
metadata |
The metadata function. |
init |
The init function. |
load |
The load function. |
metadata function is always executed, regardless of whether the mod is enabled or not, and is called before init and load. Its intended usage is for setup of the mod's icon, configuration options, and similar things. Its arguments are:
| Argument | Description |
|---|---|
self |
The mod object. |
init function is called by mod loader after metadata, if the mod is enabled. It is called only once, when the game starts. Its arguments are:
| Argument | Description |
|---|---|
self |
The mod object. |
options |
Mod options table. |
load function is called after init, if the mod is enabled. It is called multiple times during the game: when the game first starts; when beginning a new game; when continuing a game in progress; when resetting turn. Its arguments are:
| Argument | Description |
|---|---|
self |
The mod object. |
options |
Mod options table. |
version |
Mod version, the same as the version specified in the mod object. Not used for anything at the moment. |
The self object, passed as first argument to all three functions, is the table you previously returned from init.lua with following useful fields added:
| Field | Description |
|---|---|
resourcePath |
Path to mod's root directory. |
scriptPath |
Path to mod's root script directory - which should be equivalent to self.resourcePath.."scripts/". |
path |
Path to mod's init.lua file. |
dir |
name of the mod's directory inside game's mods directory. |
Example:
local function metadata(self)
LOG("Mod's metadata is being fetched!")
end
local function init(self, options)
LOG("Mod is being initialized!")
end
local function load(self, options, version)
LOG("Mod is being loaded!")
end
return {
id = "SampleMod",
name = "Sample mod",
description = "Description of the sample mod",
version = "1.0.0",
modApiVersion = "2.6.2",
requirements = {},
metadata = metadata,
init = init,
load = load,
}