Repository navigation
API
For macro and module authors.
const tt = game.modules.get("dxcufgbs-tile-triggers").api;
await tt.open(tile); // GM: open the editor on a tile (no tile = just the window)
await tt.fire(tile, "Spike trap", { token }); // fire a trigger by name or id → true, or false when it doesn't fire
await tt.fire(tile, "Spike trap", { token, force: false }); // GM: only fire if the trigger's conditions allow it
const triggers = tt.getTriggers(tile); // the tile's triggers, defaults filled in (a copy)
await tt.setTriggers(tile, triggers); // GM: replace the tile's triggers
await tt.resetState(tile); // re-arm all "once" triggers on the tile
await tt.resetState(tile, triggers[0].id); // re-arm one trigger
tt.isDisarmed(tile); // true when disarmed
await tt.setDisarmed(tile, true); // disarm (false = re-arm)
await tt.setDisarmed(tile, false, { resetFired: true }); // re-arm and re-arm its "once" triggers
tt.registerAction("my-module.myAction", def); // add an action type (see below)
await tt.runActions(action.success, ctx); // run an action list, from a custom action's run (see below)
tt.actions; // every action type, by type: { label, icon, group, fields, branches, run, summary }
tt.events; // the trigger events, by name: { icon, movement, round }-
tileis aTileDocument(usetile.documentfor a Tile on the canvas).open,fire,isDisarmedandsetDisarmedalso take a tile UUID,firea token UUID. -
firethrows when the tile or the trigger isn't found. A GM's fire is forced past the trigger's conditions (also on disarmed and switched-off tiles) unlessforce: false. A player can only fire "Manual / macro only" triggers, with no token or a token of their own, and never forced. The actions always run on the GM's client. -
setTriggerswrites the list as given (no checks): use the trigger shapegetTriggersreturns and give every trigger and action anid. Missing trigger options get their defaults when read. -
actionsandeventsare read-only: each read returns a frozen copy (actions added withregisterActionincluded), never the lists the module uses. Add actions withregisterAction; see Custom Actions. -
eventskeys are the trigger event names:enter,exit,stop,turnStart,turnEnd,roundStart,initiative,click,manual.movementis true for the movement events;roundis true forroundStartandinitiative, which fire once per combat round with no token. -
fireworks for round start and initiative count triggers too (a GM's forced fire), with no token or the one you pass.
-
Hooks.on("dxcufgbs-tile-triggers.fire", ctx => …): a trigger is about to run its actions. Called on the GM's client that runs them.ctxis{ tile, trigger, token, actor, user, event, scene, depth, vars }(tokenis a TokenDocument ornull,useris who set it off). ForroundStartandinitiativeeventstokenisnullanduseris the GM. A Play animation action with a random patch addsctx.patch = { x, y, width, height }(scene pixels) for the actions after it. -
Hooks.on("dxcufgbs-tile-triggers.disarm", (tile, disarmed) => …): a tile was disarmed or re-armed, whatever did it. Runs on every client.
Both are callAll, so they can't cancel anything.
Hooks.once("ready", () => {
const tt = game.modules.get("dxcufgbs-tile-triggers")?.active ? game.modules.get("dxcufgbs-tile-triggers").api : null;
if (!tt) return; // Tile Triggers not installed or not enabled
Hooks.on("dxcufgbs-tile-triggers.fire", ctx => console.log(ctx.trigger.name, ctx.token?.name));
});Add { "id": "dxcufgbs-tile-triggers", "type": "module" } to relationships.recommends in your module.json.
Triggers live on the tile: flags["dxcufgbs-tile-triggers"].triggers (read it with api.getTriggers, write it with api.setTriggers). Trigger options added in 1.2.0: initiative (number, default 20) and requireToken (boolean, default true). .disarmed is the disarmed state (use api.setDisarmed), .disabled: true means "Triggers on this tile are active" is unticked, .name is the tile's name in the editor and .shape its area ("rectangle" or "ellipse"). .state (what each trigger has fired for) is internal.
Tile flags are visible to players' clients; see Notes.
Dxcufgb's Workshop: every Foundry VTT project, video and changelog in one place · Support on Ko-fi · MIT License
Using it
For module authors
Help