Everything mods can react to. Listen with on(name, function(e) ... end).
Everything that happens in the game reaches mods as an event. A handler is a function that gets one argument,
the event tablee: its fields describe what happened (see the Events page for every event). Some fields are
writable (e.g. e.damage of hit): change them and the game uses your value. Setting e.cancelled = true on a
cancellable event stops what it announces (e.g. a key reaching the game). Handlers run in priority order, then in the
order they were added; later handlers see what earlier ones changed.
Custom events work the same way: events.emit("mymod:boss_spawned", {creature = c}) reaches every mod's
on("mymod:boss_spawned", ...). Prefix custom names with your mod's id.
A creature takes damage from any source: the hunter's shots, other creatures (fights, c:attack, c:bite) and scripts (c:hurt). The game has no falls or drowning for creatures.
A creature's death begins, whatever the cause (shots, fights, scripts, world.killAll): the frame after its health reached 0, before its death animation plays.
A dead body leaves the world: the drop ship carried the trophy away, world.clearBodies, c:remove on a body, or the game took it (Survive's sinking bodies).
A creature attacks: the hunter (its AI reached him: the game's attack, which kills at once) or another creature (a bite of the fights, c:attack, c:bite).
A creature that is no predator starts running from the hunter (its fear timer runs and its way leads away from him), or any creature after c.mood = "flee".
The hunter uses his equipment: the binoculars go up or down, the map (with the radar, when he has it) opens or closes. The call has its own event (call); cover scent and camouflage work by themselves (player.scent, player.camouflage).
When: A creature was added: by the game's hunt setup, a mod, or the world API.
Change its stats right away (scale, health, team) or give it data. During the game's hunt setup (before hunt_start) world.spawn returns nil; c:kill() / c:remove() inside this handler happen at the next frame.
Since API 3 c:kill(), c.health = 0, c:hurt and c:die fire it too (killer nil, or the attacker / the hunter they name). death fires for every death, whatever the cause.
When: Every frame, for every creature, before its AI runs.
For per-frame control of particular creatures. This runs very often (hundreds of creatures x 60 frames), so return quickly for creatures you do not care about. To take a creature over for good, c.ai = false is cheaper.
When: A key went down or up (menus and hunts; not while the mod menu or the console is open).
F1, F9 and ` are taken by the mod menu, reload and the console. keys.bind is the easy way to react to one key. Esc comes here first, then as the back event.
e.
Type
Access
key
string
read
the key name, e.g. "G", "Space", "F5" (see Keys)
scancode
integer
read
the SDL scancode
down
boolean
read
true when pressed, false when released
e.cancelled = true: (key down) the game does not see the key
When: A creature notices the hunter: it sees him, smells him, or hears a noise he made.
Stealth mods start here. The strength of each sense per creature is c.sight, c.smell, c.hearing. A tame creature (c.tame) never notices him. The generic brains (c.brain = "predator" ...) look for the hunter themselves and fire this event too.
always true: the one noticed is the hunter (since API 3)
e.cancelled = true: it does not notice him (this time)
-- raptors are blind: only smell and hearing give the hunter awayon("notice", function(e)
if e.creature.species == "velociraptor"and e.sense == "sight"then e.cancelled = trueendend)
When: A creature takes damage from any source: the hunter's shots, other creatures (fights, c:attack, c:bite) and scripts (c:hurt). The game has no falls or drowning for creatures.
Fires after hit / creature_damage for the same damage. Health is the game's own (a T-Rex has 1024).
When: A creature's death begins, whatever the cause (shots, fights, scripts, world.killAll): the frame after its health reached 0, before its death animation plays.
kill fires at the killing blow (shots, fights, scripts); death once for every death. It comes the frame after the health reached 0: a check that runs every frame ("is the whole team dead?" from c.alive or c.health) can see the last creature dead before its death event has fired; count deaths in the event, or check again in it.
When: A dead body leaves the world: the drop ship carried the trophy away, world.clearBodies, c:remove on a body, or the game took it (Survive's sinking bodies).
When: A creature attacks: the hunter (its AI reached him: the game's attack, which kills at once) or another creature (a bite of the fights, c:attack, c:bite).
Not fired in god mode, while the player possesses a creature, for a tame creature or one with c.canKillHunter = false (their attacks miss anyway).
the hunter only: nil = the game's kill; set a number and the bite takes that much health instead (he dies only when it is all he has left; player_death can still save him)
e.cancelled = true: it misses: no kill, no bite damage (its attack animation still plays)
-- creatures bite instead of killing: 25 health a biteon("creature_attack", function(e)
if e.hunter then e.damage = 25endend)
When: A creature that is no predator starts running from the hunter (its fear timer runs and its way leads away from him), or any creature after c.mood = "flee".
When: The hunter uses his equipment: the binoculars go up or down, the map (with the radar, when he has it) opens or closes. The call has its own event (call); cover scent and camouflage work by themselves (player.scent, player.camouflage).
e.
Type
Access
item
string
read
"binoculars" or "map"
on
boolean
read
going up / opening
radar
boolean|nil
read
map: the radar shows the creatures
e.cancelled = true: (on) the binoculars stay down / the map stays closed
-- hardcore: no binocularson("equipment", function(e) if e.item == "binoculars"then e.cancelled = trueendend)
When: The hunter asks for a resupply (the drop ship brings ammunition), a relocation (to the point chosen on the map) or the evacuation (the hunt ends).
e.
Type
Access
kind
string
read
"resupply", "relocation" or "evacuation"
e.cancelled = true: nothing is requested (no resupply or relocation is used up)
-- no leaving before the boss is deadon("request", function(e)
if e.kind == "evacuation"and bossAlive then
e.cancelled = truegame.message("Not before the T-Rex is dead!")
endend)
When: The player pressed one of the game's menu buttons (before the game acts on it).
Not for your own buttons (they call their function).
e.
Type
Access
menu
string
read
main, more, hunt_area, hunt_species, hunt_weapon or game
button
string
read
its name (see the menu page), or an added equipment item's id
e.cancelled = true: the game does not see the press
-- no Survive mode in this modon("menu_action", function(e)
if e.menu == "main"and e.button == "survive"thengame.message("Not in this mod")
e.cancelled = trueendend)
When: Every frame while some mod listens, inside the game's own GUI pass (menus and the hunt's HUD).
Here draw.sprite, draw.text (with the game's fonts), draw.fillRect, draw.rect and draw.line draw with the game's renderer in game units (y from the top): under the game's popups and the mods' windows, over its menus (layer 1500; the game's buttons are 1000, popups 2000, pages 2900 and up).