rednode API - v0.80.1
    Preparing search index...

    Interface Game

    Entry point for Tier 2 mods and overlay apps. Use the game instance.

    interface Game {
        audio: Audio;
        instance: Record<string, never>;
        player: Player;
        call<T = unknown>(
            method: string,
            params?: Record<string, unknown>,
        ): Promise<T>;
        language(): Promise<Language>;
        on<T = GameEvent>(name: string, handler: EventHandler<T>): Unsubscribe;
        onState(handler: EventHandler<GameState>): Unsubscribe;
        state(): Promise<GameState>;
    }
    Index
    audio: Audio

    The game's audio.

    instance: Record<string, never>

    The game instance, for the many game functions whose first argument is a GameInstance.

    const stats = await api.GameInstance.GetStatsSystem(game.instance);
    
    player: Player

    The player character.

    • Calls a bridge method by name. The typed calls such as Player.position are built on it.

      Type Parameters

      • T = unknown

        The result type.

      Parameters

      • method: string

        For example "player.position".

      • Optionalparams: Record<string, unknown>

        The method's parameters, if any.

      Returns Promise<T>

      const info = await game.call<{ frame: number }>("game.info");
      
    • The interface language the player chose in the game: its own name ("fr-fr") and the standard tag ("fr-FR") for Intl. game.on("language", …) hears a change, with the new name in the event's language.

      Returns Promise<Language>

      const { tag } = await game.language();
      const eddies = new Intl.NumberFormat(tag).format(123456);
    • Subscribes to a game event.

      Events are named by the game class and method that raise them, such as "PlayerPuppet.OnGameAttached", at the main menu and on every save load. REDnode's own events have short names: "combat" (CombatEvent: V's combat state changed) and "npcDowned" (NpcDownedEvent: a person defeated or killed, with their affiliation and whether V did it), sent by the game as they happen, never polled.

      Type Parameters

      Parameters

      • name: string

        Event name, for example "PlayerPuppet.OnGameAttached".

      • handler: EventHandler<T>

        Called for every occurrence. The game does not wait for it.

      Returns Unsubscribe

      A function that stops the subscription.

      const stop = game.on("PlayerPuppet.OnGameAttached", async () => {
      console.log("A save was loaded");
      });
    • Calls a handler whenever the game state changes, and once at the start with the current state.

      Parameters

      Returns Unsubscribe

      game.onState((s) => console.log(s.menu ? "menu open" : "menu closed"));

      // Read the world only while V is in it.
      let reading: ReturnType<typeof setInterval> | undefined;
      game.onState((s) => {
      if (s.world && !reading) reading = setInterval(readWeather, 1000);
      if (!s.world && reading) {
      clearInterval(reading);
      reading = undefined;
      }
      });
    • Reads what the game is showing: menus, photo mode, scenes, the main menu.

      Returns Promise<GameState>

      const s = await game.state();
      if (s.world) console.log("V is in the world");