Game data: every field from Lua
Since API 3 a script mod can read, and where it is safe change, every value of the game's objects: creatures, species, weapons and the hunter's weapon slots, the hunter himself, his equipment, the weather, the wind, the time of day, the hunt and the profile. That is close to editing the game's code, without touching it.
Two layers:
- Friendly names for everything a mod usually wants:
c.velocity,world.species("trex").mass,player.slot().ammo,world.weather.fogEnd,hunt.rules.relocateDelay. - The raw layer for everything else: each object has
fields(),get(name)andset(name, value), which reach every member of the game's own struct by its C++ name (m_unk94) or its alias (velocity).
Add "api": 3 to your mod.json when you use them (API versions).
local rex = world.species("trex")
rex.mass = 12 -- heavier trophies, at once
rex.health = 3000 -- the T-Rexes spawned from now on
rex:applyToLiving() -- and the ones already walking around
player.speed(1.5) -- the hunter walks and swims 50% faster
world.weather.fogEnd = 9000 -- thicker fog on this map
weapons.get("rifle").power = 300
What lasts how long
| What you change | Examples | Lasts |
|---|---|---|
| Definitions | species, weapon definitions, weather, the wind lock, the next hunt's time of day, hunt.rules, hunt.balance, the hunter's overrides (player.speed ...), weapons.spreadScale ... |
until your mod unloads (F9, Reload scripts, the Mods screen, quitting): then the game's values come back |
| Instances | a creature's fields, the hunter's own state (health, position, binoculars), slot ammunition, hunt.credits, cooldowns, equipment switches |
the hunt: the next hunt starts as the game sets it up |
| The profile | profile.credits, profile.relocations, profile.resupplies |
saved with the game, like a purchase; every write is logged |
Definitions are journaled: the first time any mod changes one, the game's value is kept, with the list of mods that
changed it; when the scripts unload, every one goes back. game.changes() lists them:
for _, c in ipairs(game.changes()) do
print(c.what, "was", c.original, "changed by", table.concat(c.mods, ", "))
end
-- species trex mass was 6 changed by heavy_rex
-- player speed was 1 changed by sprint
A species or weapon changed by a script stays changed through everything the game does to it: each spawn (the content
registry writes its values again), a content pack defined at run time, a model loaded again. If the registry itself
changes a value under yours (another mod's content.define), that becomes the value your change goes back to.
Weather belongs to the map: a new hunt loads its map's own weather, and your changes on the old map are gone with it.
Creatures
Every creature handle has new fields (the world page lists them all):
| Field | Access | |
|---|---|---|
visible, swimming |
read | drawn this frame; swimming in deep water |
pitch, roll, targetYaw |
read | body angles and the heading its AI turns to (degrees) |
velocity, turnRate |
read | units per second, degrees per second |
stuck, cameraDistance, blend |
read | path counter, distance to the camera, the animation blend |
huntable, dangerous, flyer, locked |
read | its species' flags; a locked trophy (trophy room) |
bleeding, targetTime, skid |
read / write | seconds of bleeding left; seconds on its walk target; the skid {time, x, z} |
Values the game recomputes every frame are read-only: writing them would do nothing. c:fields() shows every member
with what overwrites it; c:get / c:set reach them:
local c = world.nearest("velociraptor")
for _, d in ipairs(c:fields()) do
print(d.name, d.alias or "", d.access, d.recomputed or "", c:get(d.name))
end
c:set("noFind", 0) -- aim at its target again now
c:set("velocity", 0.003) -- "rw!": a push; its AI eases it back to its animation's speed
c:set("anim", 99) -- error: not an animation of its species (0-11)
access is r (read-only), rw, or rw! (it takes the value, but the game eases or recomputes it: an impulse).
Every write is checked (type, range, and the field's own rule: an animation of its species, a time inside that
animation ...). A bad value raises an error and changes nothing. Health is only written through c.health.
Species
world.species(id) returns the species itself (world.species() without an argument is still the list):
| Field | Acts |
|---|---|
mass, size, radius, score, smell, sight, flags (huntable, dangerous, flyer) |
at once |
carryHeight |
the drop ship's next pickup |
health, scaleMin, scaleRange |
creatures spawned from now on; s:applyToLiving() for the living ones |
callVariants |
the next call (1-3) |
local raptor = world.species("velociraptor")
raptor.sight = 2 -- sees the hunter from twice as far
raptor:animFps(1, raptor:animFps(1) * 2) -- its run animation twice as fast
raptor:animSound(0, -1) -- its walk is silent
print(inspect(raptor:anims())) -- {index, name, fps, frames, length, sound} each
raptor:reset() -- the game's values again
s:animFps changes an animation's speed; its length follows, and the creatures playing it stay inside it. The AIs'
walking speeds are their own numbers: a faster walk animation looks like sliding less or more.
Weapons
weapons.get(id) is a weapon's definition: power, precision, pellets, loudness, rate, ammo (per hunt),
magazine, aimFov, aimTime. The hunter's own slots are player.slot(n) (0-7; no argument: the weapon in hand) and
player.weapons() (the slots he carries); player.weapon() stays the number of the slot in hand.
local s = player.slot()
s.ammo = s.ammo + 20 -- more rounds
s.cooldown = 0 -- fire again at once
player.slot(4).available = true -- give him the rifle now (its model loads)
player.setWeapon(4) -- and take it out (the game's own change: weapon_change fires)
if player.slot(4):fire() then print("bang") end -- through the game's Weapon_Fire
weapons.spreadScale(0) -- every shot dead accurate
weapons.recoilScale(0.5) -- half the kick
A scripted shot goes along the view as it is at that moment: player.setYaw / player.setPitch followed by
slot:fire() in the same frame shoot where they point. What makes such a
shot miss at a distance is the weapon's spread and the kick of the shot before: set weapons.spreadScale(0) and
weapons.recoilScale(0) while a script aims.
The hunter
Read-outs: player.velocity(), player.swimming(), player.underwater(), player.inWater(), player.breath(),
player.scoped(), player.scanned() (the creature in the binoculars), player.killer(), player.evacuating(),
player.relocating(). Impulses: player.kick(amount) (a recoil kick of the camera), player.jump([speed]).
Overrides (each kept until your mod unloads; nil puts the game's value back):
| Function | The game's value |
|---|---|
player.speed(k) |
factor 1 on walking and swimming |
player.runScale(k) |
factor 1 on the forward speed factor |
player.jumpPower(k) |
factor 1 on jumps (800 + forward speed x 800) |
player.gravity(g) |
3000 units/s² |
player.eyeHeight(h) |
256 (180 or lower is a crouch: creatures see him worse, by the game's own rule) |
player.regenRate(r), player.drownRate(r), player.fogRate(r) |
4, 12, 64 health per second |
player.maxHealth(h) |
128 (each hunt starts with it) |
The game's own ways out, with their costs and counts: player.evacuate(), player.relocate(x, z) (the cooldown and,
in Dinosaur Hunter, a relocation of the profile), player.resupply() (one of the hunt's resupplies). Each returns
true, or false and the reason, and fires the request event like the game's buttons (Creature behaviour),
so a mod can refuse it there.
Equipment
equipment.camouflage, scent, radar, tranquilizer, binoculars switch the items on and off for this hunt
(f() reads, f(true) switches); equipment.observer() and equipment.doubleScore() are read only. An item switched
mid-hunt changes the score bonus of the trophies taken after it.
The world
world.weather: fogStart, fogEnd, skyColor, sunColor, shadowColor, skyPlaneColor (the creatures' and the
hunter's light follows the sun and shadow colours), cloudsSpeed, snow (Ice Age; since API 4 Dinosaur Hunter too:
Weather), the map's fog volumes
(weather:fog(i), weather:setFog(i, altitude, poisonous)) and waters (weather:water(i), weather:setWater(i,
color, opacity)), and viewDistance (it can only be lowered: set fogEnd below it to hide the edge).
world.weather:reset() puts the map's own weather back while your mod keeps running (every script's weather changes on
this map are undone, as when the scripts unload).
Rain, thunderstorms, snow, fog and presets that fade all of these fields in and out are the weather namespace
(API 4): Weather.
world.wind: yaw (where it blows to), speed, and locked: the game's wind stops changing.
world.time() is the loaded map's time of day. It is chosen when a map loads (the sky, shadows and sounds come from
it), so a mod sets it for the hunts loaded from now on: world.nextTime("night").
on("hunt_start", function()
local w = world.weather
w.fogStart, w.fogEnd = 2000, 6000
w.skyColor = "#8a9aa8"
world.wind.locked = true
world.wind.speed = 18
end)
The hunt
hunt.credits, relocateCooldown, resupplies, relocations, call (the decoy's species), callCooldown are
counters of this hunt; hunt.trophies(), stats(), licensed(), ship(), supply() and survive() read its state.
hunt.rules holds session versions of the rules: relocateDelay, evacuateDelay, resupplyThreshold,
resupplyInWater, the score rules (scoreMultiplier, unlicensedScore, comboBonus, flyerCredits) and the
equipment bonuses (bonusCamouflage ...). hunt.balance(key, value) is a session version of any balance value.
hunt.rules.relocateDelay = 10 -- relocate every 10 seconds
hunt.rules.scoreMultiplier = 2 -- double credits while this mod runs
The profile
profile.credits, profile.relocations, profile.resupplies read and write the saved profile (every write is
logged); profile.trophies() and profile.stats() read it. Licences stay content.unlocked / content.unlock.
Multiplayer
On a client, the host drives the creatures: their position, angles, health, size and animation come from the host
every frame, so a client's writes to those are overwritten. Definitions, the weather and the time of day are each
player's own; a mod that wants them the same everywhere sends them with net.
Without mods
Nothing of this changes the game unless a script writes: every override starts as the game's own value, and the points where the game reads them hand back exactly the original numbers.