# nova\_chat

NOVA Framework chat system with styled messages and built-in commands.

## Features

* **Styled Chat** — Custom NUI with message history
* **Command System** — Slash commands with server-side handling
* **Built-in Commands** — `/me`, `/ooc`, `/anuncio`, `/limpar`
* **Character Names** — Uses character first/last name when available
* **Compatibility** — Supports `chat:addMessage` (FiveM standard)

## Built-in Commands

| Command              | Description                         | Example                            |
| -------------------- | ----------------------------------- | ---------------------------------- |
| `/me [action]`       | Roleplay action (purple, no author) | `/me waves hello`                  |
| `/ooc [message]`     | Out-of-character message            | `/ooc Anyone need a ride?`         |
| `/anuncio [message]` | Server announcement (admin only)    | `/anuncio Server restart in 5 min` |
| `/limpar`            | Clear your chat messages            | `/limpar`                          |

## How to Register Commands

### Option 1: Add to chatCommands table (server/main.lua)

Edit `nova_chat/server/main.lua` and add to the `chatCommands` table:

```lua
-- Format: chatCommands['commandname'] = function(src, args, rawMessage)
chatCommands['hello'] = function(src, args)
    local name = GetPlayerName(src)
    pcall(function()
        local player = exports['nova_core']:GetPlayer(src)
        if player and player.charinfo then
            name = player.charinfo.firstname .. ' ' .. player.charinfo.lastname
        end
    end)
    exports['nova_chat']:SendMessage(-1, {
        author = name,
        message = ' says hello!',
        color = '#22c55e',
        type = 'me',
    })
end
```

### Option 2: Use RegisterCommand (FiveM native)

Commands not found in `chatCommands` are forwarded to `ExecuteCommand`. So you can use `RegisterCommand` in any resource:

```lua
-- In your script (server or client)
RegisterCommand('mycommand', function(source, args, rawCommand)
    -- Handle command
end, false)
```

When a player types `/mycommand` in the chat, it will be forwarded to this.

### Option 3: Server export to send messages

```lua
exports['nova_chat']:SendMessage(source, author, message, color)
-- source: player id or -1 for all
-- author: string (e.g. 'System')
-- message: string
-- color: hex color (e.g. '#e0e0e0')
```

## Server Export

| Export        | Parameters                             | Description            |
| ------------- | -------------------------------------- | ---------------------- |
| `SendMessage` | `source`, `author`, `message`, `color` | Send a message to chat |

## Message Types

The `type` field affects styling:

* `global` — Normal chat message
* `me` — Roleplay action (purple)
* `ooc` — Out-of-character
* `announce` — Server announcement (yellow)
* `system` — System message

## Usage Examples

### Send message from server

```lua
exports['nova_chat']:SendMessage(-1, 'System', 'Server restarting in 5 minutes.', '#facc15')
```

### Send to specific player

```lua
exports['nova_chat']:SendMessage(source, 'Admin', 'You have been warned.', '#ef4444')
```

### Compatibility with chat:addMessage

```lua
-- Standard FiveM format
TriggerClientEvent('chat:addMessage', source, {
    args = { 'Hello world' },
    color = { 255, 255, 255 },
})
```

## Configuration

Locales are in `locales.lua` (pt/en). Keys include `unknown`, `no_permission`, `announce`, `system`, `console`, `welcome`, `player`, `placeholder`.

## Notes

* Chat opens with **T** (control 245)
* Messages are limited to 500 characters
* `/anuncio` requires `nova_core:IsAdmin(source)` to be true
* Provides `chat` resource (replace default FiveM chat)

## Security

* All operations are validated server-side
* Internal event names are not disclosed in this documentation for security purposes
