> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-chat-v2/compatibility.md).

# Working with other resources

Use CAS Chat V2 as a drop-in chat replacement — chat:addMessage, chatMessage, chat:clear, autocomplete suggestions and other resources' commands all work, plus how to rebuild the UI.

`rsm_rpchat` declares `provide 'chat'`, so it stands in for the default chat resource. Your other scripts keep working without any change.

## Sending a message from another resource

The standard events all land in this interface.

```lua
-- One line with a prefix
TriggerClientEvent('chat:addMessage', source, {
    args = { '^1SHOP', 'Your order is ready.' }
})

-- Everyone
TriggerClientEvent('chat:addMessage', -1, {
    args = { 'Server', 'Restart in 10 minutes.' }
})

-- With a template
TriggerClientEvent('chat:addMessage', source, {
    template = '<b>{0}</b> {1}',
    args = { 'Bank', 'Deposit received.' }
})
```

Colour codes such as `^1` and HTML tags are stripped, and the line appears in the System tab. The first argument becomes the prefix when two or more are given.

The older `chatMessage` event is supported too:

```lua
TriggerClientEvent('chatMessage', source, 'Bank', { 255, 0, 0 }, 'Deposit received.')
```

## Clearing the chat

```lua
TriggerClientEvent('chat:clear', source)
```

`chat:client:ClearChat`, which some frameworks use, works as well.

## Autocomplete

Commands your resources register show up in the `/` list automatically, with whatever help text you provide, and only for players who are allowed to use them.

```lua
TriggerClientEvent('chat:addSuggestion', source, '/report', 'Report a player', {
    { name = 'id', help = 'Server ID' },
    { name = 'reason', help = 'What happened' },
})
```

`chat:addSuggestions`, `chat:removeSuggestion` and `chat:resetSuggestions` all work. The list refreshes by itself whenever a resource starts or stops.

## Commands from other resources

A player typing `/report` in the chat window runs your command exactly as the default chat would. Commands this interface does not recognise are passed straight to the game. If the command does not exist anywhere, the player gets an unknown command notice.

## Accepted and ignored

`chat:addTemplate`, `chat:addMode` and `chat:removeMode` are accepted so that callers do not throw an error, but this interface has no themes or modes, so they do nothing.

## Known limitation

The default chat's `exports.chat:addMessage` is not provided. Use the `chat:addMessage` event shown above, which is what nearly every resource already uses.

## Rebuilding the interface

The interface is a React project under `web`. Only `web/dist` is served to players, so you only need this if you change the UI source.

```
cd web
npm install
NODE_ENV=production npx vite build --mode production
```

`NODE_ENV=production` matters. If your shell has `NODE_ENV=development` set, a plain `vite build` bundles React's development build instead, which roughly doubles the file size and ships development warnings to players.

After building, check the result:

```
ls -l dist/assets/*.js
grep -c "Each child in a list" dist/assets/*.js
```

The bundle should be around 475 KB and the grep should return 0.
