> ## Documentation Index
> Fetch the complete documentation index at: https://mythicframework.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment Variables

> Configure environment-specific settings for development and production

Mythic Framework uses FiveM convars to control server behavior. The two key convars that affect environment behavior are `sv_environment` and `log_level`.

## Setting the Environment

```bash theme={null}
# server.cfg
set sv_environment "prod"
```

**Valid Values:**

* `dev` — Development mode (verbose logging, relaxed security)
* `prod` — Production mode (optimized performance, minimal logging)

<Warning>
  **Important:** Always set this to `"prod"` before launching your live server. Development mode has performance impacts and verbose logging.
</Warning>

## Environment Behavior

<CardGroup cols={2}>
  <Card title="Development (dev)" icon="code">
    * Verbose console logging
    * Detailed error messages
    * Relaxed security checks
    * Useful for debugging
  </Card>

  <Card title="Production (prod)" icon="rocket">
    * Minimal logging (errors only)
    * Optimized performance
    * Full security features active
    * Anti-cheat enabled
  </Card>
</CardGroup>

## Log Level

The `log_level` convar controls logging verbosity. It uses a **numeric** value:

```bash theme={null}
# server.cfg
setr log_level 0
```

| Value | Description     | Use Case         |
| ----- | --------------- | ---------------- |
| `0`   | Minimal logging | Production       |
| `1`   | Basic logging   | Light debugging  |
| `2`   | Verbose logging | Active debugging |
| `3+`  | Very verbose    | Deep debugging   |

<Note>
  Higher values produce more verbose output. Use `0` in production, increase when troubleshooting issues.
</Note>

## All Framework Convars

Here is a complete reference of convars used by Mythic Framework:

### Core Settings

| Convar           | Type   | Default   | Description                              |
| ---------------- | ------ | --------- | ---------------------------------------- |
| `sv_environment` | `set`  | `"prod"`  | Environment mode (`dev` or `prod`)       |
| `log_level`      | `setr` | `0`       | Logging verbosity (numeric, 0 = minimal) |
| `sv_access_role` | `set`  | `0`       | Access role level                        |
| `mfw_version`    | `setr` | `"1.0.0"` | Framework version identifier             |
| `discord_app`    | `setr` | —         | Discord application ID (rich presence)   |

### Database Convars

| Convar                     | Type  | Description                              |
| -------------------------- | ----- | ---------------------------------------- |
| `mongodb_auth_url`         | `set` | MongoDB Auth DB connection string        |
| `mongodb_auth_database`    | `set` | MongoDB Auth DB name (typically `auth`)  |
| `mongodb_game_url`         | `set` | MongoDB Game DB connection string        |
| `mongodb_game_database`    | `set` | MongoDB Game DB name (typically `fivem`) |
| `mysql_connection_string`  | `set` | MySQL connection string for oxmysql      |
| `mysql_slow_query_warning` | `set` | Slow query warning threshold in ms       |

### Discord Webhook Convars

| Convar                       | Description                             |
| ---------------------------- | --------------------------------------- |
| `discord_admin_webhook`      | Admin action logging                    |
| `discord_connection_webhook` | Player connection/disconnection logging |
| `discord_log_webhook`        | General logging                         |
| `discord_kill_webhook`       | Kill/death logging                      |
| `discord_error_webhook`      | Error and crash logging                 |
| `discord_pwnzor_webhook`     | Anti-cheat detection logging            |

### External Service Convars

| Convar                     | Description                                            |
| -------------------------- | ------------------------------------------------------ |
| `FIVEMANAGE_MEDIA_API_KEY` | FiveManage API key for image uploads (gallery, photos) |

### Network / FiveM Convars

| Convar                | Description                 |
| --------------------- | --------------------------- |
| `sv_hostname`         | Server name in browser      |
| `sv_maxclients`       | Maximum player count        |
| `sv_enforceGameBuild` | Required game build version |
| `sv_licenseKey`       | FiveM license key           |
| `steam_webApiKey`     | Steam Web API key           |
| `onesync`             | OneSync mode (must be `on`) |

## Reading Convars in Code

### Lua (Server or Client)

```lua theme={null}
-- Get the environment
local env = GetConvar('sv_environment', 'prod')

if env == 'dev' then
    print('[DEV] Development mode active')
end

-- Get log level (numeric)
local logLevel = tonumber(GetConvar('log_level', '0')) or 0

-- Get a string convar
local fivemanageKey = GetConvar('FIVEMANAGE_MEDIA_API_KEY', '')
```

