How to make a game mod - Outerra/anteworld GitHub Wiki

In Outerra, a mod is a folder inside game/mods. Outerra reads a small config file in this folder, mod.cfg, and from it knows the name of the mod and which main script to run. Everything else, like HTML menus, key bindings and maps, goes into the same folder.

Right now all mods are in game/mods. In the future, games and other mods will have separate folders.

There are 3 kinds of mods:

  • a game mod is a whole game, with its own scripts and maps. It is also called a game.
  • a mod for a game (also called a submod) is made for one specific game. It doesn't change the game, it only adds new content to it, for example new vehicles, new specific things for that game mod like zones.
  • a content mod is not made for one game, it works with every game mod. For example a UI mod: the player turns it on when starting a game, and it works in the sandbox, in Transport Minigame and in other games.

This page is mostly about game mods, you will see how to make one from zero. Mods for a game are in section 5, and content mods are explained shortly in section 4.4. As an example we use Transport Minigame, a game mod where the player delivers cargo with trucks.

What is on this page:


1. What is in a mod

A mod is a folder in game/mods. This is the folder of Transport Minigame:

game/mods/transport_minigame/
β”œβ”€β”€ mod.cfg                  the config file of the mod
β”œβ”€β”€ transport_minigame.js    the game script
β”œβ”€β”€ ...                      other script files the game script includes
β”œβ”€β”€ www/                     HTML menus
β”œβ”€β”€ defaults/
β”‚   └── iomap/               custom key bindings
β”œβ”€β”€ templates/               maps of the game
β”œβ”€β”€ preview_images/          pictures for the launcher
└── thumbnail.jpg            small picture for the launcher
Part What it is
mod.cfg the only file every mod needs. It says the name of the mod and which main script to run (section 2)
scripts the code of the mod, for example the game script
www/ the HTML menus. The game script opens them with open_window("www/...")
defaults/iomap/ custom key bindings, see the "How to make custom keybinding" page
templates/ maps that belong to the mod (section 3)
pictures thumbnail.jpg and the preview_images folder, shown in the launcher

You only need the parts your mod uses. A small mod can have just mod.cfg and one script.


2. mod.cfg

2.1 Example

This is the mod.cfg of Transport Minigame:

scripts = ["transport_minigame.js"],
category = "game",
name = "transport_minigame",
unique_id = "C0r29oRNvQwn-R8R+dXU",
thumbnail_image = "thumbnail.jpg",
description = "Transport minigame is a highly detailed, open-world transport and logistics simulation ...",
preview_images = ["preview_images\1.jpg", "preview_images\2.jpg", "preview_images\3.jpg"]

Every line is name = value, and the lines are separated with commas.

2.2 Fields

Field What it is
scripts the main script Outerra runs when the mod starts. For a game mod, this is the game script. Other script files are included from the main script, you don't add them here
category what kind of mod it is. A game is "game", a map of a game is ".template" (section 3)
name the name of the mod
unique_id an ID that is different for every mod. Other files use it to point to this mod. Outerra creates it for you, you don't write it yourself
thumbnail_image the small picture of the mod
description a text about the mod
preview_images list of bigger pictures of the mod

The file paths in mod.cfg are inside the mod's folder. So "thumbnail.jpg" means game/mods/your_mod/thumbnail.jpg.


3. Maps (templates)

3.1 What a template is

A game mod can have its own maps. They are called templates and they go into the templates folder, one folder for every map. Transport Minigame has 3 maps:

templates/
β”œβ”€β”€ Kiyoska/
β”œβ”€β”€ Moon_test/
└── Tatrolia/

A map doesn't have to be on Earth. Moon_test is a map on the Moon.

Inside a map folder there are these files:

templates/Moon_test/
β”œβ”€β”€ mod.cfg                         the config file of the map
β”œβ”€β”€ game.cfg                        settings of the map, like the planet
β”œβ”€β”€ banner.jpg                      picture of the map
β”œβ”€β”€ cache/                          data Outerra needs to load the map
β”œβ”€β”€ campos/                         data Outerra needs to load the map
└── transport_minigame_zones.js     a file only Transport Minigame uses (see 3.3)
File What it is
mod.cfg name of the map and which game it belongs to (see 3.2)
game.cfg settings of the map. For example planet = "moon" for a map on the Moon
banner.jpg the picture the launcher shows when this map is selected
cache/, campos/ the data of the map, what was built on it. Outerra creates this data when you make the map in the game, and you copy it here (see 3.4)

