Templates

Most string fields in triggers and schedules can use templates to reference server, player, and message information. Helpers are available to aid formatting and allow for control of the output. You can use templates to do math, join words or phrases together, handle null variables, and more.

Comparing Conditions


With Templates you can now compare just about any condition to any other condition or value. To start, simply add a condition that you want to compare to the normal conditions section. You'll see that there is now a blue "x" button to the left of the input field. When you click that button, it will switch from text input mode to comparison mode. You can then select the what you want to compare your condition against.


Note that the types of comparison are limited to the type of the condition. For example, a Steam64ID is treated as a string, not a number. Therefore we do not allow you to do a greater than (>) comparative for that, only for numbers.

Variables

All of the data used in conditions can also be used in templates. The variable name is shown under the condition name and is also available in the conditions table available at the top right of the trigger and schedule pages.

Variable name usage
Location of Condition Table

Helpers

Helpers are available for formatting and output control.

coalesce

The coalesce helper returns the first defined value and can be used to provide defaults.

  • {{coalesce player.ip.country player.steam.country "ZZ"}} -> Would return ZZ if both the country info for the player's IP and Steam profile were missing.
  • {{coalesce player.ip.country player.steam.country}} -> Would return undefined if both the country info for the player's IP and Steam profile were missing.

concatenate con·cat·e·nate verb link (things) together in a chain or series.

The concatenate helper will accept one or more values to be joined together and optionally a separator parameter.

  • {{concatenate player.name ": " msg.body}} -> Example Name: Hello world
  • {{concatenate player.name msg.body separator=": "}} -> Example Name: Hello world
  • {{concatenate player.id player.name player.steamID separator=", "}} -> 123, Player Name, 7654321234567890

each

The each helper allows you to iterate over a jsonArray .

Example:

{{#each (jsonArray "one" "two" "three")}}
{{key}}. {{value}}
{{/each}}
0. one
1. two
2. three

regexp

The regexp helper takes a string and returns the specified result if it matches.

regexp accepts 3 arguments with an optional 4th argument that is used if there is no match. Execution time must not exceed 1 second.

{{regexp <needle> <haystack> <result> (<resultWithoutMatch>)}}


  • needle is a PCRE compatible regular expression (JavaScript). Flags can be specified by wrapping the expression in forward slashes and specifying flags at the end. Example: /regexp/i .
  • haystack is the value being matched against.
  • result is a template. Capture groups are available under regexp .
  • resultWithoutMatch is an optional template that is used when the regular expression does not match haystack .

Examples:

  • {{regexp "/this is (?<match>an) example/" "this is an example" "{{regexp.match}}"}} -> an
  • {{regexp "/this is (?<match>an) example/" "this is an example" "{{regexp.[1]}}"}} -> an
  • {{regexp "/this is (?<match>an) example/" "this is an example" "{{regexp.[0]}}"}} -> this is an example
  • {{regexp "/this is (?<match>an) example/" "this won\'t match" "{{regexp.[1]}}" "invalid"}} -> invalid

JSON Helpers

json

The json helper allows you to serialize a value.

  • {{json server.name}} -> "The \"Best\" Example Server"
  • {{json 52}} -> 52
  • {{json undefined}} -> null

jsonObject

The jsonObject helper allows you to build valid JSON objects and can be nested or combined with the jsonArray helper.

  • {{jsonObject name=server.name players=server.players maxPlayers=server.maxPlayers}} -> {"name": "Example Server Name", "players": 50, "maxPlayers": 70}
  • {{jsonObject
    server=(jsonObject
      name=server.name
      players=server.players
      maxPlayers=server.maxPlayers
    )
    player=(jsonObject
      name=player.name
      ip=player.ip
    )}}
    { "server": { "name": "Example Server Name", "players": 50, "maxPlayers": 70 }, "player": { "name": "Player Name", "ip": "127.0.0.1" } }

jsonArray

The jsonArray helper allows you to build valid JSON arrays and can be nested or combined with the jsonObject helper.

  • {{jsonArray player.ip.country player.steam.country}} -> [null,"US"]

jsonArrayIndex

The jsonArrayIndex helper can be used to get a value from a jsonArray . Arrays use zero based indexing.

  • {{jsonArrayIndex 0 (jsonArray 3 2 1)}} -> 3

jsonArrayShuffle

The jsonArrayShuffle helper randomly shuffles an array.

  • {{jsonArray 3 2 1}} -> [2,1,3] (Example, result is random)

jsonValue

The jsonValue helper gets the raw value from a jsonArray . Try jsonValue if you're getting quotes around a value that you don't want. Currently jsonValue does not make sense to use with jsonObject as there is no supported way to get a value from jsonObject .

  • {{jsonValue (jsonArray "one" "two" "three")}} -> one,two,three
  • {{jsonValue (jsonArrayIndex 0 (jsonArray "one" "two" "three"))}} -> one

Math Helpers

Helpers can be combined by wrapping a helper in parenthesis and using it place of an argument.

Examples for a player with 10,000 seconds of play time.

  • {{floor (divide player.timePlayed 3600)}} hours and {{floor (divide (subtract player.timePlayed (multiply (floor (divide player.timePlayed 3600)) 3600)) 60)}} minute(s) -> 2 hours and 46 minute(s)
  • {{toPrecision (divide player.timePlayed 3600) 3}} hours -> 2.78 hours

add

The add helper adds two or more values together.

  • {{add 1 1}} -> 2
  • {{add 1 1 1}} -> 3

subtract

The subtract helper subtracts one or more values from the first value.

  • {{subtract 2 1}} -> 1
  • {{subtract 2 1 1}} -> 0

divide

The divide helper divides two values.

  • {{divide 100 2}} -> 50
  • {{divide 0 0}} -> NaN

multiply

The multiply helper multiplies values together.

  • {{multiply 1 2}} -> 2
  • {{multiply 1 2 2}} -> 4

round

The round helper rounds a value to the nearest whole number.

  • {{round 1.5}} -> 2
  • {{round 1.2}} -> 1

floor

The floor helper rounds a value down.

  • {{floor 1.9}} -> 1
  • {{floor 1}} -> 1

ceil

The ceil helper rounds a value up.

  • {{ceil 1.1}} -> 2
  • {{ceil 1}} -> 1

abs

The abs helper returns the absolute value of a number.

  • {{abs -123}} -> 123

min

The min helper returns the smallest value given.

  • {{min 3 2 1}} -> 1

max

The max helper returns the largest value given.

  • {{max 1 2 3}} -> 3

toPrecision

The toPrecision helper rounds a value to the specified precision.

  • {{toPrecision 5.123456 5}} -> 5.1235
  • {{toPrecision 5.123456 2}} -> 5.1
  • {{toPrecision 5.123456 1}} -> 5

Still need help? Contact Us Contact Us