Shattered Codex

Wiki

Modules/SC - Conditional AE

SC - Conditional AE

Foundry v13-v14System D&D 5eFree

SC - Conditional AE

Overview

SC - Conditional AE extends the D&D 5e Active Effect workflow in three practical ways:

  • a Condition tab on the Active Effect sheet
  • an optional Formula column for effect changes
  • a macro execution change that can run when an effect turns on or off

In practice, this lets you build effects that:

  • only apply while a JavaScript condition returns true
  • roll a fresh number when the effect activates and write that result into the change value
  • trigger a world macro as the effect is enabled, disabled, or removed

If a condition evaluates to false, the effect is suppressed and does not apply.

Installation

This module will be free, but it is currently in development.

The public manifest URL is intentionally hidden until the release build is ready.

For now, treat this page as documentation for the upcoming release workflow and feature set. Installation details will be published when the module leaves development.

Requirements

  • Foundry VTT v13 or v14
  • system: dnd5e
  • dnd5e system version: 4.0.0+
  • recommended: libWrapper

Compatibility notes from the module behavior:

  • legacy DAE condition flags are adapted into the new Condition tab
  • DAE-style expressions using @ data references are supported through compatibility mode
  • a safe fallback type is registered for Aura Effects data when Aura Effects itself is not active

Feature Overview

FeatureWhat it doesWhere you use it
Condition tabRuns JavaScript to decide whether the Active Effect should currently apply.Active Effect sheet
Formula columnRolls a formula on activation and writes the rolled total into the normal change value.Active Effect changes table
Macro execution changeExecutes a world macro when the effect turns on or off.Active Effect changes table

Condition Tab

When Show condition tab is enabled, Active Effect sheets gain a dedicated Condition tab.

Use it to write either:

  • a short expression such as actor?.system?.attributes?.hp?.value > 0
  • or a full JavaScript block that explicitly returns true or false

Examples:

js
return actor?.system?.attributes?.hp?.value > 0;
js
actor?.system?.attributes?.hp?.value > 0

The module builds the condition context with variables such as:

  • effect
  • actor
  • targetActor
  • item
  • origin
  • originActor
  • user
  • rollData
  • source
  • getProperty
  • hasProperty
  • deepClone
  • game

Behavior details worth knowing:

  • empty conditions always allow the effect
  • invalid condition code suppresses the effect instead of partially applying it
  • conditions must stay synchronous in native JavaScript mode
  • actor effects and transferred item effects both evaluate through the same condition service
Empty Condition tab on an Active Effect sheet
Condition tab
The native Condition tab adds a dedicated editor area and lists the evaluation variables available to the script.
1 / 2

Example Conditions

These examples are ready to copy into the Condition tab.

Actor Must Have More Than 0 HP

js
return (actor?.system?.attributes?.hp?.value ?? 0) > 0;

Actor Must Be Bloodied

js
const hp = actor?.system?.attributes?.hp?.value ?? 0;
const maxHp = actor?.system?.attributes?.hp?.max ?? 0;
return hp <= maxHp / 2;

Actor Must Be Below Half HP

js
const hp = actor?.system?.attributes?.hp?.value ?? 0;
const maxHp = actor?.system?.attributes?.hp?.max ?? 0;
return maxHp > 0 && hp < maxHp / 2;

Item Must Be Equipped

js
return item?.system?.equipped === true;

Item Must Be Attuned

js
return item?.system?.attunement === 2;

Item Must Be Equipped And The Actor Must Be Alive

js
return item?.system?.equipped === true
  && (actor?.system?.attributes?.hp?.value ?? 0) > 0;

Item Must Have At Least One Socket Occupied

Use this when the effect belongs to an item that also uses SC - Simple Sockets.

js
const sockets = item?.getFlag?.("sc-simple-sockets", "sockets") ?? [];
return sockets.some((slot) => Boolean(slot?.gem));

Item Must Have At Least Two Occupied Sockets

js
const sockets = item?.getFlag?.("sc-simple-sockets", "sockets") ?? [];
const occupied = sockets.filter((slot) => Boolean(slot?.gem));
return occupied.length >= 2;

Item Must Have A Specific Gem UUID Socketed

js
const sockets = item?.getFlag?.("sc-simple-sockets", "sockets") ?? [];
return sockets.some((slot) => slot?.gem?.uuid === "Item.yourGemUuidHere");

Item Must Have At Least One Socket Defined

