Getting started

This page makes a small script mod from nothing: a message when a hunt starts, a T-Rex on a key press, and a HUD line that counts your kills. Everything else in this documentation builds on the same few steps.

1. Find the mods folder

The mods folder is next to the game's executable (carnivores.exe on Windows, carnivores on Linux). The game makes it on its first start. In the game: MODS on the main menu → Open the mods folder.

2. Make a mod folder

Make a folder inside mods, for example mods/hello. The folder's name is your mod's id: keep it short, lower case, no spaces (hello, raptor_pack, arena).

Put a file mod.json into it:

{
  "name": "Hello Hunter",
  "version": "1.0",
  "author": "you",
  "description": "My first mod"
}

3. Write main.lua

Next to it, make main.lua:

print("Hello from " .. mod.name)

local kills = 0

-- when a hunt starts
on("hunt_start", function()
  kills = 0
  game.message("Welcome back, hunter!")
end)

-- count the hunter's kills
on("kill", function(e)
  if e.byHunter then
    kills = kills + 1
  end
end)

-- press T: a T-Rex appears 2000 units in front of you
keys.bind("T", function()
  if game.inHunt() then
    world.spawnNear("trex", 2000)
  end
end)

-- draw a line of text every frame
on("draw", function(e)
  if game.inHunt() then
    draw.text(20, e.height - 40, "Kills: " .. kills, "yellow", 24)
  end
end)

The folder now looks like this:

mods/
  hello/
    mod.json
    main.lua

4. Run it

Start the game. Mods are found at start; new ones are switched on. Open the console with ** (the key under Esc): you should see[hello] Hello from Hello Hunterand[hello] loaded Hello Hunter 1.0`. Start a hunt, press T**, and shoot the T-Rex.

Change the code while the game runs: save main.lua, press F9, and every script mod reloads, mid-hunt included.

5. When something goes wrong

Errors never crash the game. They go to the console in red, with the file and line:

[hello] error in kill: hello/main.lua:12: attempt to perform arithmetic on a nil value (global 'kils')

The mod menu (F1, tab Scripts) shows each script mod as running or failed with its error. Fix, save, F9.

The console also runs Lua: type world.count() or inspect(player.pos()) and press Enter. Everything a mod can use works there, which makes it the quickest way to try the API.

Where next

Editor support: download carnivores.d.lua (left, under Downloads) into your mod's folder. With VS Code and its Lua extension (by sumneko) you get autocompletion and these docs while typing.