A game mod doesn't need a template. If it has none, Outerra loads the world by itself and saves it in the cache.

3.2 The mod.cfg of a template

Every map folder has its own mod.cfg. This is the mod.cfg of Moon_test:

category = ".template",
description = "Moon template for Outerra Transport Minigame",
name = "Moon_test",
unique_id = "yU+uNU7gQ9UOBkhD9cwR",
template_game_uid = "C0r29oRNvQwn-R8R+dXU"
Field What it is
category ".template", so Outerra knows this is a map
name, description name and text of the map
unique_id the ID of this map
template_game_uid the unique_id of the game this map belongs to. Here it is the ID of Transport Minigame

template_game_uid connects the map to the game. If it is not the same as the game's unique_id, the map doesn't belong to the game.

3.3 Files that belong to the game

A map folder can also have files that only your game uses. Transport Minigame keeps the zones of every map (gas stations, factories, the start position…) in a file called transport_minigame_zones.js inside the map folder. When the game starts, the game script reads this file from the active map:

// In on_initialize() of the game script: read the zones file of the active map
let raw = this.get_file_content("transport_minigame_zones.js", 0);

This way every map has its own zones, but the game script is the same for all maps.

3.4 Making your own map

Every mod has its own unique_id, so Outerra keeps a separate cache and campos for every mod. When you make a map, Outerra saves it there, not in your template folder. So you need to copy it into the template yourself:

  1. Create the map folder in templates with its mod.cfg (see 3.2). At this point the folder has no cache and campos.
  2. Start the game with this map and build your map in the game.
  3. Go to Outerra's folder in Program Files and find the save folder of your mod. You can find it by the unique_id.
  4. Copy the cache and campos folders from there into your map folder in templates.

After that, every time the game starts, Outerra copies the cache and campos of the template over the ones of the mod. This also happens when the player starts a new game, so the map is always loaded the way you made it.

Don't start a new game on this map before you copy the 2 folders into the template. A new game can delete the cache and campos you made, and then your map is lost.


4. Starting the mod in the game

4.1 The smallest mod

A new game mod needs only a folder, a mod.cfg and a game script:

game/mods/my_game/
β”œβ”€β”€ mod.cfg
└── my_game.js
scripts = ["my_game.js"],
category = "game",
name = "my_game",
description = "My first game mod"

You don't write unique_id yourself, Outerra creates it for you. Pictures like thumbnail_image are optional, you can add them later.

The game script needs at least on_initialize():

function on_initialize() {
    this.fade("my_game started!");
    return true;
}

If you see the text on the screen after the game starts, your mod works.

4.2 Starting it

  1. Put your mod folder into game/mods. mod.cfg must be directly in the mod folder, not in a subfolder.
  2. Start Outerra. The launcher opens and shows the game mods you can play.
  3. Select your mod. If your game mod has maps, also select one of them. The launcher shows the banner.jpg of the selected map.
  4. Start the game.

4.3 What happens when the mod starts

  1. Outerra loads the selected map with the settings in its game.cfg, for example the planet. If the map has no game.cfg, Outerra uses the default settings. If the game has no template at all, Outerra loads the world by itself and saves it in the cache.
  2. Outerra runs the main script from scripts in mod.cfg. There is only one main script, and the other script files of the mod are included from it.
  3. Outerra calls on_initialize() of the game script. Here you register your actions, read the files of the map (section 3.3), read the content that mods for the game add (section 5) and spawn the first vehicles.

If the game script doesn't start, check the log for errors.

4.4 Mods for a game and content mods

A mod for a game is not a game by itself, so the player doesn't select it in the launcher. The player turns it on and then starts the game as normal. The game script finds the extra content when it starts (see section 5).

A content mod works the same way: the player turns it on when starting a game. The difference is that it is not made for one game, so it works with every game mod. That is why a UI mod can be used in the sandbox and also in Transport Minigame.


