---@meta
-- Carnivores: Dinosaur Hunter HD (PC) modding API, for the Lua language server (VS Code: the 'Lua' extension).
-- Put this file into your workspace (or point Lua.workspace.library at it) for autocompletion and docs.

---@class Creature
---@field index integer its slot in the game's character list (reused by later creatures; prefer id)
---@field id integer a number unique to this creature while it exists: store it, find it again with world.byId
---@field valid boolean false once it was removed or a new hunt began (every other field then raises an error)
---@field alive boolean true while its health is above 0
---@field type integer the game's character type number
---@field species string the species id, e.g. "trex" (see the species table)
---@field name string the species' name in the game's language
---@field x number position
---@field y number height (its feet)
---@field z number position
---@field yaw number heading in degrees (same convention as player.yaw)
---@field health number health in the game's units (a T-Rex has 1024); 0 kills it
---@field maxHealth number its species' full health (or more, if it had more)
---@field scale number size factor: 1 = its model's size; trophies and the game's stats use it
---@field height number the height of its model at its scale
---@field anim integer the animation playing (0 = the first one of its model); setting it blends to the new one
---@field animTime number seconds into the current animation
---@field animLength number length of the current animation in seconds
---@field animName string name of the current animation in its model
---@field animCount integer how many animations its model has
---@field distance number|nil distance to the hunter on the ground (nil outside a hunt)
---@field team integer its team for world.fights (0 = none)
---@field target Creature|nil creature fights: the creature it hunts
---@field attacking boolean creature fights: attacking right now
---@field fleeing boolean creature fights: running away
---@field kills integer creature fights: its kills
---@field damageDealt number creature fights: damage it dealt
---@field damageTaken number creature fights: damage it took
---@field state integer its AI's state number (species-specific; 0 = calm in most)
---@field afraid number its AI's fear timer in seconds (it flees while above 0)
---@field targetX number where its AI walks to (x); the AI may change it
---@field targetZ number where its AI walks to (z)
---@field ai boolean false = the game's AI no longer runs for it: your script moves and animates it
---@field predator boolean whether its species hunts
---@field possessed boolean whether the player drives it (c:possess())
---@field data table a table for your own data about this creature; dropped with the creature
---@field tint string|table|nil a colour laid over its model (team colours, glowing bosses); the alpha is the strength; nil = none
---@field speed number its time factor: its AI and animations run this much faster (2) or slower (0.5); 0 freezes it
---@field sight number how well it sees the hunter (1 = its species' normal, 2 = twice as far, 0.5 = half)
---@field smell number how well it smells the hunter
---@field hearing number how far it hears noises (0 = deaf)
local Creature = {}
--- It dies (its death animation; it leaves a body).
---@return boolean # false when it was not alive
function Creature:kill() end
--- It disappears (alive or a body).
---@return boolean # 
function Creature:remove() end
--- Moves it; its AI's walk target moves along.
---@param x number 
---@param z number 
---@param y? number height (default: the ground)
function Creature:teleport(x, z, y) end
--- Turns it towards a point.
---@param x number 
---@param z number 
function Creature:face(x, z) end
--- Moves it on the ground along its heading: for creatures whose AI you switched off.
---@param distance number units forward (negative = back)
---@param yaw? number direction (default: its heading)
function Creature:move(distance, yaw) end
--- Distance to another creature or a point.
---@param other Creature|number a creature, or x
---@param z? number z, when x was given
---@return number # distance on the ground
function Creature:distanceTo(other, z) end
--- Plays its current animation on: for creatures whose AI is off (with the AI on, the AI does this).
---@param dt? number seconds (default: this frame's)
---@return boolean # true when the animation wrapped around
function Creature:animate(dt) end
--- The names of its model's animations.
---@return table # names; names[i + 1] is animation i
function Creature:anims() end
--- Finds an animation by name.
---@param name string part of an animation name, e.g. "run" (case does not matter)
---@return integer|nil # the animation index
function Creature:findAnim(name) end
--- The player drives it: W/S, A/D turn, Shift runs, click attacks, Space jumps. Ends with world.unpossess() or its death.
---@return boolean # false when it cannot be possessed (dead, a flyer, not in a hunt)
function Creature:possess() end
--- The camera follows it (camera.follow).
---@param distance? number camera distance
function Creature:follow(distance) end
--- It notices danger (flees or attacks, as its species does).
---@param seconds? number how long it stays alarmed (default 20)
function Creature:alert(seconds) end
--- Plays one of its species' sounds where it stands.
---@param n integer the sound number in its model (0 = first)
---@param volume? number 0-1
function Creature:sound(n, volume) end
--- Where its head is on the screen, for labels.
---@return number? # screen x of the top of its head (nothing when behind the camera)
---@return number? # screen y
function Creature:screen() end
--- Its position in one call.
---@return number # x
---@return number # y
---@return number # z
function Creature:pos() end

---@class Event
---@field name string
---@field cancelled boolean|nil
---@field [string] any

--- Writes a line to the console ( ) and the game's log, prefixed with your mod's id: [mymod] hello.
---@param ... any values, converted with tostring and separated by spaces
function print(...) end
--- Loads a Lua file of your mod once and returns its result; later calls return the same value. The module runs in your mod's sandbox (its globals are your globals).
---@param name string a module of your mod: "util" loads util.lua, "ai.raptor" loads ai/raptor.lua (or ai/raptor/init.lua); "@othermod/name" loads a module from another enabled mod's folder
---@return any # what the module returned (true when it returned nothing)
function require(name) end
--- Compiles Lua code from a string (text only, never binary chunks).
---@param text string Lua source code
---@param chunkname? string name shown in error messages
---@param mode? string ignored: only text is accepted
---@param env? table the chunk's global table (default: your sandbox)
---@return function|nil # the compiled chunk
---@return string? # the error when it does not compile
function load(text, chunkname, mode, env) end
--- Short for events.on: listen for a game event or a custom one.
---@param event string an event name (see Events)
---@param handler function called with the event table
---@param priority? integer higher runs earlier (default 0)
---@return integer # the listener id (for events.off)
function on(event, handler, priority) end
--- Readable text of any value, with tables expanded: handy with print and in the console.
---@param value any anything
---@param depth? integer how deep tables are expanded (default 3)
---@return string # readable text
function inspect(value, depth) end
--- A minimal class helper. Call the class to make an instance; init is its constructor; Class.super is the parent.
---@param parent? table a class to inherit from
---@return table # the new class
function class(parent) end
--- The safe subset of Lua's collectgarbage.
---@param option? string "count" (default), "step" or "collect"
---@return number # Lua memory in KB for "count"
function collectgarbage(option) end

events = {}
--- Calls handler(e) every time the event happens.
---@param event string the event name
---@param handler fun(e: Event) fn(e)
---@param priority? integer higher runs earlier (default 0)
---@return integer # listener id
function events.on(event, handler, priority) end
--- Like events.on, but only for the next time the event happens.
---@param event string the event name
---@param handler fun(e: Event) fn(e)
---@param priority? integer higher runs earlier
---@return integer # listener id
function events.once(event, handler, priority) end
--- Stops a listener.
---@param id integer a listener id from on / once / keys.bind
---@return boolean # true when it was listening
function events.off(id) end
--- Fires a custom event at every mod's listeners, synchronously. e.name is set to the event name.
---@param event string a custom event name, e.g. "mymod:wave"
---@param data? table the event table handlers get (a new one when left out)
---@return table # the event table after every handler ran (read what they set)
function events.emit(event, data) end
--- Whether anybody listens: skip building expensive event data nobody wants.
---@param event string the event name
---@return boolean # true when some mod listens
function events.has(event) end

game = {}
--- Which screen the game is on.
---@return string # the current stage: menu_main, menu_hunt, menu_options, menu_more, menu_help, menu_about, menu_shop, loading, hunt, menu_privacy, privacy_terms, privacy_policy (or none)
function game.stage() end
--- Whether a hunt is running.
---@return boolean # true while hunting (the hunter exists)
function game.inHunt() end
--- The hunt's map.
---@return integer # the area chosen in the hunt menu, 0 to 6
function game.area() end
--- The game version.
---@return string # "2.0.1-pc"
function game.version() end
--- The version of this API. It grows by one with every release that adds to it; nothing is removed. A mod that needs newer functions says so in mod.json ("api": 2); older games then show why it does not run.
---@return integer # the modding API's version (1 in this release)
function game.apiVersion() end
--- Slow motion or fast forward for the whole game (creatures, the hunter, animations, timers of the game).
---@param factor? number 0.05 to 4; 1 = normal
---@return number # the factor
function game.timeScale(factor) end
--- One of the game's texts in the current (or a given) language.
---@param key string a key of the game's strings.csv, e.g. "STR_T_REX"
---@param language? string "en", "de", "fr", "es" ...
---@return string|nil # the text, nil when there is no such key
function game.text(key, language) end
--- Replaces one of the game's texts (menus, messages, names). Texts the game shows from now on use it; menus already built show it the next time they are made. Letters outside Latin-1 become ? (the game's fonts lack them).
---@param key string 
---@param text string|nil the new text; nil = the original again
function game.setText(key, text) end
--- The game's language.
---@return string # "en", "de", "fr", "es" ...
function game.language() end
--- The operating system.
---@return string # "linux" or "windows"
function game.platform() end
--- The window size in UI units (the coordinates of draw. and ui.window).
---@return number # width
---@return number # height
function game.screen() end
--- Whether the hunt is paused.
---@return boolean # true while the game menu (pause) is open
function game.paused() end
--- The game's time step of the last frame (0 while paused).
---@return number # seconds
function game.dt() end
--- The hunt's shooting statistics.
---@return integer # shots fired this hunt
---@return integer # shots that hit
function game.shots() end
--- Shows a short message at the bottom right (the same as ui.toast).
---@param text string the message
---@param seconds? number how long it shows (default 4)
---@param color? string|table text colour (default white)
function game.message(text, seconds, color) end
--- Where a world point appears on the screen, for labels and markers.
---@param x number world x
---@param y number world y (height)
---@param z number world z
---@return number? # screen x (nothing when the point is behind the camera or not in a hunt)
---@return number? # screen y
function game.project(x, y, z) end

player = {}
--- Whether the hunter exists.
---@return boolean # true in a hunt
function player.exists() end
--- The hunter's position.
---@return number # x
---@return number # y (the ground under him)
---@return number # z
function player.pos() end
--- Moves the hunter. player.setPos(x, z) puts him on the ground there.
---@param x number 
---@param y number height; with two arguments (x, z) he stands on the ground
---@param z number 
function player.setPos(x, y, z) end
--- Moves the hunter to x, z on the ground.
---@param x number 
---@param z number 
function player.teleport(x, z) end
--- Where the hunter looks (the heading).
---@return number # degrees 0-360
function player.yaw() end
--- Turns the hunter.
---@param yaw number degrees
function player.setYaw(yaw) end
--- How far up or down he looks.
---@return number # degrees, + up / - down
function player.pitch() end
--- Tilts the view.
---@param pitch number degrees (-89 to 89)
function player.setPitch(pitch) end
--- The unit direction he looks along, on the ground.
---@return number # dx
---@return number # dz
function player.forward() end
--- The hunter's health.
---@return number # current health
function player.health() end
--- Sets his health (he dies only by the game's own causes).
---@param health number above 0, at most player.maxHealth()
function player.setHealth(health) end
--- The hunter's full health.
---@return number # 
function player.maxHealth() end
--- Whether the hunter is alive (false outside a hunt).
---@return boolean # 
function player.alive() end
--- The current weapon.
---@return integer # the weapon slot in hand, -1 = none
function player.weapon() end
--- A weapon's ammunition; nothing outside a hunt, without a weapon in hand, or for the photo camera.
---@param slot? integer a weapon slot (default: the one in hand)
---@return integer? # the ammunition left (what the HUD shows)
---@return integer? # the rounds loaded
function player.ammo(slot) end
--- What is under the crosshair: a ray from the hunter's eyes along his view.
---@param distance? number how far to look (default 20000)
---@return string? # "terrain", "water", "object" or "creature" (nothing when nothing is hit)
---@return number? # x of the point hit
---@return number? # y
---@return number? # z
---@return Creature? # the creature hit
function player.aim(distance) end
--- Where the hunter's eyes (the camera) are.
---@return number # x
---@return number # y
---@return number # z
function player.eye() end
--- The player's credits (the hunt menu's money).
---@return integer # 
function player.credits() end
--- Gives or takes credits (kept with the game's save): rewards, shops, bets.
---@param n integer credits to give; negative takes (not below 0)
---@return integer # the new amount
function player.addCredits(n) end
--- The camouflage item: creatures see the hunter worse.
---@param on? boolean switch it on / off
---@return boolean # whether it is on
function player.camouflage(on) end
--- The cover-scent item: creatures smell the hunter worse.
---@param on? boolean switch it on / off
---@return boolean # whether it is on
function player.scent(on) end

world = {}
--- Adds a creature. Species the hunt did not load are loaded first (a short pause). Fires spawn.
---@param species string|integer species id or type, e.g. "trex"
---@param x number 
---@param z number (it stands on the ground)
---@param yaw? number heading in degrees (default: facing the hunter)
---@return Creature|nil # the new creature, nil when it could not be added (logged)
function world.spawn(species, x, z, yaw) end
--- Adds a creature in front of the hunter, facing him.
---@param species string|integer species id or type
---@param distance? number units in front of the hunter (default 1500)
---@return Creature|nil # 
function world.spawnNear(species, distance) end
--- The point on the ground in front of the hunter.
---@param distance? number default 1000
---@return number # x
---@return number # y (ground)
---@return number # z
function world.inFront(distance) end
--- 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.
---@param filter? string|integer|table species id, or {species=, radius=, x=, z=, team=, dead=, all=}
---@return table # a list of Creature, nearest first
function world.creatures(filter) end
--- The nearest matching creature.
---@param filter? string|integer|table as world.creatures
---@return Creature|nil # 
function world.nearest(filter) end
--- How many living (or matching) creatures there are.
---@param filter? string|integer|table as world.creatures
---@return integer # 
function world.count(filter) end
--- The creature in a slot (see Creature.index).
---@param index integer a character index
---@return Creature|nil # 
function world.get(index) end
--- Finds a creature again by its id.
---@param id integer a Creature.id
---@return Creature|nil # nil when it no longer exists
function world.byId(id) end
--- Every living creature dies.
function world.killAll() end
--- Every living creature disappears (bodies stay).
function world.removeAll() end
--- Every dead body disappears.
function world.clearBodies() end
--- 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.
---@param on? boolean switch
---@return boolean # whether creatures fight
function world.fights(on) end
--- Every creature's team back to 0.
function world.clearTeams() end
--- God mode: the hunter takes no damage and cannot die.
---@param on? boolean switch
---@return boolean # 
function world.god(on) end
--- Creatures do not notice the hunter (no sight, smell or hearing).
---@param on? boolean switch
---@return boolean # 
function world.invisible(on) end
--- Every creature stands still; the hunter still moves.
---@param on? boolean switch
---@return boolean # 
function world.frozen(on) end
--- The creature the player drives (c:possess).
---@return Creature|nil # 
function world.possessed() end
--- Back to the hunter.
function world.unpossess() end
--- Terrain height.
---@param x number 
---@param z number 
---@return number # the ground height there
function world.ground(x, z) end
--- Water at a point.
---@param x number 
---@param z number 
---@return number? # the water surface height, nothing on dry land
function world.water(x, z) end
--- Every species that can be spawned (content packs' too).
---@return table # a list of {id, type, name, predator, loaded}
function world.species() end
--- What a straight line hits first (the game's own shot tracer): line of sight, explosions, lasers.
---@param x1 number 
---@param y1 number 
---@param z1 number 
---@param x2 number 
---@param y2 number 
---@param z2 number 
---@return string? # "terrain", "water", "object" or "creature"; nothing when the line is free
---@return number? # x of the point hit
---@return number? # y
---@return number? # z
---@return Creature? # the creature hit
function world.trace(x1, y1, z1, x2, y2, z2) end

camera = {}
--- The camera follows a creature; the mouse orbits around it. The hunter moves with the camera, so creatures may notice him: combine with world.invisible.
---@param creature Creature|nil nil = the hunter's own view again
---@param distance? number distance behind it
function camera.follow(creature, distance) end
--- The creature the camera follows.
---@return Creature|nil # 
function camera.following() end
--- Distance of the follow camera (default 1500 plus the creature's size).
---@param distance? number new distance
---@return number # the distance
function camera.distance(distance) end
--- Slowly circles the followed creature (for showcases).
---@param degreesPerSecond number 0 = off
function camera.orbit(degreesPerSecond) end

ui = {}
--- A window. Call it from a draw handler every frame it should show.
---@param title string window title (also its identity)
---@param fn function draws the widgets
---@param options? table x, y, w, h (first placement; with fixed = true every frame), alpha, closable, noTitle, noResize, noMove, noScroll, autoResize, noBackground, noInput, noCollapse, noFocus
---@return boolean # false when the player closed it (closable windows)
function ui.window(title, fn, options) end
--- Adds a tab to the mod menu (F1). Call once (e.g. at load); the function runs every frame the tab is shown. Calling again with the same title replaces it.
---@param title string tab title
---@param fn function draws the tab's widgets
function ui.panel(title, fn) end
--- Removes one of your mod menu tabs.
---@param title string 
function ui.removePanel(title) end
--- Shows the mouse cursor during a hunt (mouse look pauses) so your windows can be clicked.
---@param on boolean 
function ui.cursor(on) end
--- A short message at the bottom right.
---@param text string 
---@param seconds? number default 4
---@param color? string|table 
function ui.toast(text, seconds, color) end
--- Whether the mod menu (F1) is open.
---@return boolean # 
function ui.menuOpen() end
--- The window size in UI units.
---@return number # width
---@return number # height
function ui.screen() end
--- A line of text.
---@param ... any values joined by spaces
function ui.text(...) end
--- Coloured text.
---@param color string|table 
---@param text string 
function ui.textColored(color, text) end
--- Text wrapped at the window edge.
---@param text string 
function ui.textWrapped(text) end
--- Greyed-out text (hints).
---@param text string 
function ui.textDisabled(text) end
--- A bullet point.
---@param text string 
function ui.bullet(text) end
--- A separator line with a title.
---@param text string 
function ui.heading(text) end
--- A button.
---@param label string 
---@param w? number width
---@param h? number height
---@return boolean # true the frame it was clicked
function ui.button(label, w, h) end
--- A small button that fits into a line of text.
---@param label string 
---@return boolean # clicked
function ui.smallButton(label) end
--- A checkbox.
---@param label string 
---@param value boolean current value
---@return boolean # the value (changed when clicked)
---@return boolean # true when it changed
function ui.checkbox(label, value) end
--- A radio button.
---@param label string 
---@param active boolean whether this option is the chosen one
---@return boolean # clicked
function ui.radio(label, active) end
--- A slider for numbers.
---@param label string 
---@param value number 
---@param min number 
---@param max number 
---@param format? string printf format, default "%.2f"
---@return number # the value
---@return boolean # changed
function ui.slider(label, value, min, max, format) end
--- A slider for whole numbers.
---@param label string 
---@param value integer 
---@param min integer 
---@param max integer 
---@return integer # value
---@return boolean # changed
function ui.sliderInt(label, value, min, max) end
--- A number changed by dragging.
---@param label string 
---@param value number 
---@param speed? number per pixel dragged (default 1)
---@param min? number 
---@param max? number 
---@return number # value
---@return boolean # changed
function ui.drag(label, value, speed, min, max) end
--- A text field (up to 4095 bytes).
---@param label string 
---@param text? string current text
---@param hint? string grey text while empty
---@return string # the text
---@return boolean # changed
function ui.input(label, text, hint) end
--- A multi-line text field (16 KB).
---@param label string 
---@param text? string 
---@param w? number 
---@param h? number 
---@return string # text
---@return boolean # changed
function ui.inputMultiline(label, text, w, h) end
--- A number field.
---@param label string 
---@param value number 
---@param step? number +/- buttons step (default 1)
---@return number # value
---@return boolean # changed
function ui.inputNumber(label, value, step) end
--- A whole-number field.
---@param label string 
---@param value integer 
---@param step? integer 
---@return integer # value
---@return boolean # changed
function ui.inputInt(label, value, step) end
--- A drop-down list.
---@param label string 
---@param index integer the chosen item, 1-based
---@param items table a list of strings
---@return integer # the chosen index
---@return boolean # changed
function ui.combo(label, index, items) end
--- A clickable line (lists).
---@param label string 
---@param selected? boolean shown highlighted
---@return boolean # clicked
function ui.selectable(label, selected) end
--- A colour picker.
---@param label string 
---@param color string|table current colour
---@return table # {r, g, b, a} 0-1
---@return boolean # changed
function ui.color(label, color) end
--- A progress bar.
---@param fraction number 0-1
---@param label? string text on the bar
---@param w? number width
function ui.progress(fraction, label, w) end
--- A horizontal line.
function ui.separator() end
--- The next widget goes on the same line.
---@param offset? number x position
---@param spacing? number 
function ui.sameLine(offset, spacing) end
--- A little vertical space.
function ui.spacing() end
--- An empty line.
function ui.newLine() end
--- Indents the following widgets.
---@param w? number 
function ui.indent(w) end
--- Undoes ui.indent.
---@param w? number 
function ui.unindent(w) end
--- Empty space of a size.
---@param w number 
---@param h number 
function ui.dummy(w, h) end
--- A collapsible section header.
---@param label string 
---@param open? boolean open at first
---@return boolean # true while open
function ui.collapsing(label, open) end
--- A tree node.
---@param label string 
---@param fn function draws the children
---@param open? boolean open at first
---@return boolean # open
function ui.tree(label, fn, open) end
--- A tab bar.
---@param id string 
---@param fn function calls ui.tab for each tab
function ui.tabs(id, fn) end
--- One tab, inside ui.tabs.
---@param label string 
---@param fn function draws the tab
---@return boolean # true while this tab is shown
function ui.tab(label, fn) end
--- A table.
---@param id string 
---@param columns integer 1-64
---@param fn function fills it with ui.nextRow / ui.nextColumn
---@param headers? table column titles
function ui.table(id, columns, fn, headers) end
--- Starts a table row (and its first cell).
function ui.nextRow() end
--- Moves to the next cell of the row.
---@return boolean # whether the cell is visible
function ui.nextColumn() end
--- A scrolling region inside a window.
---@param id string 
---@param w? number 0 = all
---@param h? number 0 = all
---@param fn function 
---@param border? boolean 
function ui.child(id, w, h, fn, border) end
--- Groups widgets (so ui.sameLine treats them as one).
---@param fn function 
function ui.group(fn) end
--- Widgets inside get a separate identity (loops with repeated labels).
---@param id any 
---@param fn function 
function ui.id(id, fn) end
--- A popup, opened with ui.openPopup.
---@param id string 
---@param fn function 
---@return boolean # open
function ui.popup(id, fn) end
--- Opens a popup.
---@param id string 
function ui.openPopup(id) end
--- Closes the popup the code runs in.
function ui.closePopup() end
--- A tooltip for the last widget when hovered.
---@param text string 
function ui.tooltip(text) end
--- Whether the mouse is over the last widget.
---@return boolean # 
function ui.hovered() end
--- Whether the last widget was clicked.
---@return boolean # 
function ui.clicked() end
--- Width of the next widget.
---@param w number 
function ui.width(w) end
--- Text size of the current window.
---@param factor number 
function ui.scale(factor) end
--- Space left in the window.
---@return number # width
---@return number # height
function ui.available() end
--- An image as a widget.
---@param file string a PNG or TGA file of your mod (path in its folder), or a game file by name
---@param w? number width (default: the image's)
---@param h? number height (default: keeps the shape)
---@return boolean # false when the image could not be loaded (logged once)
function ui.image(file, w, h) end

draw = {}
--- Text with a soft shadow.
---@param x number 
---@param y number 
---@param text any 
---@param color? string|table default white
---@param size? number font size (default the UI font)
---@param align? string "left" (default), "center" or "right" of x
function draw.text(x, y, text, color, size, align) end
--- The size text would take.
---@param text string 
---@param size? number 
---@return number # width
---@return number # height
function draw.textSize(text, size) end
--- A line.
---@param x1 number 
---@param y1 number 
---@param x2 number 
---@param y2 number 
---@param color? string|table 
---@param thickness? number default 1
function draw.line(x1, y1, x2, y2, color, thickness) end
--- A rectangle outline.
---@param x number 
---@param y number 
---@param w number 
---@param h number 
---@param color? string|table 
---@param thickness? number 
---@param rounding? number corner radius
function draw.rect(x, y, w, h, color, thickness, rounding) end
--- A filled rectangle.
---@param x number 
---@param y number 
---@param w number 
---@param h number 
---@param color? string|table 
---@param rounding? number 
function draw.fillRect(x, y, w, h, color, rounding) end
--- A circle outline.
---@param x number 
---@param y number 
---@param r number radius
---@param color? string|table 
---@param thickness? number 
function draw.circle(x, y, r, color, thickness) end
--- A filled circle.
---@param x number 
---@param y number 
---@param r number 
---@param color? string|table 
function draw.fillCircle(x, y, r, color) end
--- A filled triangle (arrows, markers).
---@param x1 number 
---@param y1 number 
---@param x2 number 
---@param y2 number 
---@param x3 number 
---@param y3 number 
---@param color? string|table 
function draw.fillTriangle(x1, y1, x2, y2, x3, y3, color) end
--- A filled bar: health bars, progress.
---@param x number 
---@param y number 
---@param w number 
---@param h number 
---@param fraction number 0-1
---@param color? string|table default green
---@param background? string|table default translucent black
function draw.bar(x, y, w, h, fraction, color, background) end
--- The screen size in UI units.
---@return number # width
---@return number # height
function draw.screen() end
--- Draws an image: PNG (any common kind, not interlaced) or TGA. Loaded on first use and kept.
---@param file string a PNG or TGA file of your mod (path in its folder), or a game file by name
---@param x number 
---@param y number 
---@param w? number width (default: the image's)
---@param h? number height (default: keeps the shape)
---@param color? string|table tint, and alpha for transparency
---@return boolean # false when the image could not be loaded (logged once)
function draw.image(file, x, y, w, h, color) end
--- An image's size in pixels (nothing when it cannot be loaded).
---@param file string 
---@return integer? # width
---@return integer? # height
function draw.imageSize(file) end

hud = {}
--- Hides parts of the game's HUD.
---@param name string an element, or "all"
---@param ... any more elements
function hud.hide(name, ...) end
--- Shows hidden parts again.
---@param name string an element, or "all"
---@param ... any more elements
function hud.show(name, ...) end
--- Whether a part is shown.
---@param name string an element
---@return boolean # 
function hud.shown(name) end
--- Moves a part of the HUD by dx, dy from its own place (0, 0 puts it back); without dx, dy it only returns the offset.
---@param name string a movable element
---@param dx? number to the right
---@param dy? number down
---@return number # dx
---@return number # dy
function hud.offset(name, dx, dy) end
--- Makes a part of the HUD bigger or smaller; without a factor it only returns it. The compass grows away from its corner, texts and bars around their own place.
---@param name string a movable element
---@param factor? number its size: 1 = normal (0.25 to 4)
---@return number # the factor
function hud.scale(name, factor) end
--- Every element, for menus that list them.
---@return table # {{name, description, movable, shown, scale}, ...}
function hud.elements() end
--- Shows every part, normal size, in its own place.
function hud.reset() end
--- Opens the hunt's menu (ESCAPE / RESTART / OPTIONS), like Esc. Not while the hunter is dead or being evacuated.
---@return boolean # whether the menu is open now
function hud.openMenu() end
--- Closes the hunt's menu.
---@return boolean # whether it was open
function hud.closeMenu() end
--- Whether the hunt's menu is open.
---@return boolean # 
function hud.menuOpen() end

sound = {}
--- Plays a sound for the hunter (not positioned).
---@param file string a .wav file name
---@param volume? number 0-1 (default 1)
---@return boolean # false when it could not be played
function sound.play(file, volume) end
--- Plays a sound at a point of the world.
---@param file string 
---@param x number 
---@param y number 
---@param z number 
---@param volume? number 
---@param radius? number how far it carries (default 8000)
---@return boolean # 
function sound.playAt(file, x, y, z, volume, radius) end

keys = {}
--- Calls fn when the key goes down. The game does not see the key, unless fn returns false.
---@param key string key name
---@param fn function fn(e), the key event
---@param priority? integer 
---@return integer # listener id (events.off)
function keys.bind(key, fn, priority) end
--- Whether a key is held right now.
---@param key string key name
---@return boolean # true while held
function keys.down(key) end
--- Mouse position and buttons.
---@return number # x
---@return number # y
---@return boolean # left button
---@return boolean # right
---@return boolean # middle
function keys.mouse() end
--- The player's keys for one of the game's actions.
---@param action string a game action: "fire", "jump", "map" ... (see above)
---@return string? # the first key / button, e.g. "Mouse Left" or "Space"
---@return string? # the second one
function keys.binding(action) end

timer = {}
--- Runs fn once after a delay.
---@param seconds number 
---@param fn function fn(id)
---@return integer # timer id
function timer.after(seconds, fn) end
--- Runs fn again and again. A failing repeating timer is stopped.
---@param seconds number interval
---@param fn function fn(id)
---@return integer # timer id
function timer.every(seconds, fn) end
--- Stops a timer.
---@param id integer 
---@return boolean # true when it was running
function timer.cancel(id) end
--- Seconds since the scripts started.
---@return number # seconds
function timer.now() end

mod = {}
---@type string
mod.id = nil -- your mod's id: its folder or zip name
---@type string
mod.name = nil -- the name from mod.json
---@type string
mod.version = nil -- the version from mod.json
---@type table
mod.exports = nil -- what other mods get with mods.get("yourid"): put functions and data here
---@type table
mod.settings = nil -- the current values of your settings (see mod.setting)
--- Declares a setting the player can change in the mod menu's Settings tab. Values are saved; read them from mod.settings (always current); the setting event tells you when one changed.
---@param key string 
---@param default boolean|number|string its type sets the widget
---@param options? table label, help (tooltip), min + max (a slider), options (a list of strings: a drop-down)
---@return any # the current value (saved from earlier, or the default)
function mod.setting(key, default, options) end
--- Saves data for your mod (JSON in the game's save folder, moddata/<id>.json). One value; use a table for many.
---@param value any tables, strings, numbers, booleans
---@return boolean|nil # true, or nil and an error
function mod.save(value) end
--- Loads what mod.save saved.
---@return any # what mod.save saved, nil when nothing
function mod.load() end
--- Reads a file of your mod (e.g. JSON data).
---@param path string relative to your mod's folder
---@return string|nil # the contents
---@return string? # error
function mod.read(path) end
--- Whether your mod has the file.
---@param path string 
---@return boolean # 
function mod.exists(path) end
--- Lists files of your mod.
---@param folder? string default: the mod's folder
---@return table # names, sorted; folders end in /
function mod.files(folder) end
--- Writes a file into your mod's data folder (moddata/<id>/ in the save folder): logs, exported data, many save slots.
---@param name string a file name, may contain folders: "maps/arena1.json"
---@param text string the contents (text or binary, up to 16 MB)
---@return boolean|nil # true, or nil and an error
function mod.writeData(name, text) end
--- Reads a file of your data folder.
---@param name string 
---@return string|nil # 
function mod.readData(name) end
--- Deletes a file of your data folder.
---@param name string 
---@return boolean # 
function mod.deleteData(name) end
--- Lists the files of your data folder.
---@return table # names (with folders), sorted
function mod.dataFiles() end

mods = {}
--- Another script mod's exports (call it in or after mods_loaded).
---@param id string a mod id
---@return table|nil # its mod.exports
function mods.get(id) end
--- Every installed mod.
---@return table # a list of {id, name, version, author, description, enabled, scripted, loaded, files}
function mods.list() end
--- Whether a mod is installed and on.
---@param id string 
---@return boolean # 
function mods.has(id) end
--- Reloads every script mod at the next frame (as F9).
function mods.reload() end

net = {}
--- Whether the player allowed your mod to use the network.
---@return boolean # 
function net.allowed() end
--- Asks the player for permission (once; the answer is remembered and changeable in F1 → Network). net_consent tells the answer.
---@param reason? string shown to the player
---@return boolean # true when already allowed
function net.request(reason) end
--- Hosts a session.
---@param port? integer UDP port (default 27015)
---@param name? string your player name (default: the Network tab's)
---@param maxPlayers? integer default 8
---@return boolean|nil # true, or nil and an error
function net.host(port, name, maxPlayers) end
--- Joins a session. Asynchronous: net_joined for peer 0 means you are in; net_left for peer 0 carries the reason it failed.
---@param address string IPv4 address or host name
---@param port? integer default 27015
---@param name? string your player name
---@return boolean|nil # true when the attempt started, or nil and an error
function net.join(address, port, name) end
--- Leaves the session (the host ends it for everyone).
function net.leave() end
--- The host removes a player.
---@param peer integer 
---@param reason? string 
function net.kick(peer, reason) end
--- Hosting, joining or joined.
---@return boolean # 
function net.active() end
--- Hosting, or accepted by the host.
---@return boolean # 
function net.connected() end
--- Whether this game hosts.
---@return boolean # 
function net.isHost() end
--- Your player id.
---@return integer # your id (0 = host), -1 outside a session
function net.self() end
--- Your player name.
---@return string # 
function net.name() end
--- The UDP port in use.
---@return integer # 
function net.port() end
--- The last error.
---@return string # 
function net.error() end
--- Everyone in the session, you included.
---@return table # a list of {id, name, ping, host, self}
function net.peers() end
--- Traffic statistics.
---@param peer? integer one player (default: all traffic)
---@return table # {ping, bytesSent, bytesReceived, packetsSent, packetsReceived, resends, sendRate, receiveRate}
function net.stats(peer) end
--- Sends a message.
---@param to integer|nil a player id, nil = everyone else
---@param topic string your message name, e.g. "mymod:score"
---@param data any string, number, boolean or table (as JSON)
---@param reliable? boolean default true; false for small, frequent state
---@return boolean|nil # true, or nil and an error
function net.send(to, topic, data, reliable) end
--- Listens for messages of one topic.
---@param topic string 
---@param fn function fn(e): e.from, e.topic, e.data, e.reliable
---@param priority? integer 
---@return integer # listener id (events.off)
function net.on(topic, fn, priority) end
--- Asks the local network for games (answers in net.lanGames a moment later).
---@param port? integer default 27015
---@return boolean|nil # 
function net.discover(port) end
--- Games found on the local network.
---@return table # a list of {address, port, name, players, maxPlayers}
function net.lanGames() end
--- The automatic sync of creatures, players and hits (switch it on in every game).
---@param on? boolean 
---@return boolean # whether the automatic sync is on
function net.sync(on) end
--- Tunes the automatic sync.
---@param settings? table {rate, nearRadius, sweepSeconds, hits, hunters}
---@return table # the current settings
function net.syncSettings(settings) end
--- Whether creatures notice and attack the other players too (default on).
---@param on? boolean 
---@return boolean # 
function net.huntRemotes(on) end
--- Whether this game shows the host's creatures.
---@return boolean # 
function net.mirroring() end
--- The figure of another player in your game.
---@param peer integer 
---@return Creature|nil # 
function net.standIn(peer) end
--- The player a figure stands for (nil: a normal creature).
---@param c Creature 
---@return integer|nil # 
function net.standInPeer(c) end
--- Another player's latest state.
---@param peer integer 
---@return table|nil # {x, y, z, yaw, pitch, weapon, health, inHunt, hidden}
function net.remoteHunter(peer) end
--- The creature's index in the host's game: the same number in every game.
---@param c Creature 
---@return integer|nil # 
function net.hostIndex(c) end
--- This game's handle for the host's creature.
---@param hostIndex integer 
---@return Creature|nil # 
function net.creature(hostIndex) end
--- Host: the player whose shot last hurt it.
---@param c Creature 
---@return integer|nil # 
function net.lastHitBy(c) end
--- Your own sync: the creatures' state.
---@param filter? table {huntableOnly, aliveOnly, radius}
---@return table # chunks (strings) to send
function net.packCreatures(filter) end
--- Your own sync: follow the host's creatures.
---@param chunk string 
---@return integer # creatures in it, -1 = not applicable
function net.applyCreatures(chunk) end
--- Your own sync: your hunter's state.
---@return string # 
function net.packHunter() end
--- Your own sync: show a player's figure.
---@param peer integer 
---@param data string 
---@return boolean # 
function net.applyHunter(peer, data) end
--- Your own sync: a hit for the host.
---@param c Creature 
---@param damage number 
---@param kill boolean 
---@return string # 
function net.packHit(c, damage, kill) end
--- Host: apply a player's hit.
---@param peer integer 
---@param data string 
---@return boolean # 
function net.applyHit(peer, data) end
---@type integer
net.defaultPort = nil -- 27015

content = {}
--- Species of the registry.
---@param id? string|integer one species (default: all)
---@return table|nil # info, or a list of them: {id, type, name, ai, file, mod, builtin, scripted, hunt, hidden, price, unlocked, health, mass, size, radius, score, smell, hearing, sight, scaleMin, scaleRange, huntable, predator, flying, maps, spawnWeight}
function content.species(id) end
--- Weapons of the registry.
---@param id? string 
---@return table|nil # {id, type, slot, base, file, name, mod, builtin, hidden, price, ammoPrice, unlocked, power, precision, pellets, loudness, rate, ammo, magazine, aimFov, aimTime}
function content.weapons(id) end
--- Maps of the registry.
---@param id? string 
---@return table|nil # {id, terrain, name, difficulty, mod, builtin, hidden, price, unlocked, times, residents, huntable}
function content.maps(id) end
--- The map of the hunt being played.
---@return string|nil # 
function content.currentMap() end
--- The weapon the hunter has in a slot this hunt.
---@param slot integer 
---@return string|nil # 
function content.weaponInSlot(slot) end
--- The economy and hunt rules.
---@return table # {scoreMultiplier, unlicensedScore, comboBonus, flyerCredits, speciesPriceScale, weaponPriceScale, mapPriceScale, ammoScale, maxSpecies}
function content.rules() end
--- Adds or changes an entry at run time (new ones appear in the hunt menu).
---@param kind string "species", "weapon", "map" or "rules"
---@param fields table the fields of the content pack JSON
---@return string|nil # the entry's id, or nil and an error
function content.define(kind, fields) end
--- A licence price.
---@param kind string 
---@param id string 
---@return integer # -1 = unknown
function content.price(kind, id) end
--- Sets a licence price.
---@param kind string 
---@param id string 
---@param price integer 
---@return boolean # 
function content.setPrice(kind, id, price) end
--- A weapon's ammunition price.
---@param weapon string 
---@return integer # 
function content.ammoPrice(weapon) end
--- Sets it.
---@param weapon string 
---@param price integer 
---@return boolean # 
function content.setAmmoPrice(weapon, price) end
--- One of the game's balance values.
---@param key string a balance value of the game, e.g. "RESUPPLIES_COST"
---@return number # 
function content.balance(key) end
--- Sets a balance value.
---@param key string 
---@param value number 
---@return boolean # 
function content.setBalance(key, value) end
--- Whether the player owns the licence.
---@param kind string 
---@param id string 
---@return boolean # 
function content.unlocked(kind, id) end
--- Gives (or takes) a licence.
---@param kind string 
---@param id string 
---@param on? boolean default true
function content.unlock(kind, id, on) end
--- Replaces the AI of every creature of a species with your function, every frame. Move and animate the creature there (c:move, c.yaw, c.anim, c:animate(e.dt)).
---@param species string|integer 
---@param fn function|nil fn(e) with e.creature, e.dt; nil = the game's AI again
function content.drive(species, fn) end
--- Reads every enabled mod's content packs again.
function content.reload() end
--- A report of the registry.
---@return string # one line per entry and the mods that set it
function content.report() end
--- The species whose AI a new species can use.
---@return table # species ids
function content.aiNames() end

json = {}
--- Lua value to JSON text.
---@param value any 
---@param pretty? boolean indented
---@return string # 
function json.encode(value, pretty) end
--- JSON text to a Lua value.
---@param text string JSON (comments and trailing commas allowed)
---@return any # the value, nil on error
---@return string? # error
function json.decode(text) end

--- v limited to lo..hi.
---@param v number 
---@param lo number 
---@param hi number 
---@return number # 
function math.clamp(v, lo, hi) end
--- Linear blend from a to b.
---@param a number 
---@param b number 
---@param t number 0-1
---@return number # 
function math.lerp(a, b, t) end
--- Rounds to the nearest step.
---@param v number 
---@param step? number default 1
---@return number # 
function math.round(v, step) end
--- The sign.
---@param v number 
---@return integer # -1, 0 or 1
function math.sign(v) end
--- Distance on the ground.
---@param x1 number 
---@param z1 number 
---@param x2 number 
---@param z2 number 
---@return number # 
function math.dist(x1, z1, x2, z2) end
--- Distance in 3D.
---@param x1 number 
---@param y1 number 
---@param z1 number 
---@param x2 number 
---@param y2 number 
---@param z2 number 
---@return number # 
function math.dist3(x1, y1, z1, x2, y2, z2) end
--- The yaw that looks from point 1 to point 2.
---@param x1 number 
---@param z1 number 
---@param x2 number 
---@param z2 number 
---@return number # degrees
function math.yaw(x1, z1, x2, z2) end
--- The direction of a yaw.
---@param yaw number degrees
---@return number # dx
---@return number # dz
function math.forward(yaw) end
--- The shortest turn from yaw a to yaw b.
---@param a number 
---@param b number 
---@return number # -180..180
function math.angleDiff(a, b) end
--- Splits a string.
---@param s string 
---@param sep? string default ","
---@param plain? boolean false = sep is a Lua pattern
---@return table # the parts
function string.split(s, sep, plain) end
--- Without spaces at both ends.
---@param s string 
---@return string # 
function string.trim(s) end
--- 
---@param s string 
---@param prefix string 
---@return boolean # 
function string.startsWith(s, prefix) end
--- 
---@param s string 
---@param suffix string 
---@return boolean # 
function string.endsWith(s, suffix) end
--- A shallow copy.
---@param t table 
---@return table # 
function table.copy(t) end
--- A full copy (nested tables too).
---@param t table 
---@return table # 
function table.deepcopy(t) end
--- The keys as a list.
---@param t table 
---@return table # 
function table.keys(t) end
--- The values as a list.
---@param t table 
---@return table # 
function table.values(t) end
--- Number of entries (any keys).
---@param t table 
---@return integer # 
function table.count(t) end
--- 
---@param t table 
---@param value any 
---@return any # its key, nil when absent
function table.find(t, value) end
--- 
---@param t table 
---@param value any 
---@return boolean # 
function table.contains(t, value) end
--- 
---@param t table a list
---@param fn function fn(value, index) -> new value
---@return table # 
function table.map(t, fn) end
--- 
---@param t table a list
---@param fn function fn(value, index) -> keep?
---@return table # 
function table.filter(t, fn) end
--- 
---@param t table a list
---@return table # the same list, shuffled
function table.shuffle(t) end

