Skip to content

Tweaks from plugins

A plugin can add tweaks to the overlay’s Tweaks window, the same list tweak files go in, with fields players can change. They’re listed under the plugin’s name.

For game values players should see and change, tagging a struct in your schemas [Tweak("..")] is often enough, with no code at all. See Values players can change.

tweaks.add(definition, handler) adds one. tweaks.addIn(section, definition, handler) puts it under a heading of its own, like Combat.

A Tweaks.Definition has an id, a title, a default key like F8, a mode and its fields. Each Tweaks.Field has a name, a type like f32 or u32, a starting value, and limits with has_min, min, has_max and max.

The handler gets a Tweaks.Event. Its kind is on and off as it’s turned on and off, and changed for each field, with all of them coming just before on. With mode set to action it runs once each time instead, as on. Failing an on keeps it off, and the overlay shows why.

import { Wraith } from "wraith";
const { EventKind } = Wraith.Tweaks;
let x = 2;
Wraith.tweaks().add(
{ id: "speed", title: "Speed", key: "F8", fields: [{ name: "x", type: "f32", value: x, has_min: true, min: 1, has_max: true, max: 5 }] },
(event) => {
if (event.kind === EventKind.changed) x = event.value ?? x;
else if (event.kind === EventKind.on) { /* turned on */ }
else if (event.kind === EventKind.off) { /* turned off */ }
},
);

Throwing from on keeps it off, and the overlay shows what was thrown.

Two kinds need no handler. tweaks.addHook(section, definition, hook) makes a toggle that enables a hook while it’s on. tweaks.addOpener(section, definition, window) makes an open button that opens and focuses one of your windows, so it can be opened from the Tweaks window too. The heading comes first, and "" is none. The definition’s mode and fields are ignored.

import { Wraith } from "wraith";
const tweaks = Wraith.tweaks();
tweaks.addHook("Money", { id: "free_shopping", title: "Free shopping" }, freeShopping);
tweaks.addOpener("Party", { id: "party", title: "Party members" }, partyWindow);

For anything else that opens, a definition with mode set to open shows an open button too, and calls the handler’s on when it’s clicked.

tweaks.isOn(name) says whether any tweak’s box is on, by its saved name like kai/Combat/Max bravery, and tweaks.setOn(name, on) turns it on or off next frame, the same as clicking it. tweaks.onSwitched(handler) hears every tweak going on or off. tweaks.remove(id) takes one of yours away.

import { Wraith } from "wraith";
Wraith.tweaks().onSwitched((name, on) => Wraith.log().info(`${name} is ${on ? "on" : "off"}`));

Made with ♥ by Asgard