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.

EventWhenCancellable
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.
damageA 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.yes
deathA creature's death begins, whatever the cause (shots, fights, scripts, world.killAll): the frame after its health reached 0, before its death animation plays.
despawnA living creature leaves the world (c:remove, world.removeAll; the Brachiosaurus, which cannot die, on c:kill).
body_removedA 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).
creature_attackA 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).yes
creature_huntA creature starts hunting the hunter: its AI chases him (predators, Ice Age's charging animals, c.mood = "hunt", the predator brain).yes
creature_hunt_endA creature stops hunting the hunter.
creature_fleeA 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".yes
creature_flee_endA creature stops running from the hunter.
equipmentThe 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).yes
requestThe 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).yes
arriveWhat the hunter asked for arrives: the supply bag landed, he picked it up, he was relocated, the evacuation ship takes him.
reloadThe weapon in hand is about to reload (its magazine is empty and ammunition is left).yes
menu_readyThe game's menus exist (once per script load, right after the game has set them up; after F9 at once).
menu_actionThe player pressed one of the game's menu buttons (before the game acts on it).yes
menu_selectThe player picks a map, species or weapon cell in the hunt menu (before the game does).yes
menu_openA page was opened.
menu_closeA page was closed.
guiEvery frame while some mod listens, inside the game's own GUI pass (menus and the hunt's HUD).
zone_enterThe hunter, or a creature the zone tracks (creatures in its definition), entered a zone.
zone_leaveThe hunter, or a creature the zone tracks, left a zone.
spawn_plannedBefore creatures are placed: the game's own placement (source "game"), a population's ("population", "respawn", "script").yes
population_changedThe number of a population's living creatures changed.
group_alertA member noticed danger and the group reacts (shared alertness), or g:alert().
group_fleeA group starts to flee together.
group_regroupA group waits for members that were left behind.
group_huntA pack starts to hunt (it noticed the hunter, found prey, or g:hunt()).
group_attackA pack member's turn to attack begins.
group_killA pack killed its prey (then it stays at the kill for feedTime).
group_calmA group's flight or hunt is over.
group_homeA group starts to walk back to its territory.
lightningLightning strikes: a random strike of weather.lightning, or weather.strike.yes

# 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.

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.TypeAccess
dtnumberreadreal seconds since the last frame
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.TypeAccess
fromstringreadthe previous stage (game.stage names)
tostringreadthe 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.

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.TypeAccess
creatureCreaturereadthe new creature
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)

When: The hunter fired.

e.TypeAccess
weaponintegerreadthe 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). damage fires after it for the same shot (after c.armor).

e.TypeAccess
creatureCreaturereadthe creature hit
weaponintegerreadthe weapon slot
damagenumberread / writethe damage the game will apply; change it
mortalboolean|nilreadtrue when the shot hit a deadly spot: damage is all its health (since API 3; before, those kills skipped this event)

e.cancelled = true: no damage at all

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).

damage fires after it for the same bite.

e.TypeAccess
creatureCreaturereadthe victim
attackerCreaturereadthe attacker
damagenumberread / writethe damage; change it

e.cancelled = true: no damage

# on("kill", function(e) ... end)

When: A creature died.

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.

e.TypeAccess
creatureCreaturereadthe dead creature (still valid: its body)
killerCreature|nilreadthe creature that killed it, nil otherwise
byHunterbooleanreadtrue when the hunter's shot killed it
tranquilizedbooleanreadthe hunter's tranquilizer put it to sleep (since API 3)
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.TypeAccess
killerCreature|nilreadthe creature attacking him, nil for drowning / poisonous fog
causestringread"creature" or "environment"

e.cancelled = true: the hunter lives: the creature's attack misses; after drowning or fog his health is full again

-- 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.TypeAccess
creatureCreaturereadthe 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.TypeAccess
creatureCreaturereadthe 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.TypeAccess
keystringreadthe key name, e.g. "G", "Space", "F5" (see Keys)
scancodeintegerreadthe SDL scancode
downbooleanreadtrue 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.TypeAccess
menuOpenbooleanreadwhether the hunt's menu is open

e.cancelled = true: the game does not see it

-- 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.TypeAccess
widthnumberreadthe window width in UI units
heightnumberreadthe window height
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. A tame creature (c.tame) never notices him. The generic brains (c.brain = "predator" ...) look for the hunter themselves and fire this event too.

