game

The game's state: which game, stage, hunt, version, screen, messages.

Two games, one API. The PC port runs Carnivores: Dinosaur Hunter HD and Carnivores: Ice Age; each is its own copy of the game, and game.id() tells a mod which one it runs in. A mod runs in a game only when its mod.json lists that game in "games" (Mod folders). Every function, event and field is the same in both; what differs is the game's content: the species (ids and type numbers, see the species tables), the maps (game.area() 0-6 in Dinosaur Hunter, 0-4 in Ice Age), the texts (STR_* keys) and the content registry's built-ins.

Functions

# game.id() → string

since API 2

Which game the mod runs in. Each game is its own copy of the program, so this never changes while a mod runs. Use it to pick species and texts in a mod made for both games.

Returns
string"dinohunter" (Carnivores: Dinosaur Hunter HD) or "iceage" (Carnivores: Ice Age)
local boss = game.id() == "iceage" and "mammoth" or "trex"
world.spawnNear(boss, 6000)

# game.stage() → string

Which screen the game is on.

Returns
stringthe current stage: menu_main, menu_hunt, menu_options, menu_more, menu_help, menu_about, menu_shop, loading, hunt, menu_privacy, privacy_terms, privacy_policy (or none)

# game.inHunt() → boolean

Whether a hunt is running.

Returns
booleantrue while hunting (the hunter exists)
if game.inHunt() then world.spawnNear("trex") end

# game.area() → integer

The hunt's map.

Returns
integerthe area chosen in the hunt menu: 0 to 6 (Dinosaur Hunter), 0 to 4 (Ice Age)

# game.version() → string

The game version.

Returns
string"2.0.1-pc"

# game.apiVersion() → integer

The version of this API. It grows by one with every release that adds to it; nothing is removed. A mod that needs newer functions says so in mod.json ("api": 2); older games then show why it does not run.

Returns
integerthe modding API's version (3 in this release)
if game.apiVersion() >= 2 then print("running in " .. game.id()) end

# game.timeScale(factor?) → number

Slow motion or fast forward for the whole game (creatures, the hunter, animations, timers of the game).

ParameterType
factor optionalnumber0.05 to 4; 1 = normal
Returns
numberthe factor
keys.bind("V", function() game.timeScale(game.timeScale() == 1 and 0.25 or 1) end)

# game.text(key, language?) → string|nil

One of the game's texts in the current (or a given) language.

ParameterType
keystringa key of the game's strings.csv, e.g. "STR_T_REX"
language optionalstring"en", "de", "fr", "es" ...
Returns
string|nilthe text, nil when there is no such key

# game.setText(key, text)

Replaces one of the game's texts (menus, messages, names). Texts the game shows from now on use it; menus already built show it the next time they are made. Letters outside Latin-1 become ? (the game's fonts lack them).

ParameterType
keystring
textstring|nilthe new text; nil = the original again
game.setText("STR_T_REX", "Rexy")

# game.language() → string

The game's language.

Returns
string"en", "de", "fr", "es" ...

# game.platform() → string

The operating system.

Returns
string"linux" or "windows"

# game.screen() → number, number

The window size in UI units (the coordinates of draw.* and ui.window).

Returns
numberwidth
numberheight

# game.paused() → boolean

Whether the hunt is paused.

Returns
booleantrue while the game menu (pause) is open

# game.dt() → number

The game's time step of the last frame (0 while paused).

Returns
numberseconds

# game.shots() → integer, integer

The hunt's shooting statistics.

Returns
integershots fired this hunt
integershots that hit

# game.message(text, seconds?, color?)

Shows a short message at the bottom right (the same as ui.toast).

ParameterType
textstringthe message
seconds optionalnumberhow long it shows (default 4)
color optionalColortext colour (default white)
game.message("A T-Rex is near!", 5, "orange")

# game.project(x, y, z) → number?, number?

hunt only

Where a world point appears on the screen, for labels and markers.

ParameterType
xnumberworld x
ynumberworld y (height)
znumberworld z
Returns
number?screen x (nothing when the point is behind the camera or not in a hunt)
number?screen y
local sx, sy = game.project(x, world.ground(x, z) + 300, z)
if sx then draw.text(sx, sy, "X marks the spot", "red", 20, "center") end

# game.changes() → table

since API 3

The definition changes the scripts made (species, weapons, weather, rules, overrides ...), each with the value before the first change and the mods that made it. They are undone when the scripts unload.

Returns
table{what, original, mods}...
for _, c in ipairs(game.changes()) do print(c.what, c.original, table.concat(c.mods, ", ")) end