Creatures: spawn, find, kill; fights, god mode; the ground.
Creature functions work during a hunt; outside one they return nothing (world.spawn returns nil) or do nothing.
Species are given by id ("trex", "mammoth") or by type number (see the species tables below: each game has its own
species, game.id() tells which game runs). Mod species from content packs have ids too. Spawning, fights, teams and
possession work with every species of both games except the flyers (no fights, no possession).
The switches world.fights, world.god, world.invisible and world.frozen, a possession and camera.follow belong to
the scripts: when they unload or reload (F9, Reload scripts, a mod switched off in the Mods screen, quitting) they go
back to the game's own (all off, the camera on the hunter).
Creature fights: predators hunt the nearest prey (or other predators), creatures with teams hunt every other team. Bites deal damage over time; creature_damage fires for each.
Every species of this game that can be spawned (content packs' too). Ice Age's list has its animals, Dinosaur Hunter's the dinosaurs (the species tables below). Since API 3, world.species(id) returns the species itself, to read and change (SpeciesHandle).
without id: a list of {id, type, name, predator, loaded}; with id: the species
local rex = world.species("trex")
rex.mass = 12-- heavier trophies
rex.health = 3000-- the next ones spawned
rex:applyToLiving() -- and the living ones
-- can the T-Rex see the hunter?local ex, ey, ez = player.eye()
local kind = world.trace(rex.x, rex.y + rex.height * 0.8, rex.z, ex, ey, ez)
ifnot kind thenprint("in plain view") end
The time of day of the hunts loaded from now on (switching it in a running hunt would need the sky, shadows and sounds loaded again). Kept until your mod unloads.
Parameter
Type
toptional
string
"dawn", "day", "night"; nil = the hunt menu's choice
A random point of the map (or of a zone) that meets the conditions: on land by default, never in water.
Parameter
Type
optsoptional
table
conditions, all optional: zone (a Zone or its name), water = true (in water; default: on land), nearWater / awayFromWater (distances), minHeight / maxHeight (ground height), maxSlope, minHunterDistance / maxHunterDistance, species (a place that species can stand on, the game's own test)
Returns
number?
x
number?
z (nothing when no point was found)
local x, z = world.randomPoint({nearWater = 2000, minHunterDistance = 8000, species = "parasaurolophus"})
if x thenworld.spawn("parasaurolophus", x, z) end
A handle to one creature of the hunt. Handles compare equal (==) when they are the same creature and can be table keys. A handle goes stale (c.valid == false) when the creature is removed or a new hunt begins; using a stale handle raises an error.
Fields
Field
Type
Access
index
integer
read
its slot in the game's character list (reused by later creatures; prefer id)
id
integer
read
a number unique to this creature while it exists: store it, find it again with world.byId
valid
boolean
read
false once it was removed or a new hunt began (every other field then raises an error)
alive
boolean
read
true while its health is above 0
type
integer
read
the game's character type number
species
string
read
the species id, e.g. "trex" (see the species table)
name
string
read
the species' name in the game's language
x
number
read / write
position
y
number
read / write
height (its feet)
z
number
read / write
position
yaw
number
read / write
heading in degrees (same convention as player.yaw)
health
number
read / write
health in the game's units (a T-Rex has 1024); setting 0 kills it through the game's death path (the kill event, its death animation, a body)
maxHealth
number
read
its species' full health (or more, if it had more)
scale
number
read / write
size factor: 1 = its model's size; trophies and the game's stats use it
height
number
read
the height of its model at its scale
anim
integer
read / write
the animation playing (0 = the first one of its model); setting it blends to the new one
animTime
number
read / write
seconds into the current animation
animLength
number
read
length of the current animation in seconds
animName
string
read
name of the current animation in its model
animCount
integer
read
how many animations its model has
distance
number|nil
read
distance to the hunter on the ground (nil outside a hunt)
the creature it hunts (world fights; or c.target = other / c:attack(other): it goes after another creature with its own chase and attack, also while world.fights is off; nil stops it)
attacking
boolean
read
creature fights: attacking right now
fleeing
boolean
read
creature fights: running away
kills
integer
read
creature fights: its kills
damageDealt
number
read
creature fights: damage it dealt
damageTaken
number
read
creature fights: damage it took
state
integer
read / write
its AI's state number (species-specific; 0 = calm in most)
afraid
number
read / write
its AI's fear timer in seconds (it flees while above 0)
targetX
number
read / write
where its AI walks to (x); the AI may change it
targetZ
number
read / write
where its AI walks to (z)
ai
boolean
read / write
false = the game's AI no longer runs for it: your script moves and animates it
predator
boolean
read
whether its species hunts
possessed
boolean
read
whether the player drives it (c:possess())
data
table
read / write
a table for your own data about this creature; dropped with the creature
a colour laid over its model (team colours, glowing bosses); the alpha is the strength; nil = none
speed
number
read / write
its time factor: its AI and animations run this much faster (2) or slower (0.5); 0 freezes it
sight
number
read / write
how well it sees the hunter (1 = its species' normal, 2 = twice as far, 0.5 = half)
smell
number
read / write
how well it smells the hunter
hearing
number
read / write
how far it hears noises (0 = deaf)
visible
boolean
read
drawn this frame (in view, near enough); the game recomputes it every frame
swimming
boolean
read
swimming in deep water (its AI's flag)
pitch
number
read
body pitch in degrees (the ground's slope; recomputed by its AI)
roll
number
read
body roll in degrees (recomputed by its AI)
targetYaw
number
read
the heading its AI turns to (degrees, the yaw convention)
velocity
number
read
forward speed in units per second (its AI eases it to its animation's speed)
turnRate
number
read
turn speed in degrees per second (eased by its AI)
stuck
integer
read
its blocked-path counter: above 12 it takes a detour
cameraDistance
number
read
distance to the camera, as the game measured it this frame
blend
table
read
the animation blend: {anim, time, t, active}: the animation it blends from, its time, the blend clock (above 0.25 s the blend ends)
huntable
boolean
read
its species gives a trophy
dangerous
boolean
read
its species is dangerous (a call scares the others)
flyer
boolean
read
its species flies (a credit per shot, no trophy)
locked
boolean
read
trophy room: this trophy is locked
bleeding
number
read / write
seconds of bleeding left (a wound adds 90; the blood trail)
targetTime
number
read / write
seconds on its walk target (above 30 its AI picks a new one)
skid
table
read / write
the skid after a hard turn at speed: {time (seconds), x, z} (raptors; Ice Age: Diatryma, Titanis)
brain
string|function|nil
read / write
what runs in place of its species' AI: a species id (that species' own AI, when the animations line up: ai.compatible), "prey", "predator", "defender" (Ice Age-style brains for any species) or function(c, dt) (your own, once per frame; the game still bleeds it, scales it by c.speed, runs its fights and creature_after_ai); nil = its own. Dead creatures always use their own death. See the behaviour guide
tame
boolean
read / write
it ignores the hunter: never notices, hunts, flees or attacks him (pets)
mood
string
read / write
"calm", "alert" (it knows about the hunter), "hunt" (it chases him), "flee" (it runs from him) or "dead". Setting it is the safe way to steer its AI: "calm" calms it, "alert" alarms it as a noise would (it reacts as its species does), "hunt" sends it at the hunter (a plant eater whose AI only flees flees), "flee" makes it run (predators and charging animals run for 12 s)
alerted
boolean
read
its AI knows about the hunter (alarm state or fear time)
huntingPlayer
boolean
read
it chases the hunter right now (its AI's way leads at him)
Every member of the creature's struct. The raw layer: every member of the game's struct by its C++ name (m_unk94) or its friendly alias (velocity). fields() describes them (FieldInfo): name, alias, type, access (r, rw, or rw! = writable but the game recomputes or eases it), offset, min, max, recomputed (what overwrites it), note, games. Writes are checked: type, range and the field's own rule (an animation of its species, a time inside it ...); a bad value raises an error and changes nothing.
Returns
table
a list of FieldInfo
for _, d in ipairs(c:fields()) doprint(d.name, d.alias, d.access, c:get(d.name)) end
Writes one member. Fields the game recomputes every frame are read-only (r); rw! ones take the value, but the game eases them back (an impulse). Health goes through c.health (the death path).
Parameter
Type
name
string
a member or its alias
value
any
checked: type, range, the field's rule
c:set("noFind", 0) -- aim at the target again now
c:set("velocity", 0.002) -- a push forward
One frame of walking toward a point the way the game's AIs walk: way finding around trees, rocks and water (LookForAWay; when the way stays blocked, by a cliff or a slope too steep, it turns aside for a moment before aiming at the point again, as the AIs do), turning, speeding up and slowing down, the terrain collision and tilt, its walk animation with its sound. Call it every frame (from a brain or a frame handler) for a creature whose AI you replaced.
Parameter
Type
x
number
z
number
optsoptional
table
arrive (the radius it stops within, default 300), speed (units per second, default its species' walk), water (true: it may walk into water)
Returns
number
distance left
boolean
arrived (it stands there, playing its idles)
pet.brain = function(c, dt)
local x, _, z = player.pos()
c:walkTo(x, z, {arrive = 600})
end
One frame standing: it slows down and plays its calm idles (another one now and then, with its sound); species without idles finish their step and hold it (ai.setIdles names some for them).
The game's own test (AI_CheckAfraid) for this creature now: the distance, where it looks, the wind, cover between them, camouflage and cover scent, its species' senses and c.sight / c.smell. It changes nothing.
The game's attack: when the hunter is within reach of its mouth it turns to him, plays its attack and kills him (AddDeadBody: creature_attack and player_death fire; god mode and c.canKillHunter apply).
It goes after another creature with its own chase and attack (the fights' code), also while world.fights is off; the victim reacts as in fights (flees, fights back). It ends when either dies or is removed. The same as c.target = other; it works for creatures run by their AI or by a brain that calls c:stockAI().
It takes a hit as from a shot: the damage event, its health, the alarm (it flees or attacks as its species does) and a blood trail; at 0 it dies through the death path.
Parameter
Type
amount
number
damage in the game's health units
optsoptional
table
attacker (a Creature), byHunter (the hunter's kill: trophy), calm (no alarm), bleed (default true: a blood trail)
Returns
number
the damage it took (after c.armor and the damage event)
Sets its walk target that far away from a point, as the AIs flee. With its own AI combine it with c.mood = "flee"; a brain then runs there with c:runTo(c.targetX, c.targetZ).
Its jump / lunge animation with a leap forward (raptors, the Allosaurus, the Spinosaurus, Ice Age's Diatryma ...). Its AI, or c:walkTo / c:runTo, carry the leap on.
{predator, attacks, hunting, alerted, mood, distance, heading (1 = it faces the hunter), closing (units per second toward him), eta (seconds, while closing)}
Whether it knows about the hunter, and what told it.
Returns
string?
"sight", "smell", "hearing", "shot", "hurt", "attack", "near", "script" or "unknown"; nothing while it is calm
Species ids
Each game has its own species (game.id() tells which game a mod runs in). Hunts: hunts other creatures when fights are on. Animations: the animation numbers its AI uses (for c.anim).
Dinosaur Hunter (game.id() == "dinohunter")
id
type
Species
Hunts
Animations
moschops
7
Moschops
walk 1, run 0, idle 3 4
gallimimus
8
Gallimimus
walk 1, run 0, idle 4 5
dimorphodon
9
Dimorphodon (flyer)
fly 1, 0
pteranodon
10
Pteranodon (flyer)
fly 1, 0
dimetrodon
11
Dimetrodon
walk 0, run 1, idle 2 3
brachiosaurus
12
Brachiosaurus (cannot die)
walk 0, idle 1 2 3
parasaurolophus
16
Parasaurolophus
walk 0, run 1, idle 2 3
ankylosaurus
17
Ankylosaurus
walk 1, run 0, idle 2 3
stegosaurus
18
Stegosaurus
walk 1, run 0, idle 3 4
allosaurus
19
Allosaurus
yes
walk 1, run 0, attack 6, lunge 4
chasmosaurus
20
Chasmosaurus
walk 1, run 0, idle 2 3 4
velociraptor
21
Velociraptor
yes
walk 1, run 0, attack 6, lunge 4
spinosaurus
22
Spinosaurus
yes
walk 1, run 0, idle 3 4, attack 7, lunge 5
ceratosaurus
23
Ceratosaurus
yes
walk 0, run 1, idle 2 3 4, attack 7
trex
24
Tyrannosaurus rex
yes
walk 1, run 0, idle 4 6, roar 2, attack 9
pachycephalosaurus
25
Pachycephalosaurus
walk 0, run 1, idle 4 5
amargasaurus
26
Amargasaurus
walk 1, run 0, idle 3 4 5
oviraptor
27
Oviraptor
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
troodon
28
Troodon
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
utahraptor
29
Utahraptor
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
carnotaurus
30
Carnotaurus
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
gigantoraptor
31
Gigantoraptor
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
coelophysis
32
Coelophysis
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
iguanodon
33
Iguanodon
walk 0, run 1, idle 2 3, attack 7, lunge 9
dilophosaurus
35
Dilophosaurus (unreleased in the original; its files ship with the game)
yes
walk 0, run 1, idle 2 3, attack 7, lunge 9
Ice Age (game.id() == "iceage")
id
type
Species
Hunts
Animations
pig
107
Pig
walk 0, run 1, idle 2 3 4
archaeopteryx
108
Archaeopteryx (flyer)
fly 1, 0
brontoteriy
116
Brontoteriy
walk 0, run 1, idle 2 3 4, attack 7
wildboar
117
Wild Boar
walk 0, run 1, idle 2 3 4, attack 7
wolf
118
Wolf
yes
walk 0, run 1, idle 2 3 4, attack 8
rhinoceros
119
Wooly Rhinoceros
walk 0, run 1, idle 2 3 4, attack 7
diatryma
120
Diatryma
yes
walk 0, run 1, idle 2 3, attack 8, lunge 4
deer
121
Megaloceros
walk 0, run 1, idle 2 3, attack 6
smilodon
122
Smilodon
yes
walk 0, run 1, idle 2 3 4, attack 8
mammoth
123
Mammoth
walk 0, run 1, idle 2 3, attack 6
bear
124
Bear
yes
walk 0, run 1, idle 2 3 4, attack 7
indricothere
125
Indricotherium
walk 0, run 1, idle 2 3 4 8 10, attack 7, lunge 11