e.TypeAccess
creatureCreaturereadthe creature
sensestringread"sight", "smell" or "hearing"
hunterbooleanreadalways 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 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.TypeAccess
xnumberreadwhere
ynumberread
znumberread
radiusnumberread / writehow far it carries; change it

e.cancelled = true: nobody hears it

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.TypeAccess
creatureCreaturereadthe creature
pointsintegerread / writepoints (= credits) it gives; change them
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.TypeAccess
speciesstringreadthe species the call imitates

e.cancelled = true: no call

# on("weapon_change", function(e) ... end)

When: The hunter changes weapons.

e.TypeAccess
fromintegerreadthe slot in hand (-1 = none)
tointegerreadthe slot he takes

e.cancelled = true: he keeps what he has

-- 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).

A creature's attack kills at once, unless a mod gives creature_attack a damage: then that bite comes here too (cause "creature").

e.TypeAccess
amountnumberread / writehealth lost this frame; change it
causestringread"fog", "drowning", or "creature" (a bite made non-lethal with creature_attack, since API 3)

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.TypeAccess
buttonstringread"left", "right", "middle", "x1", "x2" or "wheel"
downbooleanreadpressed (buttons)
xnumberread
ynumberread
wheelnumberreadwheel 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.TypeAccess
peerintegerreadtheir id
playerNamestringread

# on("net_left", function(e) ... end)

When: A player left the session.

e.TypeAccess
peerintegerread
reasonstringread

# on("net_message", function(e) ... end)

When: A message from another game arrived (every topic; net.on(topic, fn) for one).

e.TypeAccess
fromintegerreadthe sender's id
topicstringread
dataanyreadstring, number, boolean or table
reliablebooleanread

# on("net_consent", function(e) ... end)

When: The player answered a mod's net.request, or changed a permission in the Network tab.

e.TypeAccess
modstringreadthe mod's id
allowedbooleanread

# on("setting", function(e) ... end)

When: A player changed a setting of some mod in the mod menu.

e.TypeAccess
modstringreadthe mod's id
keystringreadthe setting
valueanyreadits new value

# on("damage", function(e) ... end)

since API 3

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).

e.TypeAccess
creatureCreaturereadthe creature hurt
amountnumberread / writethe damage it will take, after c.armor; change it
sourcestringread"hunter", "creature" or "script"
attackerCreature|nilreadthe creature dealing it
weaponinteger|nilreadthe hunter's weapon slot

e.cancelled = true: no damage

-- the boss takes a quarter of every damage, whoever deals it
on("damage", function(e)
  if e.creature.data.boss then e.amount = e.amount / 4 end
end)

# on("death", function(e) ... end)

since API 3

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.

e.TypeAccess
creatureCreaturereadthe dead creature (its body)
killerCreature|nilreadthe creature that killed it
byHunterbooleanreadthe hunter killed it
causestringread"hunter", "creature", "other" (a script, the world API) or "unknown"

# on("despawn", function(e) ... end)

since API 3

When: A living creature leaves the world (c:remove, world.removeAll; the Brachiosaurus, which cannot die, on c:kill).

e.TypeAccess
creatureCreaturereadthe creature, still valid during the event
reasonstringread"script" or "nodeath"

# on("body_removed", function(e) ... end)

since API 3

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).

e.TypeAccess
creatureCreaturereadthe body, still valid during the event
reasonstringread"ship", "clear", "script" or "game"

# on("creature_attack", function(e) ... end)

since API 3

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).

e.TypeAccess
creatureCreaturereadthe attacker
targetCreature|nilreadthe creature attacked; nil when it is the hunter
hunterbooleanreadthe hunter is attacked
damagenumber|nilread / writethe 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 bite
on("creature_attack", function(e)
  if e.hunter then e.damage = 25 end
end)

# on("creature_hunt", function(e) ... end)

since API 3

