> For the complete documentation index, see [llms.txt](https://docs.redutzu.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redutzu.com/resources/redutzu-mdt/exports-events/server-exports/incidents.md).

# Incidents

Here, you'll find key exports for managing incidents. These exports allow you to create, update, and delete incidents as needed.

***

## Type

<pre class="language-typescript"><code class="lang-typescript"><strong>type Incident = {
</strong>    id: number,
    name: string,
    description: string, // stringified JSON
    vehicles: string[],
    evidences: number[],
    players: {
        identifier: string,
        name: string
    }[],
    victims: {
        identifier: string,
        name: string
    }[],
    cops: {
        identifier: string,
        name: string
    }[],
    charges: {
        list: { id: number, name: string }[],
        reduction: {
            fine: 50,
            jail: 70
        },
        amount: {
            fine: 15000,
            jail: 60
        }
    },
    createdAt: string
}
</code></pre>

***

## Exports

### Search for an incident

<pre class="language-lua"><code class="lang-lua"><strong>-- It returns the incident data
</strong><strong>exports['redutzu-mdt']:SearchIncident(id)
</strong></code></pre>

```lua
local incident = exports['redutzu-mdt']:SearchIncident(1)
print(incident.name)
```

***

### Create an incident

```lua
-- It returns the id of the created incident
exports['redutzu-mdt']:CreateIncident(data, sender)
```

```lua
RegisterCommand('createIncident', function(source)
    exports['redutzu-mdt']:CreateIncident({
        name = 'Incident Name',
        description = '[]',
        players = { 'identifier' },
        victims = { 'identifier' },
        cops = { 'identifier' },
        vehicles = { 'plate' },
        evidences = { 1, 5 },
        charges = {
            list = { 2, 4, 8 },
            amount = { fine = 15000, jail = 50 },
            reduction = { fine = 35, jail = 80 }
        }
    }, source)
end, false)
```

***

### Update an incident

<pre class="language-lua"><code class="lang-lua"><strong>-- It returns a boolean (if it was successfully updated)
</strong>exports['redutzu-mdt']:UpdateIncident(id, data)
</code></pre>

```lua
local success = exports['redutzu-mdt']:UpdateIncident(1, {
    name = 'Updated Incident',
    vehicles = { 'XYZ987' }
})

if not success then
    print('There was an error updating the incident')
    return
end

print('Incident updated')
```

***

### Delete an incident

```lua
-- It returns a boolean (if it was successfully deleted)
exports['redutzu-mdt']:DeleteIncident(id)
```

```lua
local success = exports['redutzu-mdt']:DeleteIncident(1)

if not success then
    print('There was an error deleting the incident')
    return
end

print('Incident deleted')
```
