# Custom Variables

{% hint style="info" %}
**Custom variables** is a feature that allows you to create and use your own variables. These variables can contain conditions that affect the output text.
{% endhint %}

{% hint style="success" %}

### How do Custom Variables Work?

When creating a custom variable, you define conditions that must be met to display certain text. These conditions can be specified within various contexts, such as Player, Target, Server, DiscordUser, or DiscordChannel.

### How to Use a Custom Variable

[Default Variables](https://docs.sourcefactory.eu/discord-utilities/available-variables) (also known as Available Variables) are used like this: {Server.MapName}, where each default variable overrides the input with a single value. However, Custom Conditions are used like this: \[Server.YourCustomVariable], these custom variables can display different texts based on the conditions met.

So, in short, Default Variables, already implemented in the plugin, are enclosed within `{XX}`, while your Custom Variables are enclosed within `[XX]`, distinguishing them from each other.
{% endhint %}

{% hint style="danger" %}

### How to Setup a Custom Variable

* <mark style="color:green;">**`Value`**</mark> - The value that will be checked (You can use Default Variables)
* <mark style="color:green;">**`Operator`**</mark> - What condition must be met
* <mark style="color:green;">**`ValueToCheck`**</mark> - The value that will be compared with `Value`(You can use Default Variables)
* <mark style="color:green;">**`ReplacementValue`**</mark> - Result if the condition is met

### Available Conditions (Operators)

* <mark style="color:red;">**`==`**</mark>: Means "equals". This condition is met if the Value is equal to the ValueToCheck
* <mark style="color:red;">**`!=`**</mark>: Means "not equals". This condition is met if the Value is not equal to the ValueToCheck
* <mark style="color:red;">**`~`**</mark>: Means "contains". This condition is met if the Value contains the ValueToCheck
* <mark style="color:red;">**`>=`**</mark>: Means "greater than or equal to". This condition is met if the Value is greater than or equal to the ValueToCheck
* <mark style="color:red;">**`<=`**</mark>: Means "less than or equal to". This condition is met if the Value is less than or equal to the ValueToCheck
* <mark style="color:red;">**`>`**</mark>: Means "greater than". This condition is met if the Value is greater than the ValueToCheck
* <mark style="color:red;">**`<`**</mark>: Means "less than". This condition is met if the Value is less than the ValueToCheck
* <mark style="color:red;">**empty**</mark> : Leave operator empty (`"Operator": "",`), to override variable if none of the previous conditions are met (And this condition must always be the last one)

### Available Functions

* <mark style="color:red;">**{Replace(VALUE1)(VALUE2)}**</mark> - The value in the first brackets is overwritten by the value in the second brackets
  {% endhint %}

{% hint style="success" %}

### Example of use:

1. We create a Custom Variable that:

• When the server is empty, display "Server Is Empty"

• When there are more than 0 players on the server, display: "Number of players on the Server"

```json
"Server.CustomOnlinePlayers": [ // YOUR CUSTOM VARIABLE NAME
      {
        "Value": "{Server.OnlinePlayers}", // DEFAULT VALUE
        "Operator": "==", // CONDITION
        "ValueToCheck": "0", // VALUE TO CHECK
        "ReplacementValue": "Server Is Empty" // DISPLAYED TEXT
      },
      { // If all previous conditions are not met, the ReplacementValue is displayed
        "ReplacementValue": "{Server.OnlinePlayers}"
      }
    ]
```

{% endhint %}

### Examples

<details>

<summary>Replace Map Prefixes (Like de_ , cs_ , awp_)</summary>

* If the map name contains de\_ / cs\_ / awp\_ , this text will be removed

```json
"Server.RemoveMapPrefix": [
      {
        "Value": "{Server.MapName}",
        "Operator": "~",
        "ValueToCheck": "de_",
        "ReplacementValue": "{Replace(de_)()}"
      },
      {
        "Value": "{Server.MapName}",
        "Operator": "~",
        "ValueToCheck": "cs_",
        "ReplacementValue": "{Replace(cs_)()}"
      },
      {
        "Value": "{Server.MapName}",
        "Operator": "~",
        "ValueToCheck": "awp_",
        "ReplacementValue": "{Replace(awp_)()}"
      }
    ]
```

</details>

<details>

<summary>Better Map Names</summary>

1. If the map name is de\_mirage, the resulting text will be `MIRAGE`&#x20;
2. If the map name contains nuke, the resulting text will be `Nuke`
3. None of the previous conditions is met, the default map name will be displayed

```
"Server.BetterMapName": [
      {
        "Value": "{Server.MapName}",
        "Operator": "==",
        "ValueToCheck": "de_mirage",
        "ReplacementValue": "MIRAGE"
      },
      {
        "Value": "{Server.MapName}",
        "Operator": "~",
        "ValueToCheck": "nuke",
        "ReplacementValue": "Nuke"
      },
      {
        "ReplacementValue": "{Server.MapName}"
      }
    ]
```

</details>

<details>

<summary>Better Players Count</summary>

1. If only bots are connected, the result will be: `Only the Bots are connected`
2. If the server is empty, the result will be: `Server Is Empty`
3. If the server is not empty, the result will be: e.g. `5/10`

```
"Server.BetterPlayersCount": [
      {
        "Value": "{Server.OnlinePlayers}",
        "Operator": "==",
        "ValueToCheck": "{Server.OnlineBots}",
        "ReplacementValue": "Only the Bots are connected"
      },
      {
        "Value": "{Server.OnlinePlayers}",
        "Operator": "==",
        "ValueToCheck": "0",
        "ReplacementValue": "Server Is Empty"
      },
      {
        "Value": "{Server.OnlinePlayers}",
        "Operator": ">",
        "ValueToCheck": "0",
        "ReplacementValue": "{Server.OnlinePlayers}/{Server.MaxPlayers}"
      }
    ]
```

</details>
