Register

Better Roll Formulas

An Add-on Module for Foundry Virtual Tabletop

Author: KitCat420 Project Source Foundry Versions 12 to 13 (Verified 13) Last Updated 6 months, 2 weeks ago

This module aims to enhance roll formula capabilities in Foundry VTT. It provides a set of new functions and operators that can be used in roll formulas to make them more powerful and flexible, as well as new dice modifiers. Users familiar with coding languages will find many familiar constructs, such as ternaries and logic operations.

List of new dice modifiers

Explode Compound <quantity>d<faces>xc<operator><target>

Examples

Explode all dice rolls that match the target and sum their results.

Explode Recursive Compound <quantity>d<faces>xrc<operator><target>

Examples

Explode all dice rolls that match the target and sum their results. Unlike Explode Compound, which only reroll the die once, recusive reroll will keep rolling as long as results meet the target.

Explode Penetrating <quantity>d<faces>xp<operator><target>

Examples

Explode all dice rolls that match the target, reducing the value of the extra rolled dice by 1.

Explode Recursive Penetrating <quantity>d<faces>xrp<operator><target>

Examples

Explode all dice rolls that match the target, reducing the value of the extra rolled dice by 1. Unlike Explode Penetrating, which only reroll the die once, recusive reroll will keep rolling as long as results meet the target.

Maximize <quantity>d<faces>mx<operator><target>

Examples

Artificially maximize all dice rolls that match the target to the maximum possible value.

Minimize <quantity>d<faces>mn<operator><target>

Examples

Artificially minimize all dice rolls that match the target to the minimum possible value.

Set <quantity>d<faces>set<value><operator><target>

Examples

Artificially set all dice rolls that match the target to the provided value.

Sort <quantity>d<faces>s<order>

Examples

Sort all dice rolls in either ascending or descending order based on their result.

Unique <quantity>d<faces>u

Examples

Re-roll all dice results that are duplicate of previous results, keeping only unique values. If more dice are rolled than faces are available, re-roll dices from left to right until all values have been encountered at least once.

List of available functions

Math Functions

Round round(a) round(a, precision)

Rounds a to the nearest integer. Optionally, rounds to the specified number of decimal places specified by precision, rather than to the closest whole number.

Floor (round down) floor(a) floor(a, precision)

Rounds a down to the nearest integer. Optionally, rounds to the specified number of decimal places specified by precision, rather than to the closest whole number.

Ceiling (round up) ceil(a) ceil(a, precision)

Rounds a up to the nearest integer. Optionally, rounds to the specified number of decimal places specified by precision, rather than to the closest whole number.

Exponential a ** b pow(a, b)

Exponential term of the form aᵇ.

Modulo a % b mod(a, b)

Remainder of the division of a by b.

Logic Functions

And a && b [&& ...] and(a, b[, ...])

Returns last argument, if all arguments are truthy. Supports arbitrary number of arguments.

Or a || b [|| ...] a ?: b [?: ...] or(a, b[, ...])

Returns first truthy argument, or 0 if all are falsy. Supports arbitrary number of arguments.

Xor xor(a, b[, ...])

Returns first truthy argument if only one argument is truthy, otherwise 0, otherwise returns false.

Not !a not(a)

Returns 0 if a is truthy, otherwise returns 1.

Odd odd(a)

Returns 1 if a is an odd number, otherwise returns 0.

Even even(a)

Returns 1 if a is an even number, otherwise returns 0.

Conditionals

Ternary a ? b : c ifThenElse(a, b, c)

Returns b if a is truthy, otherwise returns c.

IfNull a ?? b ifNull(a, b)

Returns b if a is null or undefined, otherwise returns a.

If if(a, b)

Returns b if a is truthy, otherwise returns 0.

Comparison Operators

Equal a = b a == b a === b eq(a, b)

Returns 1 if a is equal to b, otherwise returns 0.

Not Equal a != b a !== b neq(a, b)

Returns 1 if a is not equal to b, otherwise returns 0.

Greater Than a > b gt(a, b)

Returns 1 if a is greater than b, otherwise returns 0.

Greater Than or Equal a >= b gte(a, b)

Returns 1 if a is greater than or equal to b, otherwise returns 0.

Less Than a < b lt(a, b)

Returns 1 if a is less than b, otherwise returns 0.

Less Than or Equal a <= b lte(a, b)

Returns 1 if a is less than or equal to b, otherwise returns 0.

Bitwise Operators

Bitwise And a & b bitAnd(a, b)

Bitwise AND operation between a and b.

Bitwise Or a | b bitOr(a, b)

Bitwise OR operation between a and b.

Bitwise Xor a ^ b bitXor(a, b)

Bitwise XOR operation between a and b.

Bitwise Not ~a bitFlip(a)

Bitwise NOT operation on a.

Bitwise Left Shift a << b leftShift(a, b)

Bitwise left shift operation on a by b bits.

Bitwise Right Shift a >> b rightShift(a, b)

Bitwise right shift operation on a by b bits.

Bitwise Unsigned Right Shift a >>> b unsignedBitShift(a, b)

Bitwise zero-fill right shift operation on a by b bits.

Utility Functions

Lookup lookup(index, fallback, a, b, ...)

Returns the value at position index, or fallback if index is out of bounds.

Between between(value, min, max)

Returns 1, if the provided value lies between min and max (exclusive), otherwise returns 0.

Categories

Available Versions

  1. Version 1.2.7

    6 months, 2 weeks ago
    Foundry Version 12 - 13 (Verified 13) Manifest URL Read Notes
  2. Version 1.2.6

    6 months, 3 weeks ago
    Foundry Version 12 - 13 (Verified 13) Manifest URL Read Notes
  3. Version 1.1.1

    10 months, 3 weeks ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  4. Version 1.0.0

    1 year, 1 month ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes