-
Notifications
You must be signed in to change notification settings - Fork 0
4. Making your first mod
In the Mods folder, create a folder and name it however you want, it will be named MyMod
in this tutorial. Inside, create 3 files :
modfile.txt
config.lua
main.lua
Open modfile.txt
and type the following :
Top Import "config.lua"
Import "main.lua"
This is the file that tells Mod Importer how to install your mod.
Then, open config.lua and type the following :
local mod = ModUtil.Mod.Register("MyMod")
mod.Config = {
Enabled = true
}
This file will contain your mod's configuration settings, which the user will be able to change. The Enabled
setting lets you turn on and off your mod without having to uninstall it.
Open main.lua
and type the following :
if not MyMod.Config.Enabled then return end
This file will contain your mod's code. If Enabled
is set to false in your config, then none of it will run. Make sure you write your code after the if statement.
For now the mod doesn't do anything, so add this code :
if not MyMod.Config.Enabled then return end
OnAnyLoad{ "DeathArea", function (triggerArgs)
DebugPrint({Text = "Hello World!"})
end}
Next, make sure you saved all your files and run modimporter then start your game and load your save.
Press CTRL+D, and if you started your game in debug mode and you are in the House of Hades, you should see this :
OnAnyLoad
is an engine trigger, more commonly referred to as an event, that happens whenever a map is loaded.
We pass it the argument DeathArea
, which is the internal name for the House of Hades map. This means we only want our code to run if it loads this map.
Then the second argument passed is a function, with the generic argument triggerArgs
. You can ignore the triggerArgs
as it's not relevant here.
This function is the code that will be executed when the event occurs.
DebugPrint
is an engine function, meaning it is defined in the game's engine and not in LUA. It takes as argument an object which is why we put curly brackets inside the parentheses.
Inside that object we define Text
, and that is what this function displays in game.
From this basic mod you can do a ton of things, and it's a good idea to experiment. Look at existing mods and the game code in the Scripts
folder and try modifying them from your mod, as it's good practice for the future.