// Earth Games: types for a game's rules script (server.js) and its manifest (game.json). // API version 1. Generated from the platform's API table; do not edit by hand. /** A place on Earth. */ export interface Point { lat: number; lon: number } /** * A player, as your script sees them. A snapshot: it does not change after you receive it. * `id` is the same every time this person plays your game, different in every other game, * and tells you nothing else about them. */ export interface Player extends Point { readonly id: string; readonly name: string; readonly mode: 'walk' | 'drive' | 'fly' | string; /** Metres per second. */ readonly speed: number; /** True when they are not signed in. */ readonly guest: boolean; /** Once the game uses combat or inventories. */ readonly hp?: number; readonly armor?: number; readonly dead?: boolean; /** What they hold: 'fists' | 'bat' | 'pistol' | 'smg' | 'shotgun'. */ readonly weapon?: string; /** The id of their team, once the game put them on one (teams.assign, teams.auto). */ readonly team?: string; /** What they are driving: its id, its racing class (D, C, B, A, S, or M for bikes) and its top speed in m/s. */ readonly car?: { id: string; cls: string; top: number }; /** How many other players are riding in their vehicle. */ readonly riders?: number; /** The id of the player whose vehicle they are riding in. */ readonly ridingWith?: string; /** True while the player is marked busy or in a race. */ readonly busy?: boolean; readonly isPlayer: true; } export type WeatherPreset = 'clear' | 'cloudy' | 'overcast' | 'rain' | 'storm' | 'snow' | 'fog'; export type HandlingProfile = 'arcade' | 'sport' | 'real'; export type TireCompound = 'slick' | 'allweather' | 'gravel'; /** An entity placed by your script on the map. */ export interface Entity { readonly id: string; readonly kind: 'zone' | 'marker'; readonly at: Point; readonly radius: number; readonly style: string; readonly label: string; readonly radar: boolean; readonly visibleTo?: string | null; } /** A team and its live score and members. */ export interface Team { readonly id: string; readonly name: string; readonly color: string; readonly score: number; readonly players: string[]; } /** Options for npcs.spawn / npcs.spawnMany. */ export interface SpawnOpts { lat: number; lon: number; heading?: number; brain?: Brain; target?: Player | string | Point; route?: Point[]; tag?: string; } /** A button in a card, HUD, or window. */ export interface Button { id: string; label: string; action?: 'signin' | 'waypoint' | 'close' | 'report'; style?: 'primary' | 'secondary' | 'danger' | 'ghost'; disabled?: boolean } export type WindowButton = Button; /** One content block inside a rich window (ui.window). */ export type WindowBlock = | { type: 'heading'; text: string } | { type: 'text'; text: string; muted?: boolean } | { type: 'divider' } | { type: 'stats'; items: { label: string; value: string | number; tone?: 'info' | 'good' | 'warn' | 'bad' }[] } | { type: 'bar'; value: number; max: number; text?: string; tone?: 'info' | 'good' | 'warn' | 'bad' } | { type: 'list'; items: { id?: string; title: string; detail?: string; button?: string; disabled?: boolean; to?: Point }[] } | { type: 'table'; columns: string[]; rows: (string | number)[][] } | { type: 'callout'; title?: string; text: string; tone?: 'info' | 'good' | 'warn' | 'bad' } | { type: 'badges'; items: { text: string; tone?: 'info' | 'good' | 'warn' | 'bad' }[] } | { type: 'actions'; buttons: WindowButton[] }; /** A rich structured window opened by eg.ui.window. */ export interface WindowDef { id: string; title: string; subtitle?: string; position?: 'center' | 'left' | 'right'; width?: 'sm' | 'md' | 'lg'; closable?: boolean; backdrop?: boolean; tabs?: { id: string; label: string }[]; tab?: string; blocks?: WindowBlock[]; buttons?: WindowButton[]; note?: string; } /** Options for eg.ui.confirm. */ export interface ConfirmOpts { title: string; body?: string; ok?: string; cancel?: string; danger?: boolean; timeoutS?: number } /** Options for eg.ui.prompt. */ export interface PromptOpts { title: string; body?: string; label?: string; placeholder?: string; value?: string; maxLength?: number; ok?: string; cancel?: string; timeoutS?: number } /** One selectable option inside eg.ui.choose. */ export interface ChooseOption { id: string; label: string; detail?: string; disabled?: boolean } /** Options for eg.ui.choose. */ export interface ChooseOpts { title: string; body?: string; options: ChooseOption[]; cancel?: string; timeoutS?: number } /** One field inside eg.ui.form. */ export type FormField = | { name: string; label: string; type?: 'text'; placeholder?: string; value?: string; maxLength?: number; required?: boolean } | { name: string; label: string; type: 'number' | 'slider'; min?: number; max?: number; step?: number; value?: number } | { name: string; label: string; type: 'select'; options: { value: string; label: string }[]; value?: string } | { name: string; label: string; type: 'checkbox'; value?: boolean }; /** Options for eg.ui.form. */ export interface FormOpts { title: string; body?: string; fields: FormField[]; ok?: string; cancel?: string; timeoutS?: number } /** Options for eg.ui.banner. */ export interface BannerDef { title: string; subtitle?: string; tone?: 'info' | 'good' | 'warn' | 'bad'; seconds?: number } /** Options for eg.ui.countdown. */ export interface CountdownOpts { seconds: number; label?: string; goText?: string; sound?: boolean } /** A race track (race.tracksNear, race.course). Times are in milliseconds. */ export interface Track { readonly id: string; readonly name: string; readonly kind: 'sprint' | 'circuit'; readonly laps: number; readonly lengthM: number; readonly start: Point; /** A good time for a typical car of each class: D, C, B, A, S, and M for bikes. */ readonly par: { [cls: string]: number }; /** This week's featured track of its area. */ readonly featured?: boolean; /** Recorded by a player. */ readonly user?: boolean; /** Made by this game with race.course. */ readonly course?: boolean; } /** A real named place from the map. */ export interface Place extends Point { id: string; name: string; kind: 'depot' | 'fuel' | 'shop' | 'office' | string } /** A kind of character your game uses. */ export interface Kind { id: string; name?: string; /** A character from the library; left out, each one gets a different everyday person. */ model?: string; scale?: number; /** Walking and running speed, metres per second. */ speed?: number; runSpeed?: number; health?: number; /** How far it notices players, and how far it follows before giving up (metres). */ sight?: number; leash?: number; brain?: Brain; aggro?: boolean; attack?: { range: number; damage: number; cooldownS?: number; windupS?: number; ranged?: boolean }; corpseS?: number; } export type Brain = 'idle' | 'wander' | 'chase' | 'flee' | 'guard' | 'patrol' | 'goto'; /** One of your characters, as npcs.info returns it. */ export interface Npc extends Point { id: number; kind: string; heading: number; hp: number; alive: boolean; brain: Brain; target: string | null; spawner: string | null; tag: string | null } /** What a player carries: a gun's number is its rounds, a melee weapon's is 1, anything else is your own item. */ export type Loadout = { [item: string]: number }; /** * A piece of a HUD card. Text may hold tokens shown in the player's own units: * {dist:1234} (metres), {km:2.5} (a trip length), {time:95} (1:35). */ export type HudPart = | { type: 'title'; text: string } | { type: 'text'; text: string } | { type: 'badge'; text: string; tone?: 'info' | 'good' | 'warn' | 'bad' } | { type: 'distance'; to: Point; text?: string } | { type: 'bearing'; to: Point; text?: string } | { type: 'timer'; since?: number; until?: number; par?: number; text?: string } | { type: 'bar'; value: number; max: number; text?: string } | { type: 'counter'; text: string; value: number | string } | { type: 'list'; items: { label: string; value?: string | number; highlight?: boolean }[] } | { type: 'divider' } | ({ type: 'button' } & Button) | { type: 'teams' }; type point = Point; /** Wherever a player is wanted, pass the player object or its id. */ type player = Player | string; export interface Eg { /** Time, distance, bearings, real places, and instance weather/solar-hour atmosphere. Everything works wherever on Earth the game is played. */ readonly world: { /** The time now, in milliseconds since 1970 (the server clock). */ now(): number; /** Metres between two points. */ distance(a: point, b: point): number; /** The point that many metres east and south of another: place things relative to wherever the game is being played. */ offset(from: point, eastM: number, southM: number): point; /** Local solar hour (0 to 24) at a point, for "only at night" rules anywhere on Earth. */ hour(at: point): number; /** Real named places from the built map between minM and maxM metres of a point: [{ id, name, kind (depot | fuel | shop | office), lat, lon }], each on the road in front of it. The same seed gives the same sample. Three more kinds come only when you ask for them in `kinds`: "hospital", "police" (a police station) and "street" (a point on a named street). */ placesNear(at: point, opts?: { minM?: number, maxM?: number, kinds?: string[], max?: number, seed?: string }): Promise; /** Is this point on a road? null where the map is not built. */ onRoad(at: point): Promise; /** Compass bearing in degrees from one point toward another (0 north, 90 east, 180 south, 270 west). */ bearing(from: point, to: point): number; /** The point `meters` away from `from` along a compass bearing in degrees. */ pointAlong(from: point, bearingDeg: number, meters: number): point; /** The point halfway between two points. */ midpoint(a: point, b: point): point; /** True when `at` is within `radiusM` metres of `center`. */ inRadius(at: point, center: point, radiusM: number): boolean; /** A random point evenly distributed inside a circle or ring (`minM` to `maxM` metres, default 0 to 100) around `center`. */ randomPoint(center: point, opts?: { minM?: number, maxM?: number }): point; /** Override the weather ("clear", "cloudy", "overcast", "rain", "storm", "snow", "fog") for everyone in the instance (null restores live local weather). Private games only (not games layered on the shared world). */ setWeather(weather: WeatherPreset | null): void; /** Pin the local solar hour (0 to 24, for instance 22 for night or 6.5 for sunrise) for everyone in the instance (null restores real local time). Private games only (not games layered on the shared world). */ setTime(hour: number | null): void; /** Flash the sky and play thunder for players near a point, or everyone in the instance when omitted. Private games only (not games layered on the shared world). */ lightning(at?: point | null): void; }; /** Who is in the game: queries, teams, ephemeral match data, movement freezes, and teleports. Player objects are snapshots; call players.get for a fresh one. */ readonly players: { /** Everyone in the game now. */ all(): Player[]; /** The latest snapshot of one player, or null when they are not in the game. */ get(player: player): Player | null; /** Players within a radius of a point, nearest first. */ near(at: point, radiusM: number): Player[]; /** The closest player to a point matching optional filters (`exclude`, `team`, `alive`, `maxM`), or null when none match. */ nearest(at: point, opts?: { exclude?: player | player[], team?: string, alive?: boolean, maxM?: number }): Player | null; /** Everyone currently assigned to a team. */ inTeam(team: string): Player[]; /** One randomly chosen player matching optional filters, or null when none match. */ random(opts?: { team?: string, alive?: boolean, exclude?: player | player[] }): Player | null; /** How many players are in the game. */ count(): number; /** True when the player is marked busy with `players.setBusy` or in a race. */ isBusy(player: player): boolean; /** Keep an ephemeral value on a player for this run (up to 50 keys per player; cleared when they leave). */ setData(player: player, key: string, value: any): void; /** Read one ephemeral value set with `players.setData` (or all keys as an object when `key` is left out). */ getData(player: player, key?: string): any; /** Did this player skip the trip since a moment (teleported, was snapped back by the server, or flew)? null when the trip was honest. For games that reward getting somewhere. */ skipped(player: player, sinceMs: number): 'teleport' | 'correct' | 'fly' | null; /** Mark a player as in the middle of a run (a job, a round). The platform will not move a busy player to another game without telling you first. */ setBusy(player: player, busy: boolean): void; /** Ask the platform whether this player may start a scored run now. False when a free player has used up their runs for the day; the platform has already told them. Call it before starting anything that ends with finishRun. */ startRun(player: player): Promise; /** A run that began with startRun was completed. Counts as having played the game. */ finishRun(player: player): void; /** Give a signed-in player a profile badge. Resolves true when it is new to them. Earth Games team only. */ award(player: player, badge: { id: string, label: string }): Promise; /** Move a player to a point at once: the start of a round, a respawn point. Private games only (not games layered on the shared world). */ teleport(player: player, to: point): void; /** Move everyone in the instance to a point, optionally spaced evenly around a ring of `spreadM` metres (0 to 100). Private games only (not games layered on the shared world). */ teleportAll(to: point, opts?: { spreadM?: number }): void; /** Freeze or unfreeze a player (null: everyone). Frozen players cannot walk or drive, while still able to look around and answer prompts or windows. Private games only (not games layered on the shared world). */ setFrozen(player: player | null, frozen: boolean): void; /** Put a player out of the vehicle they are driving onto foot beside it. Private games only (not games layered on the shared world). */ eject(player: player): void; /** Send a player out of this private instance back to the shared world with an optional message. Private games only (not games layered on the shared world). */ kick(player: player, reason?: string): void; /** Add to a player's cash in this game (a negative number takes some, down to nothing). Resolves to what they have now. Earth Games team only. */ pay(player: player, cash: number): Promise; /** Players within a radius who are wanted by the police in another Earth Games game right now, nearest first, with where they are. An id lasts while that player stays online. Earth Games team only. */ wanted(at: point, radiusM: number): Promise<{ id: string, name: string, level: number, lat: number, lon: number }[]>; /** Put a car from the roster in a signed-in player's garage for good (a prize). Resolves true when it is new to them. Earth Games team only. */ grantCar(player: player, car: string): Promise; }; /** Sides in a game, with scores, shuffling, leader lookups, and team broadcasts. */ readonly teams: { /** Say which teams the game has (up to 8). Scores of teams that stay are kept; a player on a team that is gone has none. */ define(teams: { id: string, name?: string, color?: 'red' | 'blue' | 'green' | 'yellow' | 'purple' | 'orange' }[]): void; /** Put a player on a team (null: on none). Their snapshot has `team` from the next event on. Teammates cannot hurt each other unless combat is enabled with friendlyFire. */ assign(player: player, team: string | null): void; /** Put every player who has no team on the team with the fewest players. */ auto(): void; /** Add to a team's score (a negative number takes away). */ addScore(team: string, points: number): void; /** Set a team's score. */ setScore(team: string, points: number): void; /** The teams now, with their scores and the ids of the players on each. */ all(): Promise; /** One team by id, with its color, score and player ids, or null. */ get(team: string): Promise; /** The highest-scoring team right now (`tied` is true when two or more teams share the lead), or null when no teams are defined. */ leader(): Promise<(Team & { tied: boolean }) | null>; /** Set every defined team's score back to 0. */ resetScores(): void; /** Randomly rebalance every player currently in the game evenly across the defined teams. */ shuffle(): void; /** Show a toast message only to players on one team. */ broadcast(team: string, text: string, tone?: 'info' | 'good' | 'warn'): void; }; /** What players drive: emergency sirens, handling profiles, tire compounds, speed caps, and nitro boosts. */ readonly vehicles: { /** Switch the emergency siren of the vehicle a player is driving on or off: traffic makes way for them, and players near them hear it. */ siren(player: player, on: boolean): void; /** Set ground-vehicle handling for everyone in the instance: "arcade" (forgiving grip), "sport" (eager and lively), or "real" (factory road specs). Private games only (not games layered on the shared world). */ setHandling(profile: HandlingProfile): void; /** Fit a tire compound ("slick", "allweather", "gravel", or null for default) on a player's vehicle or everyone's. Private games only (not games layered on the shared world). */ setTire(player: player | null, tire: TireCompound | null): void; /** Cap ground-vehicle speed in metres per second (for pit lanes or speed traps); null removes the cap. Private games only (not games layered on the shared world). */ setSpeedLimit(player: player | null, maxMps: number | null): void; /** Give a player's ground vehicle a temporary speed and acceleration surge (`strength` 0.2 to 2, `seconds` 0.3 to 8). Private games only (not games layered on the shared world). */ boost(player: player, opts?: { strength?: number, seconds?: number }): void; }; /** What a player's camera and viewport do: shakes, field-of-view kicks, and smooth screen fades. */ readonly camera: { /** Shake a player's camera for a moment (null: everyone): a blast, a landing, something heavy going past. Not shown to players who asked their device for less motion. */ shake(player: player | null, opts?: { strength?: number, seconds?: number }): void; /** Widen or narrow a player's field of view by `kick` degrees (-15 to 15) for `seconds` (0.1 to 30); null resets to normal. */ fov(player: player | null, opts: { kick?: number, seconds?: number } | null): void; /** Fade a player's screen smoothly toward black or white (`opacity` 0 to 1, `seconds` 0.1 to 5); pass opacity 0 or null to fade back in. */ fade(player: player | null, opts: { color?: "black" | "white", opacity?: number, seconds?: number } | null): void; }; /** Timed races through gates, on the tracks the platform makes from real streets or on a course of your own. The platform draws the gates and lights and keeps the time. */ readonly race: { /** Race tracks on real streets near a point, nearest first: [{ id, name, kind ("sprint" | "circuit"), laps, lengthM, start, par: { D, C, B, A, S, M } (a good time in ms for each class of car), featured?, user? }]. The platform makes them from the map, and players record their own. */ tracksNear(at: point, opts?: { maxM?: number, max?: number }): Promise; /** A course of your own through the points you give, in order (100 m to 20 km): the platform puts the gates on it. End within 30 m of the start for a circuit. It lasts as long as the game runs (up to 20 at a time). null when it cannot be made; your log says why. */ course(points: point[], opts?: { name?: string, laps?: number }): Promise; /** Put a player on a track (by its id): a ring appears on its start line. When they stop in it in a car or on a bike, the start lights count down and the platform times them through every gate; players of your game who line up together start together. You hear the rest in onRace. The player counts as busy until the race ends. */ offer(player: player, track: string, opts?: { mode?: string }): Promise<{ ok: boolean, why?: 'racing' | 'unknown' | 'far' }>; /** Take a player out of the race they are lining up for or driving. You hear onRace with ev "void", reason "cancelled". */ cancel(player: player): void; /** The race a player is currently in (`stage`, `next` gate and `total` gates), or null when they are not racing. */ status(player: player): Promise<{ track: string, stage: 'grid' | 'count' | 'race', next: number, total: number } | null>; }; /** Zones and markers on the map: places players go to, stand in, inspect, or press F at. */ readonly entities: { /** Put a zone (a ring players enter) or a marker (a beacon) on the map and return its id. `visibleTo` makes it one player's own. A `trigger` makes it fire onZone; `interact` gives it an F prompt that fires onInteract. */ add(def: { id?: string, kind: 'zone' | 'marker', at: point, radius?: number, style?: string, label?: string, radar?: boolean, visibleTo?: player, trigger?: { dwellS?: number, maxSpeed?: number, modes?: string[] }, interact?: { verb: string, reach?: number, modes?: string[] } }): string; /** Change an entity (same fields as add). */ update(id: string, patch: object): void; /** Take an entity off the map. */ remove(id: string): void; /** Read one entity your script placed by id, or null when it is not on the map. */ get(id: string): Promise; /** List the entities your script currently has on the map, optionally filtered by `kind`, id `prefix` or `visibleTo`. */ list(opts?: { kind?: 'zone' | 'marker', prefix?: string, visibleTo?: player }): Promise; /** Your script's entities within `radiusM` metres of a point, nearest first. */ near(at: point, radiusM: number, opts?: { kind?: 'zone' | 'marker', prefix?: string }): Promise; /** How many entities your script currently has on the map. */ count(opts?: { kind?: 'zone' | 'marker', prefix?: string }): Promise; /** Remove every entity your script placed, or only those matching an id `prefix` or `visibleTo`. */ clear(opts?: { prefix?: string, visibleTo?: player }): void; }; /** Characters the game puts in the world. The platform moves them; you choose their kind, batch spawns, and what they are doing. */ readonly npcs: { /** Define the kinds of characters this game uses: [{ id, name?, model?, scale?, speed?, runSpeed?, health?, sight?, leash?, brain?, aggro?, attack?: { range, damage, cooldownS, windupS, ranged? } }]. Private games only (not games layered on the shared world). */ kinds(kinds: Kind[]): void; /** Spawn one character. Resolves to its id, or null when the kind is unknown or the world is full. Private games only (not games layered on the shared world). */ spawn(kind: string, opts: SpawnOpts): Promise; /** Spawn up to 50 characters of one kind in a single call, returning their ids (or null for any that did not fit). Private games only (not games layered on the shared world). */ spawnMany(kind: string, list: SpawnOpts[]): Promise<(number | null)[]>; /** Take a character out of the world at once. Private games only (not games layered on the shared world). */ despawn(id: number): void; /** Take every character with a matching `tag` out of the world at once. Resolves to how many were removed. Private games only (not games layered on the shared world). */ despawnTag(tag: string): Promise; /** Remove every character. Private games only (not games layered on the shared world). */ clear(): void; /** Change what a character is doing. Private games only (not games layered on the shared world). */ setBrain(id: number, brain: 'idle' | 'wander' | 'chase' | 'flee' | 'guard' | 'patrol' | 'goto', opts?: { target?: player | point, route?: point[], home?: point, run?: boolean }): void; /** Change what every living character matching `kind`, `tag` or `spawner` is doing. Resolves to how many were updated. Private games only (not games layered on the shared world). */ setBrainAll(filter: { kind?: string, tag?: string, spawner?: string }, brain: Brain, opts?: { target?: player | point, route?: point[], home?: point, run?: boolean }): Promise; /** Hurt a character. Private games only (not games layered on the shared world). */ damage(id: number, amount: number, by?: player): Promise<{ hp: number, died: boolean } | null>; /** Heal a character. Private games only (not games layered on the shared world). */ heal(id: number, amount: number): void; /** One character: { id, kind, lat, lon, heading, hp, alive, brain, target, spawner, tag }. Private games only (not games layered on the shared world). */ info(id: number): Promise; /** Ids of living characters within a radius, nearest first. Private games only (not games layered on the shared world). */ near(at: point, radiusM: number, opts?: { kind?: string, tag?: string, max?: number }): Promise; /** How many characters are alive. Private games only (not games layered on the shared world). */ count(opts?: { kind?: string, spawner?: string }): Promise; }; /** Rules that keep characters around the players, or around a spot, without you placing each one. */ readonly spawners: { /** Add or replace a spawner. With `at` it keeps `count` characters alive around that spot. Without, it keeps characters around the players wherever they go, appearing on ground that matches `where`, never closer than minFromPlayersM. Private games only (not games layered on the shared world). */ add(def: { id: string, kind: string, at?: point, radius?: number, count?: number, capNear?: number, capTotal?: number, perSecond?: number, respawnS?: number, hours?: [number, number], brain?: string, tag?: string, where?: { roadClass?: string[], minFromPlayersM?: number, maxFromPlayersM?: number } }): void; /** Remove a spawner; `clear` also removes the characters it made. Private games only (not games layered on the shared world). */ remove(id: string, opts?: { clear?: boolean }): void; /** Switch a spawner on or off. Private games only (not games layered on the shared world). */ enable(id: string, on: boolean): void; /** Scale a spawner (0 none, 1 as written, up to 4). Private games only (not games layered on the shared world). */ setDensity(id: string, k: number): void; /** Spawn up to n right now, ignoring the rate. Private games only (not games layered on the shared world). */ burst(id: string, n: number): void; /** Remove the characters a spawner made. Private games only (not games layered on the shared world). */ clear(id: string): void; /** All active spawners with whether each is enabled and how many characters from it are alive. Private games only (not games layered on the shared world). */ list(): Promise<{ id: string, kind: string, enabled: boolean, alive: number }[]>; }; /** Health, armor, shields, damage, death and respawning. Switch it on and players can fight your characters (and each other, if you allow it). */ readonly combat: { /** Switch combat on. Every player gets health (100 unless you say), a health and weapon bar, and the starting loadout; their shots and swings hurt your characters; your characters' attacks hurt them (npcDamage: false to decide that yourself in onNpc). A player at 0 health is down for respawnS seconds (5; 0 means until you call combat.respawn), then back with full health and safeS seconds (3) of protection. Players only hurt each other with pvp: true. Private games only (not games layered on the shared world). */ enable(opts?: { health?: number, respawnS?: number, pvp?: boolean, npcDamage?: boolean, safeS?: number, friendlyFire?: boolean, loadout?: Loadout }): void; /** Switch combat off: weapons are put away and nobody can be hurt by shots. Health and inventories are kept. Private games only (not games layered on the shared world). */ disable(): void; /** Let players hurt each other, or stop them. Private games only (not games layered on the shared world). */ setPvp(on: boolean): void; /** Set a player's health (and, optionally, their maximum). 0 kills them. Private games only (not games layered on the shared world). */ setHealth(player: player, hp: number, max?: number): void; /** Set a player's armor, 0 to 100. Armor soaks 60 % of each hit until it is used up. Private games only (not games layered on the shared world). */ setArmor(player: player, armor: number): void; /** Give a player `seconds` (0 to 60) of spawn protection during which attacks do not hurt them. Private games only (not games layered on the shared world). */ setSafe(player: player, seconds: number): void; /** Hurt a player (a trap, a fall, a rule of your own). null when it did nothing: they are down already, or just respawned. Private games only (not games layered on the shared world). */ damage(player: player, amount: number, opts?: { by?: player, why?: string }): Promise<{ hp: number, died: boolean } | null>; /** Give health back, up to their maximum. Call it from a timer for health that comes back by itself. Private games only (not games layered on the shared world). */ heal(player: player, amount: number): void; /** Heal every living player in the game (by `amount`, or back to full health when left out). Private games only (not games layered on the shared world). */ healAll(amount?: number): void; /** Put a player down at once. Private games only (not games layered on the shared world). */ kill(player: player, why?: string): void; /** Put a downed player back on their feet now, with full health. Private games only (not games layered on the shared world). */ respawn(player: player): void; /** Put every downed player in the game back on their feet now with full health. Private games only (not games layered on the shared world). */ reviveAll(): void; }; /** What each player carries: weapons, rounds, and any items of your own. */ readonly inventory: { /** Give a player a weapon ("bat", "pistol", "smg", "shotgun"; a gun's count is its rounds) or any item of your own ("key", "medkit": lowercase ids the platform just counts for you). Private games only (not games layered on the shared world). */ give(player: player, item: string, count?: number): void; /** Take some of an item away, or all of it when count is left out. Private games only (not games layered on the shared world). */ take(player: player, item: string, count?: number): void; /** Replace everything a player carries: { pistol: 48, bat: 1, medkit: 2 }. Everyone always has fists. Private games only (not games layered on the shared world). */ setLoadout(player: player, loadout: Loadout): void; /** Put a weapon they carry in their hands. Private games only (not games layered on the shared world). */ equip(player: player, weapon: string): void; /** What a player carries now. Private games only (not games layered on the shared world). */ get(player: player): Promise<{ [item: string]: number }>; /** True when the player carries at least `count` (1 by default) of an item or weapon. Private games only (not games layered on the shared world). */ has(player: player, item: string, count?: number): Promise; /** Remove everything from a player's inventory, leaving only fists. Private games only (not games layered on the shared world). */ clear(player: player): void; }; /** Effects in the world (sparks, smoke, fire, confetti, rings, explosions, screen flashes), seen by everyone near. */ readonly fx: { /** A splash of blood. Shown only when your manifest says the game has blood ("content": { "blood": true }), and only to signed-in players who turned blood on in their settings. Hits in combat do this for you. Private games only (not games layered on the shared world). */ blood(at: point | player, opts?: { size?: number }): void; /** A puff of dust, as when something hits the ground or a wall. Private games only (not games layered on the shared world). */ impact(at: point | player, opts?: { size?: number }): void; /** A burst of sparks. Private games only (not games layered on the shared world). */ sparks(at: point | player, opts?: { size?: number }): void; /** Smoke rising from a point for a few seconds. Private games only (not games layered on the shared world). */ smoke(at: point | player, opts?: { size?: number, seconds?: number }): void; /** Flickering flames rising at a point for `seconds` (2 by default, up to 12). Private games only (not games layered on the shared world). */ fire(at: point | player, opts?: { size?: number, seconds?: number }): void; /** A celebratory burst of colorful confetti around a point or player. Private games only (not games layered on the shared world). */ confetti(at: point | player, opts?: { size?: number }): void; /** An expanding shockwave or pulse ring on the ground. Private games only (not games layered on the shared world). */ ring(at: point | player, opts?: { color?: string, radius?: number, seconds?: number }): void; /** A blast everyone near sees and hears. With `damage` it hurts players and characters within `radius` metres (8), less the farther they are; `by` is the player credited. Private games only (not games layered on the shared world). */ explosion(at: point | player, opts?: { size?: number, damage?: number, radius?: number, by?: player }): void; /** Flash the edges of a player's screen (null: everyone). Private games only (not games layered on the shared world). */ flash(player: player | null, opts?: { color?: "red" | "white" | "green", seconds?: number }): void; }; /** What a player sees: toasts, HUD cards, result cards, menus, rich multi-block windows, awaitable modal prompts & forms, banners, countdowns, hints, and GPS waypoints. */ readonly ui: { /** A short message. null sends it to everyone in the game. */ toast(player: player | null, text: string, tone?: 'info' | 'good' | 'warn'): void; /** Set a player's HUD card for this game (null clears it). See HUD_PARTS for the pieces. */ hud(player: player | null, parts: HudPart[] | null): void; /** A result card (shown in place of the HUD until closed or `seconds` pass). */ card(player: player, card: { title: string, lines?: string[], buttons?: Button[], seconds?: number } | null): void; /** Open (or replace, or with null close) a panel with a list of choices. A choice fires onUi with { from: "menu", id, item }; a tab fires { from: "menu", id, tab }. */ menu(player: player, menu: { id: string, title: string, tabs?: { id: string, label: string }[], tab?: string, text?: string, items?: { id: string, title: string, detail?: string, button?: string, disabled?: boolean }[], rows?: string[], note?: string } | null): void; /** Open or update a structured window (up to 3 per player; null closes all). Supports centered modals or docked left/right panels with tabs, stats, bars, tables, callouts, badges, lists and buttons. Interactions fire onUi with from "window". */ window(player: player | null, win: WindowDef | null): void; /** Close one open window by id, or all open windows when `id` is omitted. */ closeWindow(player: player | null, id?: string): void; /** Open a Yes/No modal dialog for one player and await their answer (`true` when confirmed, `false` when cancelled, closed or timed out). */ confirm(player: player, opts: ConfirmOpts): Promise; /** Open a text-input modal dialog for one player and await what they type (up to 240 characters), or `null` when cancelled. */ prompt(player: player, opts: PromptOpts): Promise; /** Open a choice/dialogue picker modal for one player and await the chosen option's `id`, or `null` when cancelled. */ choose(player: player, opts: ChooseOpts): Promise; /** Open a multi-field modal form (`text`, `number`, `select`, `checkbox`, `slider`, up to 8 fields) and await `{ [name]: value }`, or `null` when cancelled. */ form(player: player, opts: FormOpts): Promise<{ [key: string]: string | number | boolean } | null>; /** Show a bold announcement banner across the upper center of the screen (null clears it). */ banner(player: player | null, banner: BannerDef | null): void; /** Show a subtle control or action hint pill near the bottom HUD (null clears it). */ hint(player: player | null, text: string | null): void; /** Show a big 3, 2, 1, GO! countdown overlay in the center of the screen (null cancels it). */ countdown(player: player | null, opts: CountdownOpts | null): void; /** Clear every game HUD, card, menu, window, banner, countdown and GPS waypoint for a player (null: everyone). */ clear(player: player | null): void; /** Guide a player to a point with the GPS (null lets go of it). `hint` is shown once when they arrive within hintM metres. */ waypoint(player: player, at: point | null, opts?: { hint?: string, hintM?: number }): void; }; /** Post game announcements, private clues, and team callouts straight into players' in-game chat feeds. */ readonly chat: { /** Post a game line into the chat window for everyone currently in this game. */ announce(text: string, opts?: { tone?: 'info' | 'good' | 'warn', label?: string }): void; /** Post a private game line into one player's chat window. */ tell(player: player, text: string, opts?: { tone?: 'info' | 'good' | 'warn', label?: string }): void; /** Post a game line into the chat window of every player on one team. */ team(team: string, text: string, opts?: { tone?: 'info' | 'good' | 'warn', label?: string }): void; }; /** Library sound effects for players or locations, plus gamepad haptic rumble. */ readonly audio: { /** Play a short sound from the library by id (for instance "ui.job_accept"). */ cue(player: player | null, id: string): void; /** Play a library sound for every player within `radius` metres of a point (150 by default, up to 1000). */ cueNear(at: point, id: string, opts?: { radius?: number }): void; /** Vibrate a player's gamepad controller (`strength` 0.1 to 1, `seconds` 0.05 to 2; ignored when using keyboard). */ rumble(player: player | null, opts?: { strength?: number, seconds?: number }): void; }; /** Weekly and all-time leaderboards, personal bests, and player rank lookups for your game. */ readonly scores: { /** Add points to a signed-in player on this game's weekly and all-time boards. Resolves to their totals, or null for a guest. `board` names a board of your own to add to instead (a count of wins, say); it is not shown on the game's leaderboard. */ add(player: player, points: number, opts?: { meters?: number, board?: string }): Promise<{ week: number, all: number, runs: number } | null>; /** Keep a signed-in player's best (lowest) time in milliseconds on a board you name, such as one per track. Resolves to their best now, what it was before, whether this run improved it, and their place on that board; null for a guest. */ setBest(player: player, board: string, ms: number, opts?: { meters?: number }): Promise<{ best: number, before: number | null, improved: boolean, rank: number | null } | null>; /** A player's best time on one of your time boards, or null. */ bestOf(player: player, board: string): Promise; /** The best time anyone has set on one of your time boards, or null. */ record(board: string): Promise; /** The top of a board. */ top(period: 'week' | 'all', limit?: number): Promise<{ rank: number, name: string, score: number, runs: number, meters: number }[]>; /** A signed-in player's rank and total score on this game's weekly/all-time board or a custom board, or null. */ rankOf(player: player, opts?: { period?: 'week' | 'all', board?: string }): Promise<{ rank: number, score: number, runs: number } | null>; }; /** What your game keeps between sessions: a saved world's data in persistent games, and a little data per player in any game. */ readonly saves: { /** Keep a value with this saved world (persistent games: "instance": { "kind": "persistent" }). It is still there when players come back after everyone left, or after the server restarted: you get everything back in onLoad. Up to 200 keys and 256 KB per world. Private games only (not games layered on the shared world). */ set(key: string, value: any): void; /** One saved value of this world (null when there is none), or without a key everything saved, as { key: value }. Private games only (not games layered on the shared world). */ get(key?: string): Promise; /** Forget one saved value of this world. Private games only (not games layered on the shared world). */ remove(key: string): void; /** Keep a value for this player in your game, in any kind of game: an unlock, a best time, where they left off. It follows them into every match and world of this game. Up to 50 keys and 16 KB per player. */ setPlayer(player: player, key: string, value: any): void; /** One value kept for this player (null when there is none), or without a key everything kept for them. */ getPlayer(player: player, key?: string): Promise; /** Forget one value kept for this player. */ removePlayer(player: player, key: string): void; }; /** A report of a round that its signed-in players and their organization can open later: each route on a map, with your numbers. The Response drill saves one after every drill. */ readonly reports: { /** Save a report of the round that its signed-in players (and the admins of their organization) can open later: a map of each player's route (`path`: [lat, lon, seconds] points, up to 1500), their numbers, and your lines. `player` is a player's id. Show it with a card button whose action is "report" and whose id is the report id. Null when nobody signed in played. One report every 30 seconds per game. */ save(report: { title: string, lines?: string[], points?: { label: string, at: point }[], players: { player: string, path?: [number, number, number][], stats?: { label: string, value: string }[] }[] }): Promise<{ id: string, url: string } | null>; }; /** Inspect and control the running game itself: title, phase, locks, player cap, uptime, restarts, and shutdown. */ readonly instance: { /** Name the part of the game that is running ("lobby", "round 2", "over"). It is yours to choose; it is shown where the game is listed. Private games only (not games layered on the shared world). */ setPhase(phase: string): void; /** Update the running instance's live title shown in the instance bar. Private games only (not games layered on the shared world). */ setTitle(title: string): void; /** Stop new players joining (a round is under way), or with false let them in again. Players already in the game are not affected. Private games only (not games layered on the shared world). */ lock(locked?: boolean): void; /** Start the game over in place for a new round: the script starts again from onStart (after onLoad in a persistent game) with the players it has, and everything it put in the world is cleared. Saves are kept. Private games only (not games layered on the shared world). */ restart(): void; /** About this running game. */ info(): { game: string, kind: string, title: string, version: string }; /** Maximum number of players allowed in this running instance. */ playersMax(): number; /** True when the instance is currently locked against new joins. */ isLocked(): boolean; /** The current phase string set by `instance.setPhase` (default "play" or "lobby"). */ phase(): string; /** Seconds since this running script started. */ uptimeS(): number; /** End the game and send everyone back to the shared world. Private games only (not games layered on the shared world). */ end(reason?: string): void; }; /** Schedule callbacks once or on an interval, inspect active timers, or clear them all at once. */ readonly timers: { /** Run a function once, later. Returns an id for timers.cancel. */ after(seconds: number, fn: () => void): number; /** Run a function again and again (at most ten times a second). */ every(seconds: number, fn: () => void): number; /** Stop a timer. */ cancel(id: number): void; /** Stop every active timer in this script at once. */ cancelAll(): void; /** How many timers are currently active. */ count(): number; }; /** Convenient game math and randomness helpers: clamp, lerp, random integers, weighted loot rolls, shuffling, and seeded PRNGs. */ readonly math: { /** Constrain a number between `min` and `max`. */ clamp(value: number, min: number, max: number): number; /** Linearly interpolate from `a` to `b` by fraction `t` (0 to 1). */ lerp(a: number, b: number, t: number): number; /** A random whole number from `min` through `max` (inclusive). */ randomInt(min: number, max: number): number; /** Return one random element from an array, or null when empty. */ pick(list: any[]): any; /** Return a new randomly shuffled copy of an array without mutating the original. */ shuffle(list: any[]): any[]; /** Pick one item at random proportional to positive `weight` values, or null when empty. */ weighted(entries: { item: any, weight: number }[]): any; /** Create a fast, deterministic random number generator returning numbers between 0 and 1. */ seed(seed: string | number): () => number; }; /** Your game's own notebook: keep anything here for as long as the game runs. */ state: Record; /** Text players see, in English with its values filled in, marked so that each player gets it in their own language: eg.ui.toast(player, eg.t('{n, plural, one {# flag} other {# flags}} to go', { n })). Write the text out in quotes where you call it; put the parts that change in as {names} (a player becomes their name). Use the result anywhere players see text: toasts, the HUD, cards, menus, labels, waypoint hints. Translations come from your lang/.json files and, once the game is live and played, from the platform. */ t(text: string, values?: { [name: string]: string | number | Player }): string; } /** What a rules script exports: `export default { onStart() { … }, onPlayerJoin(player) { … } }`. Every handler is optional and may be async. */ export interface Handlers { /** Persistent games only, before onStart: everything this world saved with saves.set. "fresh" is true for a brand-new world. "version" is the version of your game that last saved it, so an update can convert old saves here. */ onLoad?(saved: { [key: string]: any }, info: { version: string | null, savedAt: number | null, fresh: boolean }): void | Promise; /** The game started (or restarted after the server did). Set things up here. */ onStart?(): void | Promise; /** A player entered the game. `rejoined` is true when they came back after a dropped connection in time to keep their place. */ onPlayerJoin?(player: Player, info: { rejoined: boolean }): void | Promise; /** A player's connection dropped and their place is being held for a while (manifest player.rejoinS). Pause what they were doing. */ onPlayerAway?(player: Player): void | Promise; /** A player is gone from the game for good. */ onPlayerLeave?(player: Player, reason: 'left' | 'disconnected' | 'timeout' | 'closed'): void | Promise; /** A player came into a new area (about 1.5 km squares), including the one they start in. Use it to put things where players actually are. */ onPlayerArea?(player: Player, area: { id: string, center: point }): void | Promise; /** A player switched how they are getting around (for instance walk to drive, or drive to walk). */ onPlayerMode?(player: Player, change: { from: string, to: string }): void | Promise; /** A player entered or left a zone with a trigger, or stayed in it slowly enough for long enough (dwell). */ onZone?(player: Player, entityId: string, what: 'enter' | 'leave' | 'dwell'): void | Promise; /** A player pressed F at an entity with `interact`. */ onInteract?(player: Player, entityId: string): void | Promise; /** A player chose something: a menu item or tab, a button on a card, HUD or window, closing a window, or one of the game's own actions (manifest `actions`, such as a key). */ onUi?(player: Player, what: { from: 'menu' | 'card' | 'hud' | 'action' | 'window', id: string, item?: string, tab?: string, button?: string, closed?: boolean }): void | Promise; /** A player lost health. `by` is the id of the player responsible, `npc` the character. */ onPlayerDamaged?(player: Player, hit: { amount: number, hp: number, why: 'npc' | 'player' | 'blast' | string, by?: string, npc?: number, kind?: string, weapon?: string }): void | Promise; /** A player reached 0 health and is down. */ onPlayerDied?(player: Player, hit: { why: string, by?: string, npc?: number, kind?: string, weapon?: string }): void | Promise; /** A downed player is back on their feet. */ onPlayerRespawn?(player: Player): void | Promise; /** A race you offered moved on. "start": the lights began (racers: how many on them). "gate": gate n of "of" crossed at ms. "finish": every gate crossed in ms milliseconds, with the splits, the par for their car's class (cls), and their place among "of" racers when it was a heat. "void": it ended without a time; reason is teleport, correct, fly, onfoot, swap, fast, expired or cancelled. */ onRace?(player: Player, race: { ev: 'start' | 'gate' | 'finish' | 'void', track: string, name?: string, cls?: string, car?: string, racers?: number, n?: number, of?: number, ms?: number, splits?: number[], par?: number, lengthM?: number, mode?: string, place?: number, featured?: boolean, user?: boolean, course?: boolean, reason?: string }): void | Promise; /** Something happened to one of the game's characters. `player` is who it saw, attacked or was killed by; `died` says where (lat, lon); `gone` says why it was removed. */ onNpc?(event: { ev: 'spawned' | 'died' | 'saw' | 'lost' | 'reached' | 'attack' | 'gone', id: number, player?: Player, kind?: string, damage?: number, spawner?: string, tag?: string, lat?: number, lon?: number, why?: string }): void | Promise; } /** game.json. Only id, title, summary, version and api are required. */ export interface Manifest { /** Lowercase letters, digits and dashes, 3 to 40 characters. Yours for good once published. */ id: string; title: string; summary: string; /** "1.0.0" */ version: string; api: 1; /** A match is played and over; a persistent world goes on. Up to 32 players. */ instance?: { kind?: 'match' | 'persistent'; minPlayers?: number; maxPlayers?: number }; /** Where it can be played. Leave it out (anywhere) unless the game really needs one place. */ area?: { anywhere: true } | { bbox: [west: number, south: number, east: number, north: number] } | { corridor: unknown } | { regions: string[] } | { built: true }; /** What players should know before they enter. Blood is only ever shown when `blood` is true here. */ content?: { violence?: 'none' | 'mild' | 'strong'; blood?: boolean; horror?: 'none' | 'mild' | 'strong'; language?: 'none' | 'mild' | 'strong'; pvp?: boolean; notice?: string }; /** The everyday traffic and passers-by inside your game: 0 (none, the default) to 1 (as in the shared world), up to 2. */ world?: { traffic?: number; pedestrians?: number }; /** modes: how players may get around. rejoinS: how long a dropped player's place is held (seconds, up to 600). */ player?: { modes?: ('walk' | 'drive' | 'fly' | 'boat' | 'bike')[]; rejoinS?: number }; /** Your own actions: "panel" is the game's main key (J); the rest are keys players press. */ actions?: { id: string; label?: string; key?: 'panel' | 'KeyB' | 'KeyG' | 'KeyH' | 'KeyJ' | 'KeyK' | 'KeyL' | 'KeyN' | 'KeyO' | 'KeyP' | 'KeyU' | 'KeyY' | 'KeyZ' | 'Digit5' | 'Digit6' | 'Digit7' | 'Digit8' | 'Digit9' | 'Digit0' }[]; } /** `eg` is always there in a rules script. For checked handlers: `/** @type {import("earthgames").Handlers} */ export default { … }`. */ declare global { const eg: Eg; }