world

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") or by type number (see the species table below). Mod species from content packs have ids too.

Functions

# world.spawn(species, x, z, yaw?) → Creature|nil

hunt only

Adds a creature. Species the hunt did not load are loaded first (a short pause). Fires spawn.

ParameterType
speciesSpeciesspecies id or type, e.g. "trex"
xnumber
znumber(it stands on the ground)
yaw optionalnumberheading in degrees (default: facing the hunter)
Returns
Creature|nilthe new creature, nil when it could not be added (logged)
local x, _, z = player.pos()
local rex = world.spawn("trex", x + 3000, z)
rex.scale = 2

# world.spawnNear(species, distance?) → Creature|nil

hunt only

Adds a creature in front of the hunter, facing him.

ParameterType
speciesSpeciesspecies id or type
distance optionalnumberunits in front of the hunter (default 1500)
Returns
Creature|nil
world.spawnNear("velociraptor", 1200)

# world.inFront(distance?) → number, number, number

hunt only

The point on the ground in front of the hunter.

ParameterType
distance optionalnumberdefault 1000
Returns
numberx
numbery (ground)
numberz

# world.creatures(filter?) → table

Finds creatures: living ones by default; dead = true for bodies only, all = true for both. Distances are from x, z when given, else from the hunter.

ParameterType
filter optionalFilterspecies id, or {species=, radius=, x=, z=, team=, dead=, all=}
Returns
tablea list of Creature, nearest first
for _, c in ipairs(world.creatures({radius = 5000})) do
  print(c.name, math.floor(c.distance))
end

# world.nearest(filter?) → Creature|nil

The nearest matching creature.

ParameterType
filter optionalFilteras world.creatures
Returns
Creature|nil
local rex = world.nearest("trex")

# world.count(filter?) → integer

How many living (or matching) creatures there are.

ParameterType
filter optionalFilteras world.creatures
Returns
integer

# world.get(index) → Creature|nil

The creature in a slot (see Creature.index).

ParameterType
indexintegera character index
Returns
Creature|nil

# world.byId(id) → Creature|nil

Finds a creature again by its id.

ParameterType
idintegera Creature.id
Returns
Creature|nilnil when it no longer exists

# world.killAll()

Every living creature dies.

# world.removeAll()

Every living creature disappears (bodies stay).

# world.clearBodies()

Every dead body disappears.

# world.fights(on?) → boolean

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.

ParameterType
on optionalbooleanswitch
Returns
booleanwhether creatures fight

# world.clearTeams()

Every creature's team back to 0.

# world.god(on?) → boolean

God mode: the hunter takes no damage and cannot die.

ParameterType
on optionalbooleanswitch
Returns
boolean

# world.invisible(on?) → boolean

Creatures do not notice the hunter (no sight, smell or hearing).

ParameterType
on optionalbooleanswitch
Returns
boolean

# world.frozen(on?) → boolean

Every creature stands still; the hunter still moves.

ParameterType
on optionalbooleanswitch
Returns
boolean

# world.possessed() → Creature|nil

The creature the player drives (c:possess).

Returns
Creature|nil

# world.unpossess()

Back to the hunter.

# world.ground(x, z) → number

hunt only

Terrain height.

ParameterType
xnumber
znumber
Returns
numberthe ground height there

# world.water(x, z) → number?

hunt only

Water at a point.

ParameterType
xnumber
znumber
Returns
number?the water surface height, nothing on dry land

# world.species() → table

