Events
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 table e: 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.
Event When Cancellable
mods_loadedOnce after every script mod has loaded (at start and after each reload).
unloadBefore the scripts are unloaded: F9 / Apply in the Mods screen, or quitting the game.
frameEvery frame (about 60 times a second), in menus and hunts.
stageThe game screen changed (main menu, hunt menu, loading, hunt ...).
new_huntA hunt is being set up, before the game places its creatures.
hunt_startThe first frame of a hunt (the hunter is on the map).
hunt_endThe hunt is over (back to the menus).
spawnA creature was added: by the game's hunt setup, a mod, or the world API.
shotThe hunter fired.
hitA shot of the hunter hit a creature. yes
creature_damageA creature hurt another one (creature fights: world.fights). yes
killA creature died.
player_deathThe hunter is about to die. yes
creature_aiEvery frame, for every creature, before its AI runs. yes
creature_after_aiEvery frame, for every creature, after its AI (and the world API's fights / possession) ran.
keyA key went down or up (menus and hunts; not while the mod menu or the console is open). yes
backEsc was pressed: the game's back key (menus: back; hunt: the menu opens, or closes when it is open). yes
drawEvery frame while some mod listens, inside the UI frame.
noticeA creature notices the hunter: it sees him, smells him, or hears a noise he made. yes
noiseThe hunter made a noise creatures can hear (a shot). yes
trophyThe hunter took a trophy (the drop ship picks the creature up).
callThe hunter used the call (decoy). yes
weapon_changeThe hunter changes weapons. yes
player_damageThe hunter loses health to poisonous fog or drowning (every frame it goes on). yes
mouseA mouse button went down or up, or the wheel turned (not while the mod menu or the console is open). yes
net_joinedA player joined the session (see Multiplayer).
net_leftA player left the session.
net_messageA message from another game arrived (every topic; net.on(topic, fn) for one).
net_consentThe player answered a mod's net.request, or changed a permission in the Network tab.
settingA player changed a setting of some mod in the mod menu.
# on("mods_loaded", function(e) ... end)
When: Once after every script mod has loaded (at start and after each reload).
The place for setup that needs other mods: mods.get(id) returns their exports by now.
copy on ("mods_loaded" , function ()
local lib = mods .get("uilib" )
if lib then lib.register("My mod" ) end
end )
# on("unload", function(e) ... end)
When: Before the scripts are unloaded: F9 / Apply in the Mods screen, or quitting the game.
Save what you need with mod.save here; everything of the old run (timers, windows, listeners) is dropped right after.
# on("frame", function(e) ... end)
When: Every frame (about 60 times a second), in menus and hunts.
For continuous logic. Keep it fast; for anything slower use timer.every.
e. Type Access
dtnumber read real seconds since the last frame
copy local t = 0
on ("frame" , function (e)
t = t + e.dt
end )
# on("stage", function(e) ... end)
When: The game screen changed (main menu, hunt menu, loading, hunt ...).
Stages: menu_main menu_hunt menu_options menu_more menu_help menu_about menu_shop loading hunt menu_privacy privacy_terms privacy_policy.
e. Type Access
fromstring read the previous stage (game.stage names)
tostring read the new stage
# on("new_hunt", function(e) ... end)
When: A hunt is being set up, before the game places its creatures.
Every creature handle of the previous hunt becomes invalid here. The game's own creatures then fire spawn before hunt_start.
# on("hunt_start", function(e) ... end)
When: The first frame of a hunt (the hunter is on the map).
World setup goes here: spawn creatures, change rules, open your HUD.
copy on ("hunt_start" , function ()
for i = 1 , 3 do world .spawnNear("velociraptor" , 2000 + i * 300 ) end
end )
# on("hunt_end", function(e) ... end)
When: The hunt is over (back to the menus).
# on("spawn", function(e) ... end)
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.
e. Type Access
creatureCreature read the new creature
copy on ("spawn" , function (e)
if e.creature.species == "trex" then e.creature.scale = e.creature.scale * 1.5 end
end )
# on("shot", function(e) ... end)
e. Type Access
weaponinteger read the weapon slot (0 = the first weapon of the hunt)
# on("hit", function(e) ... end)
When: A shot of the hunter hit a creature.
Every creature has the game's own health (a T-Rex has 1024).
e. Type Access
creatureCreature read the creature hit
weaponinteger read the weapon slot
damagenumber read / write the damage the game will apply; change it
e.cancelled = true: no damage at all
copy on ("hit" , function (e)
if e.creature.species == "trex" then e.damage = e.damage * 0.5 end -- tougher T-Rex
end )
# on("creature_damage", function(e) ... end)
When: A creature hurt another one (creature fights: world.fights).
e. Type Access
creatureCreature read the victim
attackerCreature read the attacker
damagenumber read / write the damage; change it
e.cancelled = true: no damage
# on("kill", function(e) ... end)
e. Type Access
creatureCreature read the dead creature (still valid: its body)
killerCreature |nilread the creature that killed it, nil otherwise
byHunterboolean read true when the hunter's shot killed it
copy on ("kill" , function (e)
if e.byHunter then kills = kills + 1 end
end )
# on("player_death", function(e) ... end)
When: The hunter is about to die.
e. Type Access
killerCreature |nilread the creature attacking him, nil for drowning / poisonous fog
causestring read "creature" or "environment"
e.cancelled = true: the hunter lives: the creature's attack misses; after drowning or fog his health is full again
copy -- three lives
local lives = 3
on ("player_death" , function (e)
if lives > 0 then lives = lives - 1 ; e.cancelled = true ; game .message(lives .. " lives left" ) end
end )
# on("creature_ai", function(e) ... end)
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.
e. Type Access
creatureCreature read the creature
e.cancelled = true: its AI does not run this frame (you move and animate it: c:move, c:animate)
# on("creature_after_ai", function(e) ... end)
When: Every frame, for every creature, after its AI (and the world API's fights / possession) ran.
Correct or hold what its AI did (positions, animations).
e. Type Access
creatureCreature read the creature
# on("key", function(e) ... end)
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
keystring read the key name, e.g. "G", "Space", "F5" (see Keys)
scancodeinteger read the SDL scancode
downboolean read true when pressed, false when released
e.cancelled = true: (key down) the game does not see the key
# on("back", function(e) ... end)
When: Esc was pressed: the game's back key (menus: back; hunt: the menu opens, or closes when it is open).
Close your own window first, or give Esc a new job. Without a cancel the game does what it always does.
e. Type Access
menuOpenboolean read whether the hunt's menu is open
e.cancelled = true: the game does not see it
copy -- Esc closes the shop window before it opens the game's menu
on ("back" , function (e)
if shopOpen then
shopOpen = false
e.cancelled = true
end
end )
# on("draw", function(e) ... end)
When: Every frame while some mod listens, inside the UI frame.
The only place (besides ui.panel functions) where draw.* and ui.window work.
e. Type Access
widthnumber read the window width in UI units
heightnumber read the window height
copy on ("draw" , function (e)
draw .text(e.width / 2 , 20 , "Wave " .. wave, "yellow" , 28 , "center" )
end )
# on("notice", function(e) ... end)
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.
e. Type Access
creatureCreature read the creature
sensestring read "sight", "smell" or "hearing"
e.cancelled = true: it does not notice him (this time)
copy -- raptors are blind: only smell and hearing give the hunter away
on ("notice" , function (e)
if e.creature.species == "velociraptor" and e.sense == "sight" then e.cancelled = true end
end )
# on("noise", function(e) ... end)
When: The hunter made a noise creatures can hear (a shot).
e. Type Access
xnumber read where
ynumber read
znumber read
radiusnumber read / write how far it carries; change it
e.cancelled = true: nobody hears it
copy on ("noise" , function (e) e.radius = e.radius * 0.3 end ) -- silencers for everyone
# on("trophy", function(e) ... end)
When: The hunter took a trophy (the drop ship picks the creature up).
e. Type Access
creatureCreature read the creature
pointsinteger read / write points (= credits) it gives; change them
copy on ("trophy" , function (e)
if e.creature.scale > 1.2 then e.points = e.points * 2 end -- big ones pay double
end )
# on("call", function(e) ... end)
When: The hunter used the call (decoy).
e. Type Access
speciesstring read the species the call imitates
e.cancelled = true: no call
# on("weapon_change", function(e) ... end)
When: The hunter changes weapons.
e. Type Access
frominteger read the slot in hand (-1 = none)
tointeger read the slot he takes
e.cancelled = true: he keeps what he has
copy -- pistols only
on ("weapon_change" , function (e) if e.to ~= 0 then e.cancelled = true end end )
# on("player_damage", function(e) ... end)
When: The hunter loses health to poisonous fog or drowning (every frame it goes on).
Creatures' attacks do not hurt gradually: they kill (see player_death).
e. Type Access
amountnumber read / write health lost this frame; change it
causestring read "fog" or "drowning"
e.cancelled = true: no damage this frame
# on("mouse", function(e) ... end)
When: A mouse button went down or up, or the wheel turned (not while the mod menu or the console is open).
In a hunt the left button fires and the right one holds the binoculars.
e. Type Access
buttonstring read "left", "right", "middle", "x1", "x2" or "wheel"
downboolean read pressed (buttons)
xnumber read
ynumber read
wheelnumber read wheel steps (+ away from you)
e.cancelled = true: (press / wheel) the game does not see it
# on("net_joined", function(e) ... end)
When: A player joined the session (see Multiplayer).
e. Type Access
peerinteger read their id
playerNamestring read
# on("net_left", function(e) ... end)
When: A player left the session.
e. Type Access
peerinteger read
reasonstring read
# on("net_message", function(e) ... end)
When: A message from another game arrived (every topic; net.on(topic, fn) for one).
e. Type Access
frominteger read the sender's id
topicstring read
dataany read string, number, boolean or table
reliableboolean read
# on("net_consent", function(e) ... end)
When: The player answered a mod's net.request, or changed a permission in the Network tab.
e. Type Access
modstring read the mod's id
allowedboolean read
# on("setting", function(e) ... end)
When: A player changed a setting of some mod in the mod menu.
e. Type Access
modstring read the mod's id
keystring read the setting
valueany read its new value