Expressions and Variables
On this page(7)
Almost every number inside an action can be math. That is how an enchant scales. Its damage grows with your level, a loop repeats more often, and a chain hits harder on each jump.
amount: '{damage} * (1 + {level} / 100)' # +1% damage per level
radius: '2 + {level} / 250' # a bigger area as you level
times: 'min(12, 3 + floor({level} / 100))' # 3 rounds, one more every 100 levels, at most 12Quote every expression that has braces, spaces or operators: '{damage} * 2'. In YAML an
unquoted {damage} starts a map and breaks the file.
Operators
| Operator | Meaning | Example |
|---|---|---|
+ - * / | Add, subtract, multiply, divide | {damage} * 3 + 10 |
% | Remainder | {level} % 2 (0 on even levels) |
^ | Power | 1.05 ^ {level} |
( ) | Grouping | ({level} + 10) / 2 |
== != < <= > >= | Comparison: 1 when true, 0 when false | {level} >= 50 |
&& || ! | And, or, not | {level} >= 50 && {jump} > 1 |
Comparisons shine in requirement: and in math tricks. {damage} * (1 + ({level} >= 500)) doubles the damage from level 500 on.
Functions
| Function | Result |
|---|---|
min(a, b, ...) / max(a, b, ...) | The smallest / largest value |
floor(x) / ceil(x) | Rounded down / up to a whole number |
round(x) | Rounded to the nearest whole number |
abs(x) | The value without its sign |
sqrt(x) | The square root |
pow(a, b) | a to the power b (same as a ^ b) |
log10(x) | The base 10 logarithm |
clamp(x, low, high) | x, kept between low and high |
A division by zero or any other result that is not a finite number makes that action do nothing. It never crashes the enchant.
Variables
Variables are always written in braces. A variable that does not exist is a warning, and what happens next depends on the key:
- In a required key (a damage
amount), the action is skipped. - In an optional key, its default is used.
- In a text, the variable shows as written and the action still runs.
chance and requirement are optional keys. A typo in them drops the guard, so the action runs on
every proc at every level. Always read the console after a reload.
| Variable | Value | Valid |
|---|---|---|
{level} | The player's level of this enchant | Everywhere |
{max_level} | The max-level of this enchant | Everywhere |
{damage} | The damage of the swing that procced: the sword damage times your damage boosters, before debuffs | Everywhere |
{prestige} | The prestige stars of this enchant (0 without) | Everywhere |
{prestige_power} | The chance factor of those stars: 1 + power-per-star x stars | Everywhere |
{max_prestige} | Its max-stars (0 = no prestige) | Everywhere |
{random:a:b} | A new random number from a up to (not including) b, every time it is read. a and b are plain numbers | Everywhere |
{i} | The round of the innermost loop, from 0 | Inside a loop (0 outside) |
{mob_health} | The health of the mob of the running round, read when the round starts | Inside a for-each-mob (0 outside) |
{mob_health_percent} | That health in percent of its max health, 0 to 100 | Inside a for-each-mob (0 outside) |
{jump} | The jump of the running chain, from 1 | Inside a chain (0 outside) |
{point_index} | The point of the running round, from 0 | Inside a for-each-point (0 outside) |
{point_count} | How many points that path walks | Inside a for-each-point (0 outside) |
{debuff_stacks} | The most charges one mob has after the last debuff action of this proc | After a debuff (0 before) |
{debuff_percent} | Those charges times that debuff's percent (the extra damage) | After a debuff (0 before) |
{<param>} | A number param of the preset this line is in | Inside a preset |
{random:1:7} gives decimals from 1 up to 6.99. For a whole number from 1 to 6, write
floor({random:1:7}).
PlaceholderAPI numbers
An expression can read a PlaceholderAPI placeholder of the player as a number:
amount: '{damage} * (1 + %player_level% / 100)'- The placeholder is read when the action runs.
- Only letters, digits and
_ : - .may appear between the%signs. - When the text is not a number, or PlaceholderAPI is missing, the value is not a number and the action does nothing.
Plain-number keys
A few keys take a plain number only, never an expression or a variable:
- Every root key:
max-level,chance,cooldown-ticks,cost. fade-in,stayandfade-outof atitle.sizeof aDUSTparticle.weightof arandomentry.- The
valueandticksof everyanimation:step. max-multiplierandtimeofadd-booster(timetakes30s,5m,1h,1dor seconds).amountandcustom-model-dataof an item map.- Every key of
follow:anddash:(exceptdash.damage) and ofmomentum:.
Texts
Texts are message, actionbar, title, subtitle, a text display and a mob or NPC name. They
take:
- Colors:
&c,&l, hex&#FF5555, and MiniMessage tags like<red>or<gradient:#FF5555:#FFAA00>. - PlaceholderAPI placeholders of the player:
%player_name%. - Text variables:
{player}(the player's name),{enchant}(the display-name) and{enchant_id}. - Every number variable of the table above. A whole number shows without decimals, any other number with up to 2 decimals.
- Formatted numbers: add
_formattedto any number variable for the currencies' number format:{damage_formatted}shows1.5K. - In a text,
{level}showsmax-level-labelofmodules/sword/config.ymlonce the enchant is at its max-level.{level_formatted}stays the number.
- type: message
message: '&7[&d{enchant}&7] &flevel {level}/{max_level} &7hit for &c{damage_formatted}'There is no math inside braces in a text. {level*2} stays as written and logs a warning. To
show a computed number, pass it through a preset number param, then write
{param} or {param_formatted} in the text.
Ids with variables
The id and name of add-booster and the id of
remove-booster also paste {player}, {enchant_id}, {level} and the number variables:
id: 'frenzy-{enchant_id}'.