5. Mods for a game: adding content to a game

A mod for a game adds content to one specific game. A game can let other mods add content to it, without changing the game's files. Transport Minigame does this: a mod for it can add new vehicles, trailers, cargo or zones.

5.1 How it works

  1. The mod for the game has a file with a special name, for Transport Minigame it is transport_minigame_mod.js.
  2. When the game starts, the game script looks for this file in all mods that are turned on.
  3. If it finds the file, it reads the content and adds it to the game.

If the mod is turned off, its content is not added. So the player can turn the extra content on and off like a normal mod.

5.2 The folder of the mod

A mod for a game is a normal mod with its own folder in game/mods and its own mod.cfg. It has no category = "game", because it is not a game:

game/mods/transport_minigame_mod/
β”œβ”€β”€ mod.cfg
└── transport_minigame_mod.js
scripts = ["transport_minigame_mod.js"],
name = "transport_minigame_mod",
unique_id = "39vvMl8UbT-I0KRVq4n3"

scripts says which file is the main script of the mod, and every mod needs one. Here the main script is the file with the content.

5.3 The file

The file has one object called TRANSPORT_MINIGAME_MOD_DATA. Inside it there are sections for the things you want to add. For example, a mod that adds one new truck and one new cargo:

var TRANSPORT_MINIGAME_MOD_DATA = {
    "vehicles": {
        "my_truck": {
            "id": "my_truck",
            "name": "My Truck",
            "price": 20000,
            "path": "my_mod/vehicles/my_truck/my_truck"
        }
    },
    "cargos": {
        "bricks": {
            "id": "bricks",
            "name": "Bricks",
            "reward": 800,
            "type": "crates"
        }
    }
};

The object must be written like JSON: every key in quotes, and no comma after the last item. Comments with // are ok.

5.4 Sections and required fields

Section What it adds Required fields
vehicles vehicles id, name, price
trailers trailers id, name, price, max_capacity, allowed_cargo
vehicle_beds beds for vehicles id, name, price, compatible_vehicle, max_capacity, allowed_cargo
cargos cargo types id, name, reward, type
zone_presets presets for zones type, radius, input_capacity, output_capacity
zones zones on the map id, lat, lon

Rules the game checks:

  • The key of every item (like "my_truck") must be the same as its id.
  • If an item with the same key already exists in the game, the new one is not added. A mod can't overwrite the game's content.
  • If a required field is missing, the item is not added.

In all these cases the game writes a warning in the log with the reason, so check the log if something doesn't appear.

5.5 How the game finds the file

If you make your own game mod, you can let other mods add content to it in the same way. Transport Minigame uses 2 names to find the content:

const MOD_CONFIG_FILENAME = "transport_minigame_mod.js";      // the file name to look for
const MOD_DATA_MARKER = "TRANSPORT_MINIGAME_MOD_DATA";        // the name of the object in the file

In on_initialize(), the game script goes through the files of all mods that are turned on and looks for this file name:

this.iterate_mod_files("", MOD_CONFIG_FILENAME, false, function (file, modname) {
    // read the content of the file that was found
    let raw = this.get_mod_file_content();

    // ... remove the comments, find the object after MOD_DATA_MARKER,
    //     read it with JSON.parse() and add its items to the game ...

    return true;   // continue with the next mod
});
  • Inside the function, this refers to the game script object, like in on_initialize().
  • modname is the name of the mod where the file was found, useful for the log.
  • The game script only looks for the file name and the object name. So for your own game, choose your own names, for example my_game_mod.js and MY_GAME_MOD_DATA.
  • The content is read with JSON.parse(), that's why the object must be written like JSON (see 5.3).

6. Common problems

Problem Reason
The mod doesn't appear in the launcher mod.cfg is missing or not directly in the mod folder
The game starts but nothing happens The game script is not in scripts in mod.cfg, or the file name is wrong
A map doesn't appear for the game template_game_uid of the map is not the same as the game's unique_id
Added content doesn't appear The mod is turned off, the file name is wrong, the JSON has an error, or a required field is missing. Check the log