### Important: Convar Type Handling

Convars always return **strings**. Convert as needed:

```lua theme={null}
-- Boolean-like convars: compare strings
local isDev = GetConvar('sv_environment', 'prod') == 'dev'

-- Numeric convars: use tonumber
local logLevel = tonumber(GetConvar('log_level', '0')) or 0

-- With validation
local maxSlots = tonumber(GetConvar('inventory_max_slots', '50')) or 50
```

## Custom Convars

You can define your own convars in `server.cfg` for resource-specific configuration:

```bash theme={null}
# server.cfg — custom settings
set my_feature_enabled "true"
set my_api_key "your_key_here"
set my_custom_rate "1.5"
```

```lua theme={null}
-- Read in your resource
local featureEnabled = GetConvar('my_feature_enabled', 'false') == 'true'
local apiKey = GetConvar('my_api_key', '')
local rate = tonumber(GetConvar('my_custom_rate', '1.0')) or 1.0
```

<Note>
  Use `set` for convars that should only be readable server-side. Use `setr` for convars that should also be readable on the client via `GetConvar`.
</Note>

## Complete server.cfg Reference

```bash theme={null}
# === ENVIRONMENT ===
set sv_environment "prod"
set sv_access_role 0
setr log_level 0
setr mfw_version "1.0.0"
setr discord_app "your_discord_app_id"

# === DATABASE ===
set mongodb_auth_url "mongodb://localhost:27017/?readPreference=primary&ssl=false"
set mongodb_auth_database "auth"
set mongodb_game_url "mongodb://localhost:27017/?readPreference=primary&ssl=false"
set mongodb_game_database "fivem"
set mysql_connection_string "mysql://root@localhost/MythicFramework?charset=utf8mb4"
set mysql_slow_query_warning 300

# === DISCORD WEBHOOKS ===
set discord_admin_webhook ""
set discord_connection_webhook ""
set discord_log_webhook ""
set discord_kill_webhook ""
set discord_error_webhook ""
set discord_pwnzor_webhook ""

# === EXTERNAL SERVICES ===
set FIVEMANAGE_MEDIA_API_KEY "your_fivemanage_key"

# === ONESYNC ===
set onesync on
set onesync_enabled true
set onesync_population true
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Convar Returns Empty String" icon="magnifying-glass">
    **Problem:** `GetConvar` returns empty or default value

    **Solutions:**

    1. Verify the convar is set in server.cfg with `set` keyword:
       ```bash theme={null}
       set my_variable "value"
       ```
    2. Check for typos in the convar name
    3. Ensure server was restarted after changing server.cfg
    4. Always provide a default fallback:
       ```lua theme={null}
       local value = GetConvar('my_variable', 'default_value')
       ```
  </Accordion>

  <Accordion title="Boolean Convars Always True" icon="toggle-on">
    **Problem:** Boolean check always evaluates to true

    **Cause:** `GetConvar` returns strings, and any non-empty string is truthy in Lua

    **Solution:**

    ```lua theme={null}
    -- Wrong: always true (non-empty string)
    local debug = GetConvar('sv_environment', 'prod')
    if debug then end  -- always enters

    -- Correct: compare the string value
    local isDev = GetConvar('sv_environment', 'prod') == 'dev'
    if isDev then end  -- only enters when actually "dev"
    ```
  </Accordion>

  <Accordion title="Numeric Convars" icon="hashtag">
    **Problem:** Math operations fail on convar values

    **Solution:**

    ```lua theme={null}
    -- Wrong: string, not number
    local level = GetConvar('log_level', '0')
    local doubled = level * 2  -- error

    -- Correct: convert to number
    local level = tonumber(GetConvar('log_level', '0')) or 0
    local doubled = level * 2  -- works
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Server Configuration" icon="server" href="/configuration/server-cfg">
    Complete server.cfg guide
  </Card>

  <Card title="Database Connections" icon="database" href="/configuration/database-connections">
    Configure database connection strings
  </Card>

  <Card title="Discord Webhooks" icon="discord" href="/configuration/discord-webhooks">
    Set up webhook logging
  </Card>

  <Card title="Resource Management" icon="boxes-stacked" href="/configuration/resource-management">
    Resource load order and dependencies
  </Card>
</CardGroup>
