Dxcufgb's Workshop

API

DeprecatedDeprecated: this module has been merged into Dxcufgb's Reminders. Please use that module instead.

const api = game.modules.get("dxcufgbs-death-trigger").api;

api.findTriggers(actor);            // the actor's items that count as death triggers → Item[]
await api.alert(actor);             // posts the GM alert card for this actor now, whatever its HP → the ChatMessage, or null if it has no death triggers
api.triggerStatus(item);            // → { trigger, reason, detail }; reason: "always" | "never" | "list" | "none"
api.hpPathFor(actor);               // the HP path inside actor.system the module watches, e.g. "attributes.hp.value"

api.getList();                      // the world's list ({ version, triggerTypes, features }), or null before it is set up
api.isListed("Undead Fortitude");   // a name or an item → true / false
await api.addToList(item);          // GM: adds the item (or a name) to the list → true if it was added
await api.removeFromList(item);     // GM: removes the entries matching that name or item (see Remove above) → true if any were removed
api.exportList();                   // GM: downloads the list as death-triggers-<world id>.json
await api.importList();             // GM: opens the file picker and the Yes/No warning → true if the list was replaced
await api.resetList();              // GM: replaces the world's list with the default list, without asking → true when done
await api.configureItem(item);      // GM: opens the Automatic / Always / Never dialog for this item
  • alert(actor, triggers) takes an optional array of items to show on the card (default: findTriggers(actor)). It doesn't check HP, the Only check non-player creatures setting or whether the creature was already alerted. Any user can call it; the card is always whispered to the GMs.
  • GM calls do nothing for players (they return false, or nothing for exportList and configureItem). addToList also returns false when the name is already in the list. List changes show a notification.
  • triggerStatus(item): the item's own Always / Never setting wins, then the list. When reason is "list", detail is the name of the matching list entry.
  • removeFromList works like Remove in the context menu; see The Death Trigger List.

From another module

The API is set in the module's ready hook, so it isn't there during init or setup, and depending on load order it may not be there yet when your own ready runs. Look it up when you need it, and make it optional:

function deathTriggers(actor) {
  const api = game.modules.get("dxcufgbs-death-trigger")?.api;   // undefined when the module is missing or not enabled
  return api ? api.findTriggers(actor) : [];
}

Add { "id": "dxcufgbs-death-trigger", "type": "module" } to relationships.recommends in your module.json.

Reacting to an alert

The module calls no hooks of its own. To react to an alert, watch for its chat card. It is whispered to the GMs, so it only reaches GM clients:

Hooks.on("createChatMessage", async message => {
  if (!message.getFlag("dxcufgbs-death-trigger", "alert")) return;
  const actor = await fromUuid(message.getFlag("dxcufgbs-death-trigger", "actorUuid"));
  const itemUuids = message.getFlag("dxcufgbs-death-trigger", "itemUuids");   // the features on the card
  console.log(`${actor?.name} dropped to 0 HP with ${itemUuids.length} death trigger(s)`);
});

Data

  • flags.dxcufgbs-death-trigger.trigger on Items: true (always a death trigger), false (never), unset (follow the list). See Excluding Features.
  • flags.dxcufgbs-death-trigger on the alert card: alert: true, actorUuid (the creature) and itemUuids (the features on the card).
  • The list (what getList() returns, what Export writes and Import reads): { "version", "triggerTypes", "features" }, where version is the list version (2 for the current default list) and triggerTypes names the trigger types. Each feature needs a name; match is "exact" (the default) or "contains", and aliases is an optional array of other names that match too. id identifies the entry; the other fields (type, owner, edition, source, trigger, effect, …) only describe it. Import refuses a file without a features array or with an entry that has no name. In the module's default list, entries added after the first version carry listVersion.

This page mirrors the Death Trigger Alerts wiki on GitHub.