js
const sockets = item?.getFlag?.("sc-simple-sockets", "sockets") ?? [];
return sockets.length > 0;

Only The GM Can Benefit From The Effect

js
return user?.isGM === true;

Effect Must Only Apply During Combat

js
return Boolean(game?.combat);

For socket checks, the examples above use direct flag reads instead of async API calls because native SC - Conditional AE conditions are synchronous.

Formula-Backed Changes

When Enable formula column is enabled, eligible Active Effect changes can store an extra formula alongside the normal value.

Use this when you want the effect to roll at activation time instead of hard-coding the final number.

Example setup:

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: -2d6

Ready-to-copy formula ideas:

Roll Negative Temporary Hit Point Maximum

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: -2d6

Roll Positive Temporary Hit Point Maximum

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: 2d6

Roll A Small Temporary Hit Point Bonus

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: 1d4 + 1

Scale Temporary Hit Point Maximum With Spellcasting

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: 1d6 + @abilities.cha.mod

Scale Temporary Hit Point Maximum With Proficiency

code
Attribute Key: system.attributes.hp.tempmax
Mode: Add
Value: 0
Formula: 1d8 + @prof

Typical runtime flow:

  1. The effect becomes active.
  2. The responsible user is prompted to review or edit the formula.
  3. The formula is rolled.
  4. The rolled total is written into the effect's normal Value field.
Active Effect changes table with an empty Formula column
Formula column
The extra Formula column sits alongside the normal change fields and stays available only when the module setting is enabled.
1 / 4

Responsibility selection follows the module logic:

  • an active non-GM owner is preferred first
  • if no active player owner is available, the active GM handles the roll

This is useful for:

  • variable temporary HP penalties or bonuses
  • random stat adjustments
  • effects that should re-roll whenever they come back online

Macro Execution Changes

To execute a world macro from an Active Effect, add a change with:

  • Key: cae.macro.execute
  • Mode: Custom
  • Value: a macro name or UUID, followed by optional arguments

Example:

code
Apply Rage "fire" 2

That would try to execute the macro Apply Rage and pass fire and 2 as macro arguments.

The execution scope includes:

  • action
  • actor
  • token
  • effect
  • item
  • origin
  • change
  • args
  • macroArgs
  • lastArg
  • speaker
  • user

Action values:

  • on when the effect is applied or re-enabled
  • off when the effect is disabled or deleted

The service also supports:

  • sc-conditional-ae.macro.execute as a legacy key
  • macro.execute when DAE is not active

If DAE is active, DAE remains responsible for macro.execute.

Compatibility Notes

The module includes explicit compatibility behavior for older and adjacent workflows.

IntegrationBehavior
DAE condition flagsReads legacy `flags.dae.enableCondition` and `flags.dae.disableCondition` values and surfaces them through the Condition tab.
DAE expression syntaxSupports compatibility expressions that use `@` roll-data references, `dae.eval(...)`, and `dae.roll(...)`.
DAE macro changesAdds `cae.macro.execute` to DAE specials and avoids taking over `macro.execute` when DAE is active.
Aura EffectsRegisters a fallback Active Effect type for Aura Effects data when that module is not active, so imported effect data has a safer landing path.

Module Settings

Go to Game Settings -> Module Settings -> SC - Conditional AE.

SettingDefaultWhat it does
Enable formula columnOnAdds the Formula column to Active Effect changes and enables activation-time rolls.
Show condition tabOnAdds the Condition tab to Active Effect configuration sheets.
Documentation-Opens the module wiki.
Support the developer-Opens the Patreon support page.

Both boolean settings require a reload after you change them.

Troubleshooting

The effect never applies

Check these first:

  1. Confirm the Condition tab returns true.
  2. Verify the code is valid JavaScript.
  3. Do not use async code in the native JavaScript condition workflow.
  4. If the effect came from DAE, verify the original expression still makes sense for the current actor data.

The Formula column is missing

  1. Make sure Enable formula column is on.
  2. Reload the world after changing that setting.

The macro does not run

  1. Confirm the change key is cae.macro.execute.
  2. Confirm the change mode is Custom.
  3. Make sure the referenced macro exists in the world macro directory.
  4. Check whether the effect is being suppressed by its condition.

Notes and Limits

  • This page reflects the current development build and may change before release.
  • The public manifest URL is intentionally not shown yet.
  • Native JavaScript conditions are synchronous; asynchronous logic is only relevant to compatibility expressions handled outside that path.
  • If condition code throws an error, the effect is treated as unavailable.