# Exports & Events

HZ-CarControl exposes client exports and events to allow integration with your custom scripts.

***

## Client Exports

### isMenuOpen

Check if the CarControl menu is currently open.

```lua
local isOpen = exports['HZ-CarControl']:isMenuOpen()
```

**Return:**

* `boolean`: `true` if the menu is open, `false` otherwise

**Example:**

```lua
-- Prevent another NUI from opening if CarControl is active
if exports['HZ-CarControl']:isMenuOpen() then
    return
end
```

***

### openMenu

Open the CarControl menu programmatically.

```lua
exports['HZ-CarControl']:openMenu()
```

{% hint style="warning" %}
The player must be in a vehicle for the menu to open. If not, a notification will be shown.
{% endhint %}

**Example:**

```lua
-- Open CarControl from another script
RegisterCommand('veh', function()
    exports['HZ-CarControl']:openMenu()
end)
```

***

### closeMenu

Close the CarControl menu programmatically.

```lua
exports['HZ-CarControl']:closeMenu()
```

**Example:**

```lua
-- Close menu when entering a specific zone
AddEventHandler('myzone:entered', function()
    exports['HZ-CarControl']:closeMenu()
end)
```

***

### getCurrentVehicle

Get the current vehicle entity handle.

```lua
local vehicle = exports['HZ-CarControl']:getCurrentVehicle()
```

**Return:**

* `entity` or `nil`: Vehicle entity handle, or `nil` if no vehicle is tracked

**Example:**

```lua
local veh = exports['HZ-CarControl']:getCurrentVehicle()
if veh and DoesEntityExist(veh) then
    print('Current vehicle: ' .. GetDisplayNameFromVehicleModel(GetEntityModel(veh)))
end
```

***

### isCruiseActive

Check if cruise control is currently active.

```lua
local active = exports['HZ-CarControl']:isCruiseActive()
```

**Return:**

* `boolean`: `true` if cruise control is engaged

***

### getCruiseSpeed

Get the current cruise control speed.

```lua
local speed = exports['HZ-CarControl']:getCruiseSpeed()
```

**Return:**

* `number`: Current cruise speed in km/h (0 if inactive)

**Example:**

```lua
-- Display cruise info in a HUD
if exports['HZ-CarControl']:isCruiseActive() then
    local speed = exports['HZ-CarControl']:getCruiseSpeed()
    DrawText('CRUISE: ' .. speed .. ' km/h')
end
```

***

### isLimiterActive

Check if the speed limiter is currently active.

```lua
local active = exports['HZ-CarControl']:isLimiterActive()
```

**Return:**

* `boolean`: `true` if the speed limiter is engaged

***

### getLimiterSpeed

Get the current speed limiter value.

```lua
local speed = exports['HZ-CarControl']:getLimiterSpeed()
```

**Return:**

* `number`: Current limiter speed in km/h (0 if inactive)

***

## Events

### Server → Client

#### HZ-CarControl:openMenu

Force open the menu on a specific player.

```lua
-- Server
TriggerClientEvent('HZ-CarControl:openMenu', targetPlayerId)
```

***

#### HZ-CarControl:closeMenu

Force close the menu on a specific player.

```lua
-- Server
TriggerClientEvent('HZ-CarControl:closeMenu', targetPlayerId)
```

***

#### HZ-CarControl:notify

Send a notification to a player through the CarControl bridge.

```lua
-- Server
TriggerClientEvent('HZ-CarControl:notify', targetPlayerId, 'Message text', 'info')
```

**Parameters:**

* `message` (string): Notification text
* `type` (string): `'info'`, `'success'`, `'error'`

***

### Client → Server

#### HZ-CarControl:saveNeonColor

Triggered when a player changes a neon color (if `SaveColor` is enabled).

```lua
-- Server
RegisterNetEvent('HZ-CarControl:saveNeonColor', function(plate, r, g, b)
    local src = source
    print('Player ' .. src .. ' set neon color on plate ' .. plate)
end)
```

***

#### HZ-CarControl:logAction

Triggered on various player actions (only when `Config.Debug = true`).

```lua
-- Server
RegisterNetEvent('HZ-CarControl:logAction', function(action, data)
    local src = source
    print('Player ' .. src .. ' — ' .. action)
end)
```

***

## Integration Examples

### Disable Cruise Control in a Zone

```lua
-- Client: disable cruise when entering a no-speed zone
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1000)
        local coords = GetEntityCoords(PlayerPedId())

        if #(coords - noSpeedZone) < 50.0 then
            if exports['HZ-CarControl']:isCruiseActive() then
                exports['HZ-CarControl']:closeMenu()
                -- Cruise will auto-disengage when menu closes
            end
        end
    end
end)
```

### Display CarControl State on External HUD

```lua
-- Client: poll cruise/limiter state for a custom HUD
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(500)

        local cruiseActive = exports['HZ-CarControl']:isCruiseActive()
        local cruiseSpeed  = exports['HZ-CarControl']:getCruiseSpeed()
        local limiterActive = exports['HZ-CarControl']:isLimiterActive()
        local limiterSpeed  = exports['HZ-CarControl']:getLimiterSpeed()

        SendNUIMessage({
            action = 'updateDrivingHUD',
            cruise = cruiseActive and cruiseSpeed or nil,
            limiter = limiterActive and limiterSpeed or nil,
        })
    end
end)
```

***

{% hint style="success" %}
**Need help integrating these exports?** Join our [Discord](https://discord.gg/D2jMNswvBM) and open a ticket in #support!
{% endhint %}