When: A creature starts hunting the hunter: its AI chases him (predators, Ice Age's charging animals, c.mood = "hunt", the predator brain).

Checked after every creature's AI, while some mod listens to one of the hunt / flee events.

e.TypeAccess
creatureCreaturereadthe hunter's hunter
causestringreadwhat alarmed it: "sight", "smell", "hearing", "shot", "hurt", "attack", "near", "script" or "unknown"
distancenumberreadto the hunter

e.cancelled = true: it calms down this time (its AI may notice him again later)

on("creature_hunt", function(e)
  game.message(e.creature.name .. " is coming for you (" .. e.cause .. ")", 3, "red")
end)

# on("creature_hunt_end", function(e) ... end)

since API 3

When: A creature stops hunting the hunter.

e.TypeAccess
creatureCreatureread
reasonstringread"calm" (it gave up, was calmed or tamed), "died" or "hunter_dead"
distancenumberreadto the hunter

# on("creature_flee", function(e) ... end)

since API 3

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".

e.TypeAccess
creatureCreatureread
causestringreadwhat alarmed it (as creature_hunt)
distancenumberreadto the hunter

e.cancelled = true: it calms down this time

# on("creature_flee_end", function(e) ... end)

since API 3

When: A creature stops running from the hunter.

e.TypeAccess
creatureCreatureread
reasonstringread"calm", "died" or "hunter_dead"
distancenumberreadto the hunter

# on("equipment", function(e) ... end)

since API 3

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.TypeAccess
itemstringread"binoculars" or "map"
onbooleanreadgoing up / opening
radarboolean|nilreadmap: the radar shows the creatures

e.cancelled = true: (on) the binoculars stay down / the map stays closed

-- hardcore: no binoculars
on("equipment", function(e) if e.item == "binoculars" then e.cancelled = true end end)

# on("request", function(e) ... end)

since API 3

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.TypeAccess
kindstringread"resupply", "relocation" or "evacuation"

e.cancelled = true: nothing is requested (no resupply or relocation is used up)

-- no leaving before the boss is dead
on("request", function(e)
  if e.kind == "evacuation" and bossAlive then
    e.cancelled = true
    game.message("Not before the T-Rex is dead!")
  end
end)

# on("arrive", function(e) ... end)

since API 3

When: What the hunter asked for arrives: the supply bag landed, he picked it up, he was relocated, the evacuation ship takes him.

e.TypeAccess
kindstringread"resupply" (the bag landed), "pickup" (he took it: ammunition refilled), "relocation" or "evacuation" (the hunt ends)

# on("reload", function(e) ... end)

since API 3

When: The weapon in hand is about to reload (its magazine is empty and ammunition is left).

e.TypeAccess
weaponintegerreadthe weapon slot
roundsintegerreadrounds it will load
ammointegerreadammunition left

e.cancelled = true: not now: it stays empty and asks again next frame (a manual-reload mod lets it through later)

# on("menu_ready", function(e) ... end)

since API 3

When: The game's menus exist (once per script load, right after the game has set them up; after F9 at once).

The place to measure: sprite and text sizes, the screen, the game's buttons (menu.buttons).

e.TypeAccess
widthnumberreadthe screen in game units
heightnumberread

# on("menu_action", function(e) ... end)

since API 3

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.TypeAccess
menustringreadmain, more, hunt_area, hunt_species, hunt_weapon or game
buttonstringreadits 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 mod
on("menu_action", function(e)
  if e.menu == "main" and e.button == "survive" then
    game.message("Not in this mod")
    e.cancelled = true
  end
end)

# on("menu_select", function(e) ... end)

since API 3

When: The player picks a map, species or weapon cell in the hunt menu (before the game does).

e.TypeAccess
menustringreadhunt_area, hunt_species or hunt_weapon
kindstringread"map", "species" or "weapon"
idstringreadits content id
indexintegerreadits cell (1 = the first)
selectedbooleanreadwhether it is going to be chosen (false: un-chosen)

e.cancelled = true: the cell stays as it is

# on("menu_open", function(e) ... end)

since API 3

When: A page was opened.

e.TypeAccess
pagestringreadits id

# on("menu_close", function(e) ... end)

since API 3

When: A page was closed.

e.TypeAccess
pagestringreadits id

# on("gui", function(e) ... end)

since API 3

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).

e.TypeAccess
menustring|nilreadthe menu shown (as menu.current)
pagestring|nilreadthe open page
widthnumberreadthe screen in game units
heightnumberread
on("gui", function(e)
  if e.menu == "main" then
    draw.sprite("icon_radar", 10, 10)
    draw.text(40, 12, "Modded", "#ffe020", nil, "left", "ccra14")
  end
end)

# on("zone_enter", function(e) ... end)

since API 3

When: The hunter, or a creature the zone tracks (creatures in its definition), entered a zone.

Checked every frame on this hunt's map. A creature that dies inside leaves without an event.

