> For the complete documentation index, see [llms.txt](https://docs.ragnasync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ragnasync.com/ragnascript/message-templates.md).

# Message Templates

Send pre-formatted messages from your game server to Discord using the src\_template placeholder

Message templates let your game server send its own pre-formatted messages to Discord. Instead of relying on RagnaSync's built-in formatting, your server controls the exact text that appears.

This is especially useful when your server has information that RagnaSync doesn't know about — like map names, party details, or item categories.

## How It Works

1. Your game server adds a `[template: ...]` field to its RagnaScript packet
2. RagnaSync captures the template text and makes it available as `{{src_template}}`
3. On your dashboard, set a route's format to **Custom Message** and use `{{src_template}}` as the template

That's it — whatever your server puts in the `[template: ...]` field shows up in Discord.

## Quick Setup

### Step 1: Add the Template Field to Your Server

In your game server's source code, append a `[template: ...]` field to the RagnaScript message:

```c
sprintf(buf, "[action: mob_item_drop][channel: %s][player_name: %s][mob_name: %s]"
    "[mob_id: %d][item_name: %s][item_id: %d][rate: %d]"
    "[account_id: %d][char_id: %d]"
    "[template: :gem: [Card Drop] %s obtained %s's %s at %s.]",
    channel_id, sd->status.name, mob_name,
    mob_id, item_name, item_id, rate,
    sd->status.account_id, sd->status.char_id,
    sd->status.name, mob_name, item_name, map_name);
```

The template field is **optional** — messages without it work exactly as before.

### Step 2: Configure the Route on Your Dashboard

1. Go to **Discord > Message Routes** on your RagnaSync dashboard
2. Find the event type (e.g., Mob Item Drops) and edit the route
3. Set the format to **Custom Message**
4. In the template editor, type: `{{src_template}}`
5. Save

### Step 3: That's It

Your Discord messages will now show whatever your server puts in the template field:

```
💎 [Card Drop] Seiya obtained Matyr's Matyr Card at Morocc Sphinx B3.
```

## Supported Script Types

The `[template: ...]` field works with these script types:

| Script Type          | Action           | Use Case                    |
| -------------------- | ---------------- | --------------------------- |
| Mob Item Drop        | `mob_item_drop`  | Item drop announcements     |
| Homunculus Item Drop | `hom_item_drop`  | Homunculus kill drops       |
| Mercenary Item Drop  | `merc_item_drop` | Mercenary kill drops        |
| Mob Death            | `mob_death`      | Boss/MVP kill announcements |
| @Command Log         | `at_command`     | GM command audit logging    |

## Mixing with Other Placeholders

You can combine `{{src_template}}` with other placeholders for hybrid messages:

```
{{src_template}} — dropped by {{mob_name}}
```

Or use `{{src_template}}` as just part of a bigger template:

```
**Server Alert** {{src_template}} ({{rate}} drop rate)
```

If your server doesn't send a template for a particular message, `{{src_template}}` resolves to an empty string — so your custom message degrades gracefully.

## Template Examples

### Card Drop Announcements

**Server-side (C):**

```c
sprintf(template, ":gem: [Card Drop] %s obtained %s's %s at %s.",
    sd->status.name, mob_name, item_name, map_name);
```

**Discord result:**

```
💎 [Card Drop] Seiya obtained Matyr's Matyr Card at Morocc Sphinx B3.
```

### Boss Kill with Party

**Server-side (C):**

```c
if (sd->status.party_id > 0) {
    sprintf(template, ":trophy: [%s] of Party [%s] killed %s at %s!",
        sd->status.name, party_name, mob_name, map_name);
} else {
    sprintf(template, ":trophy: [%s] has solo killed %s at %s!",
        sd->status.name, mob_name, map_name);
}
```

**Discord result:**

```
🏆 [xArrow] of Party [unliEDDGA] killed Eddga at Payon Forest F11!
```

### Conditional Templates by Rarity

**Server-side (C):**

```c
if (rate <= 10) {
    sprintf(template, ":tada: JACKPOT! %s got %s from %s!",
        sd->status.name, item_name, mob_name);
} else if (rate <= 100) {
    sprintf(template, ":gem: [Card Drop] %s obtained %s at %s.",
        sd->status.name, item_name, map_name);
} else {
    // No template — RagnaSync uses the dashboard format
    template[0] = '\0';
}
```

### GM Command Audit

**Server-side (C):**

```c
sprintf(template, ":small_orange_diamond: Command Log: %s | %s",
    sd->status.name, command);
```

**Dashboard template:** `{{src_template}}`

**Discord result:**

```
🔸 Command Log: AdminName | @warp prontera
```

## Using Emojis

You can use Discord emoji shortcodes in your templates — RagnaSync automatically converts them to real emoji. This works even inside code blocks where Discord normally wouldn't parse them.

| Shortcode                | Emoji | Good For     |
| ------------------------ | ----- | ------------ |
| `:gem:`                  | 💎    | Rare drops   |
| `:trophy:`               | 🏆    | Boss kills   |
| `:tada:`                 | 🎉    | Celebrations |
| `:star:`                 | ⭐     | Achievements |
| `:fire:`                 | 🔥    | Hot items    |
| `:skull:`                | 💀    | Deaths       |
| `:crossed_swords:`       | ⚔️    | Combat       |
| `:warning:`              | ⚠️    | Alerts       |
| `:small_orange_diamond:` | 🔸    | Compact logs |
| `:small_blue_diamond:`   | 🔹    | Info lines   |

## Tips

* The `[template: ...]` field should always be the **last field** in your RagnaScript packet
* Templates are **optional** — if you don't include one, the message uses whatever format is set on the dashboard route
* If a route's format is set to Log, Embed, or Narrate, the `{{src_template}}` placeholder won't be used — switch to **Custom Message** to use it
* Emoji shortcodes are case-sensitive: `:gem:` works, `:Gem:` doesn't
* Keep templates under \~2000 characters (Discord's message limit)

## Troubleshooting

**Template not showing up?**

* Make sure the route is set to **Custom Message** format on the dashboard
* Make sure the template field contains `{{src_template}}`
* Check that your server is sending the `[template: ...]` field in the RagnaScript packet

**Empty messages?**

* If `{{src_template}}` is the only thing in your custom template and the server didn't send a template field, the message will be empty. Add a fallback: `{{src_template}}{{player_name}} got {{item_name}}`

**Brackets showing wrong?**

* Player names with brackets like `[GM] Player` are fine — the parser handles this correctly as long as `[template: ...]` is the last field in the packet
