> For the complete documentation index, see [llms.txt](https://grp-development.gitbook.io/solid-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://grp-development.gitbook.io/solid-scripts/resources/solid-chat/exports-and-events/server-exports.md).

# Server exports

Exports you can call from server scripts.

#### Messages

**addMessage**

Sends a message to one player, or to every player with `-1`. Called with only a message, it goes to everyone.

```lua
---@param target integer
---@param message string|table
exports['solid-chat']:addMessage(target, message)
```

```lua
exports['solid-chat']:addMessage(-1, 'Server restart in 5 minutes.')

exports['solid-chat']:addMessage(source, {
    args = { 'Dispatch', 'Units requested at the station.' },
    tab = 'jobs',
})
```

| Field        | Type    | Description                                                                                              |
| ------------ | ------- | -------------------------------------------------------------------------------------------------------- |
| `args`       | table   | The parts of the message. With the default template, the first is the sender and the second is the text. |
| `template`   | string  | Your own HTML for this message. `{0}` and `{1}` are the args.                                            |
| `templateId` | string  | A template added with `addTemplate`.                                                                     |
| `params`     | table   | Values for your own `{name}` placeholders in the template.                                               |
| `color`      | table   | An RGB colour like `{ 255, 80, 80 }`, shown as the message's accent colour.                              |
| `multiline`  | boolean | Keeps line breaks in the text.                                                                           |
| `tab`        | string  | `all`, `local`, `jobs` or `staff`. With `staff`, only staff receive it.                                  |
| `every`      | boolean | `true` shows it in every tab, without an unread badge.                                                   |
| `senderId`   | integer | Server ID of the sender. Their own message never pings them.                                             |
| `text`       | string  | The plain text that mentions are checked in. Without it, the last arg is used.                           |

**clear**

Clears the chat of one player, or of every player with `-1`.

```lua
---@param target integer
exports['solid-chat']:clear(target)
```

#### Suggestions and templates

**addSuggestion**

Adds a command to the suggestions a player sees while typing.

```lua
---@param target integer
---@param name string
---@param help string
---@param params? table
exports['solid-chat']:addSuggestion(-1, '/report', 'Send a report to staff', {
    { name = 'message', help = 'What happened' },
})
```

**removeSuggestion**

```lua
---@param target integer
---@param name string
exports['solid-chat']:removeSuggestion(-1, '/report')
```

**addTemplate**

Adds a message template that messages can use with `templateId`.

```lua
---@param target integer
---@param id string
---@param html string
exports['solid-chat']:addTemplate(-1, 'bank', '<div class="chat-message system">{0}</div>')
```

```lua
exports['solid-chat']:addMessage(source, {
    templateId = 'bank',
    args = { 'You received $500.' },
})
```

#### Overhead text

**showOverhead**

Shows a /me or /do line above a player's head. It uses the same word filter, cooldown, range and stacking as the commands.

```lua
---@param playerId integer
---@param text string
---@param kind 'me'|'do'
---@param options? table
---@return boolean shown
---@return integer? lineId
---@return integer? duration
local shown, lineId, duration = exports['solid-chat']:showOverhead(source, 'checks the door', 'me')
```

```lua
exports['solid-chat']:showOverhead(source, 'The door is locked.', 'do', {
    duration = 6000,
})
```

`duration` is in milliseconds and stays between the minimum and maximum duration set in `/chatsetup`. Without it, the length of the text decides, the same as for the commands.

#### Hooks and modes

**registerMessageHook**

Runs your function for every public chat message before it is delivered. The function can change the message, send it to other players or stop it.

```lua
---@param fn function
---@return integer hookId
exports['solid-chat']:registerMessageHook(function(source, message, hook)
    if message.text:find('discord.gg', 1, true) then
        hook.cancel()
    end
end)
```

| Method                       | Description                                                                                                         |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `hook.updateMessage(fields)` | Changes fields of the message, like `args`, `template` or `params`. In a new template, `{}` stands for the old one. |
| `hook.cancel()`              | Stops the message.                                                                                                  |
| `hook.setRouting(target)`    | Sends it only to a player ID, or a table of IDs.                                                                    |
| `hook.setSeObject(ace)`      | Sends it only to players with this ace.                                                                             |

Hooks are removed on their own when your resource stops.

**registerMode**

Adds a chat mode players can switch to, like a team chat. Every message sent in the mode goes through your `cb` first, with the same arguments as a message hook.

```lua
---@param mode table
---@return boolean added
exports['solid-chat']:registerMode({
    name = 'team',
    displayName = 'Team',
    color = '#8049FC',
    seObject = 'team.chat',
    cb = function(source, message, hook)
        hook.setSeObject('team.chat')
    end,
})
```

| Field         | Type     | Description                                                            |
| ------------- | -------- | ---------------------------------------------------------------------- |
| `name`        | string   | Unique ID of the mode.                                                 |
| `displayName` | string   | Name players see.                                                      |
| `color`       | string   | Colour of the mode, for example `#8049FC`.                             |
| `seObject`    | string   | Ace a player needs to see and use the mode. Leave it out for everyone. |
| `cb`          | function | Runs for every message sent in the mode.                               |

**removeMode**

```lua
---@param name string
exports['solid-chat']:removeMode('team')
```

Modes are removed on their own when your resource stops.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://grp-development.gitbook.io/solid-scripts/resources/solid-chat/exports-and-events/server-exports.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
