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

    Variable tweakdbConst

    tweakdb: {
        clone(path: string, base: string): Promise<boolean>;
        create(path: string, type: string): Promise<boolean>;
        flat<T = unknown>(path: string): Promise<Flat<T> | null>;
        get<T = unknown>(path: string): Promise<T | null>;
        id(path: string): string;
        learn(paths: string[]): void;
        name(id: string): string | null;
        record<K extends keyof RecordTypes = "gamedataTweakDBRecord">(
            path: string,
            type?: K,
        ): Promise<RecordTypes[K] | null>;
        records(type: string): Promise<string[]>;
        set(
            path: string,
            value: unknown,
            options?: { type?: string },
        ): Promise<boolean>;
        type(path: string): Promise<string | null>;
        update(path: string): Promise<boolean>;
    } = ...

    Reading TweakDB from the running game.

    Type Declaration

    • clone: function
      • A new record, as a copy of another one, through TweakXL. Change its flats with tweakdb.set. Records stay until the game closes: TweakDB cannot remove them.

        Parameters

        • path: string
        • base: string

        Returns Promise<boolean>

        await tweakdb.clone("Items.MyMod_Lexington", "Items.Preset_Lexington_Default");
        
    • create: function
      • A new, empty record of a type, through TweakXL. Most mods clone an existing record instead, which comes with every flat its type needs.

        Parameters

        • path: string
        • type: string

        Returns Promise<boolean>

    • flat: function
      • A flat with its type, or null when there is none.

        Type Parameters

        • T = unknown

        Parameters

        • path: string

        Returns Promise<Flat<T> | null>

        await tweakdb.flat("Items.money.quality"); // { type: "TweakDBID", value: "0x..." }
        tweakdb.learn(["Quality.Common"]);
        await tweakdb.flat("Items.money.quality"); // { type: "TweakDBID", value: "Quality.Common" }
    • get: function
      • A flat's value, or null when TweakDB has no such flat. TweakDB ids in the value come back as paths when their names are known.

        Type Parameters

        • T = unknown

        Parameters

        • path: string

          The flat's path, such as "Items.money.quality", or its id as "0x...".

        Returns Promise<T | null>

        const capacity = await tweakdb.get<number>("Items.Preset_Lexington_Default.magazineCapacity");
        
    • id: function
      • The id of a path, as the game computes it: "0x...". Needs no game.

        Parameters

        • path: string

        Returns string

        tweakdb.id("Items.money"); // "0x0000000B..."
        
    • learn: function
      • Tells REDnode the names of ids, such as a list of the records your mod uses, so they come back as paths.

        Parameters

        • paths: string[]

        Returns void

    • name: function
      • The path of an id, when REDnode knows its name, or null.

        Parameters

        • id: string

        Returns string | null

    • record: function
      • A record, as a game object you can call methods on, or null when there is none. Give its type for typed methods; it is not checked.

        Type Parameters

        • K extends keyof RecordTypes = "gamedataTweakDBRecord"

        Parameters

        • path: string
        • Optionaltype: K

        Returns Promise<RecordTypes[K] | null>

        const car = await tweakdb.record("Vehicle.v_standard2_archer_hella_player", "Vehicle");
        console.log(await car?.DisplayName());
    • records: function
      • The ids of every record of a type, as paths where their names are known and "0x..." otherwise. A list can be long: TweakDB holds thousands of items.

        Parameters

        • type: string

        Returns Promise<string[]>

        const ids = await tweakdb.records("Vehicle");
        console.log(`${ids.length} vehicles`);
    • set: function
      • Changes a flat, through TweakXL, and applies it to its record. The flat keeps its own type; a flat that does not exist yet needs type, such as "Int32", "String" or "array:CName". Resolves with TweakXL's answer: true when it took the value.

        REDnode undoes the change when your package stops. Changes made at once (with Promise.all) run in the same game frame.

        Objects already in the game, such as an item in V's inventory, may keep the values they copied when they were made. Unverified which ones.

        Parameters

        • path: string
        • value: unknown
        • options: { type?: string } = {}

        Returns Promise<boolean>

        await tweakdb.set("Items.Preset_Lexington_Default.friendlyName", "REDnode's Lexington");
        await Promise.all([
        tweakdb.set("Items.MyGun.quality", "Quality.Legendary"),
        tweakdb.set("Items.MyGun.tags", ["Weapon", "MyMod"], { type: "array:CName" }),
        ]);
    • type: function
      • A record's type, its native name such as "gamedataVehicle_Record", or null when there is no such record.

        Parameters

        • path: string

        Returns Promise<string | null>

    • update: function
      • Applies a record's changed flats to the record object. tweakdb.set does this itself; call it after changing flats some other way.

        Parameters

        • path: string

        Returns Promise<boolean>

    import { tweakdb } from "rednode";

    const name = await tweakdb.get("Items.Preset_Lexington_Default.friendlyName"); // "w_handgun_militech_lexington"
    const weapon = await tweakdb.record("Items.Preset_Lexington_Default", "WeaponItem");
    const vehicles = await tweakdb.records("Vehicle"); // every vehicle record's id