Every species that can be spawned (content packs' too).

Returns
tablea list of {id, type, name, predator, loaded}

# world.trace(x1, y1, z1, x2, y2, z2) → string?, number?, number?, number?, Creature?

hunt only

What a straight line hits first (the game's own shot tracer): line of sight, explosions, lasers.

ParameterType
x1number
y1number
z1number
x2number
y2number
z2number
Returns
string?"terrain", "water", "object" or "creature"; nothing when the line is free
number?x of the point hit
number?y
number?z
Creature?the creature hit
-- 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)
if not kind then print("in plain view") end

Creature

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

FieldTypeAccess
indexintegerreadits slot in the game's character list (reused by later creatures; prefer id)
idintegerreada number unique to this creature while it exists: store it, find it again with world.byId
validbooleanreadfalse once it was removed or a new hunt began (every other field then raises an error)
alivebooleanreadtrue while its health is above 0
typeintegerreadthe game's character type number
speciesstringreadthe species id, e.g. "trex" (see the species table)
namestringreadthe species' name in the game's language
xnumberread / writeposition
ynumberread / writeheight (its feet)
znumberread / writeposition
yawnumberread / writeheading in degrees (same convention as player.yaw)
healthnumberread / writehealth in the game's units (a T-Rex has 1024); 0 kills it
maxHealthnumberreadits species' full health (or more, if it had more)
scalenumberread / writesize factor: 1 = its model's size; trophies and the game's stats use it
heightnumberreadthe height of its model at its scale
animintegerread / writethe animation playing (0 = the first one of its model); setting it blends to the new one
animTimenumberread / writeseconds into the current animation
animLengthnumberreadlength of the current animation in seconds
animNamestringreadname of the current animation in its model
animCountintegerreadhow many animations its model has
distancenumber|nilreaddistance to the hunter on the ground (nil outside a hunt)
teamintegerread / writeits team for world.fights (0 = none)
targetCreature|nilreadcreature fights: the creature it hunts
attackingbooleanreadcreature fights: attacking right now
fleeingbooleanreadcreature fights: running away
killsintegerreadcreature fights: its kills
damageDealtnumberreadcreature fights: damage it dealt
damageTakennumberreadcreature fights: damage it took
stateintegerread / writeits AI's state number (species-specific; 0 = calm in most)
afraidnumberread / writeits AI's fear timer in seconds (it flees while above 0)
targetXnumberread / writewhere its AI walks to (x); the AI may change it
targetZnumberread / writewhere its AI walks to (z)
aibooleanread / writefalse = the game's AI no longer runs for it: your script moves and animates it
predatorbooleanreadwhether its species hunts
possessedbooleanreadwhether the player drives it (c:possess())
datatableread / writea table for your own data about this creature; dropped with the creature
tintColor|nilread / writea colour laid over its model (team colours, glowing bosses); the alpha is the strength; nil = none
speednumberread / writeits time factor: its AI and animations run this much faster (2) or slower (0.5); 0 freezes it
sightnumberread / writehow well it sees the hunter (1 = its species' normal, 2 = twice as far, 0.5 = half)
smellnumberread / writehow well it smells the hunter
hearingnumberread / writehow far it hears noises (0 = deaf)

Methods

# c:kill() → boolean

It dies (its death animation; it leaves a body).

Returns
booleanfalse when it was not alive

# c:remove() → boolean

It disappears (alive or a body).

Returns
boolean

# c:teleport(x, z, y?)

Moves it; its AI's walk target moves along.

ParameterType
xnumber
znumber
y optionalnumberheight (default: the ground)

# c:face(x, z)

Turns it towards a point.

ParameterType
xnumber
znumber

# c:move(distance, yaw?)

Moves it on the ground along its heading: for creatures whose AI you switched off.

ParameterType
distancenumberunits forward (negative = back)
yaw optionalnumberdirection (default: its heading)

# c:distanceTo(other, z?) → number

Distance to another creature or a point.

ParameterType
otherCreature|numbera creature, or x
z optionalnumberz, when x was given
Returns
numberdistance on the ground

# c:animate(dt?) → boolean

Plays its current animation on: for creatures whose AI is off (with the AI on, the AI does this).

ParameterType
dt optionalnumberseconds (default: this frame's)
Returns
booleantrue when the animation wrapped around

# c:anims() → table

The names of its model's animations.

Returns
tablenames; names[i + 1] is animation i

# c:findAnim(name) → integer|nil

Finds an animation by name.

ParameterType
namestringpart of an animation name, e.g. "run" (case does not matter)
Returns
integer|nilthe animation index
local run = c:findAnim("run")
if run then c.anim = run end

# c:possess() → boolean

The player drives it: W/S, A/D turn, Shift runs, click attacks, Space jumps. Ends with world.unpossess() or its death.

Returns
booleanfalse when it cannot be possessed (dead, a flyer, not in a hunt)

# c:follow(distance?)

The camera follows it (camera.follow).

ParameterType
distance optionalnumbercamera distance

# c:alert(seconds?)

It notices danger (flees or attacks, as its species does).

ParameterType
seconds optionalnumberhow long it stays alarmed (default 20)

# c:sound(n, volume?)

Plays one of its species' sounds where it stands.

ParameterType
nintegerthe sound number in its model (0 = first)
volume optionalnumber0-1

# c:screen() → number?, number?

Where its head is on the screen, for labels.

Returns
number?screen x of the top of its head (nothing when behind the camera)
number?screen y
local sx, sy = c:screen()
if sx then draw.text(sx, sy - 20, c.name, "white", 18, "center") end

# c:pos() → number, number, number

Its position in one call.

Returns
numberx
numbery
numberz

Species ids

idtypeSpeciesHunts
moschops7Moschops
gallimimus8Gallimimus
dimorphodon9Dimorphodon (flyer)
pteranodon10Pteranodon (flyer)
dimetrodon11Dimetrodon
brachiosaurus12Brachiosaurus
parasaurolophus16Parasaurolophus
ankylosaurus17Ankylosaurus
stegosaurus18Stegosaurus
allosaurus19Allosaurusyes
chasmosaurus20Chasmosaurus
velociraptor21Velociraptoryes
spinosaurus22Spinosaurusyes
ceratosaurus23Ceratosaurusyes
trex24Tyrannosaurus rexyes
pachycephalosaurus25Pachycephalosaurus
amargasaurus26Amargasaurus
oviraptor27Oviraptoryes
troodon28Troodonyes
utahraptor29Utahraptoryes
carnotaurus30Carnotaurusyes
gigantoraptor31Gigantoraptoryes
coelophysis32Coelophysisyes
iguanodon33Iguanodon
dilophosaurus35Dilophosaurus (unreleased in the original; its files ship with the game)yes