resources/precinct/index.ts
1
import { arg, API_VERSION, type ResourceApi, type ResourceManifest } from "#server";
2
import { db } from "./db.ts";
3
4
export const manifest = { api: API_VERSION } satisfies ResourceManifest;
5
6
export function init(api: ResourceApi) {
7
api.on("playerJoined", ({ player }) => {
8
api.broadcast(`${player.name} signed in at the precinct.`);
9
});
10
11
// A look is plain JSON -- head, outfit, hat, the whole face layer. The mod
12
// ships no database: put it in yours, keyed by identity and never by name.
13
api.on("appearanceChanged", ({ player, look }) => {
14
db.characters.save(player.identity, look);
15
});
16
17
// The schema names and parses the arguments; the handler gets them typed.
18
api.command("goto", { args: [arg.num("x"), arg.num("y"), arg.num("z")] },
19
(player, { x, y, z }) => api.teleport(player.id, { x, y, z }));
20
21
// One clock for everyone; the engine reads the hour every frame.
22
api.setTimeOfDay(23.5);
23
api.setTimeRatio(0);
24
}