e.TypeAccess
zoneZonereadthe zone
creatureCreature?readthe creature (nil: the hunter)
hunterbooleanreadthe hunter crossed the edge
on("zone_enter", function(e)
  if e.hunter and e.zone.name == "nest" then game.message("Raptor nest!") end
end)

# on("zone_leave", function(e) ... end)

since API 3

When: The hunter, or a creature the zone tracks, left a zone.

e.TypeAccess
zoneZonereadthe zone
creatureCreature?readthe creature (nil: the hunter)
hunterbooleanreadthe hunter crossed the edge

# on("spawn_planned", function(e) ... end)

since API 3

When: Before creatures are placed: the game's own placement (source "game"), a population's ("population", "respawn", "script").

During the hunt setup (before hunt_start) the hunter's position is not available to scripts.

e.TypeAccess
speciesstringread / writethe species id (set another loaded species to change it)
countintegerread / writehow many (a group placed together)
xnumber?read / writewhere (nil for the game's own: it looks for a place itself; set x and z to choose)
znumber?read / write
sourcestringread"game", "population", "respawn" or "script"
rulestring?readthe population's id
groupstring?read"herd", "pack" or "group" when they become one
nearPlayerbooleanreadthe game's own: its "near the hunter" placement

e.cancelled = true: nothing is placed

on("spawn_planned", function(e)
  if e.source == "game" and e.species == "trex" then e.cancelled = true end   -- no T-Rex this time
end)

# on("population_changed", function(e) ... end)

since API 3

When: The number of a population's living creatures changed.

e.TypeAccess
rulestringreadthe population's id
speciesstringreadits species
countintegerreadhow many live now
changeintegerread
  • placed, - died or removed
reasonstringread"spawn", "respawn", "death" or "removed"
creatureCreature?readthe one that died

# on("group_alert", function(e) ... end)

since API 3

When: A member noticed danger and the group reacts (shared alertness), or g:alert().

Then a herd flees (group_flee), a pack hunts the hunter (group_hunt), other groups alert each member.

e.TypeAccess
groupGroupreadthe group
creatureCreaturereadthe member that noticed it
threatCreature?readthe creature it noticed (nil: the hunter)
hunterbooleanreadthe hunter is the danger
causestringread"hunter", "creature", "death" (a member died) or "script"

# on("group_flee", function(e) ... end)

since API 3

When: A group starts to flee together.

e.TypeAccess
groupGroupreadthe group
fromCreature?readwhat it flees from (nil: the hunter)
hunterbooleanread
xnumberreadwhere it runs to
znumberread

# on("group_regroup", function(e) ... end)

since API 3

When: A group waits for members that were left behind.

e.TypeAccess
groupGroupreadthe group
creatureCreaturereadthe leader
distancenumberreadthe farthest member
causestringread"split"

# on("group_hunt", function(e) ... end)

since API 3

When: A pack starts to hunt (it noticed the hunter, found prey, or g:hunt()).

e.TypeAccess
groupGroupreadthe group
targetCreature?readits prey (nil: the hunter)
hunterbooleanread

# on("group_attack", function(e) ... end)

since API 3

When: A pack member's turn to attack begins.

e.TypeAccess
groupGroupreadthe group
creatureCreaturereadthe attacker
targetCreature?readthe prey (nil: the hunter)
hunterbooleanread

# on("group_kill", function(e) ... end)

since API 3

When: A pack killed its prey (then it stays at the kill for feedTime).

e.TypeAccess
groupGroupreadthe group
creatureCreaturereadthe prey
killerCreature?readthe member that killed it

# on("group_calm", function(e) ... end)

since API 3

When: A group's flight or hunt is over.

e.TypeAccess
groupGroupreadthe group

# on("group_home", function(e) ... end)

since API 3

When: A group starts to walk back to its territory.

e.TypeAccess
groupGroupreadthe group
creatureCreaturereadthe leader
xnumberreadwhere it goes
znumberread
distancenumberread

# on("lightning", function(e) ... end)

since API 4

When: Lightning strikes: a random strike of weather.lightning, or weather.strike.

Before the flash. A strike made in a lightning handler gets no event of its own.

e.TypeAccess
xnumberreadwhere it strikes
znumberread
distancenumberreadfrom the hunter, in units (128 = 1 m)
delaynumberreadseconds until its thunder
scriptedbooleanreadit comes from weather.strike

e.cancelled = true: no flash, no bolt, no thunder

on("lightning", function(e)
  if e.distance < 30000 then game.message("That was close!") end
end)