# Exports

## PHud - Exports Documentation

This document lists all available exports for PHud and how to use them in your other scripts.

### Table of Contents

* HUD Control
* Minimap
* Seatbelt
* Money
* Voice
* Radio
* Status
* Settings

***

### HUD Control

#### ToggleHUD

Show or hide the complete HUD.

**Usage:**

```lua
-- Hide the HUD
exports['PHud']:ToggleHUD(false)

-- Show the HUD
exports['PHud']:ToggleHUD(true)
```

**Parameters:**

* `state` (boolean): `true` to show, `false` to hide

**Usage Examples:**

```lua
-- During a cutscene
exports['PHud']:ToggleHUD(false)
Wait(5000)
exports['PHud']:ToggleHUD(true)

-- During a special event
RegisterNetEvent('myserver:startCutscene', function()
    exports['PHud']:ToggleHUD(false)
end)

RegisterNetEvent('myserver:endCutscene', function()
    exports['PHud']:ToggleHUD(true)
end)
```

#### IsHUDVisible

Check if the HUD is currently visible.

**Usage:**

```lua
local isVisible = exports['PHud']:IsHUDVisible()
if isVisible then
    print("HUD is visible")
end
```

**Returns:**

* `boolean`: `true` if visible, `false` if hidden

***

### Minimap

#### ToggleMinimap

Show or hide the minimap.

**Usage:**

```lua
-- Hide the minimap
exports['PHud']:ToggleMinimap(false)

-- Show the minimap
exports['PHud']:ToggleMinimap(true)
```

**Parameters:**

* `state` (boolean): `true` to show, `false` to hide

***

### Seatbelt

#### SetSeatbelt / seatbelt

Enable or disable the seatbelt.

**Usage:**

```lua
-- Put on seatbelt
exports['PHud']:SetSeatbelt(true)

-- Remove seatbelt
exports['PHud']:SetSeatbelt(false)

-- Alias (works the same way)
exports['PHud']:seatbelt(true)
```

**Parameters:**

* `state` (boolean): `true` to fasten, `false` to unfasten

#### GetSeatbelt

Check if the seatbelt is fastened.

**Usage:**

```lua
local isBeltOn = exports['PHud']:GetSeatbelt()
if isBeltOn then
    print("Seatbelt is fastened")
end
```

**Returns:**

* `boolean`: `true` if fastened, `false` otherwise

***

### Money

#### SetMoney

Update the display of cash and bank money.

**Usage:**

```lua
-- Update money
exports['PHud']:SetMoney(5000, 25000)
```

**Parameters:**

* `cash` (number): Cash amount
* `bank` (number): Bank amount

**Example:**

```lua
RegisterNetEvent('banking:updateMoney', function(cash, bank)
    exports['PHud']:SetMoney(cash, bank)
end)
```

***

### Voice

#### UpdateVoiceRange

Update voice range (whisper/normal/shout).

**Usage:**

```lua
-- Whisper
exports['PHud']:UpdateVoiceRange(1)

-- Normal
exports['PHud']:UpdateVoiceRange(2)

-- Shout
exports['PHud']:UpdateVoiceRange(3)
```

**Parameters:**

* `range` (number): 1 = whisper, 2 = normal, 3 = shout

#### UpdateTalking

Update talking state (speaking or not).

**Usage:**

```lua
-- Player is talking
exports['PHud']:UpdateTalking(true)

-- Player stopped talking
exports['PHud']:UpdateTalking(false)
```

**Parameters:**

* `talking` (boolean): `true` if talking, `false` otherwise

#### UpdateVoice

Update both voice range AND talking state at once.

**Usage:**

```lua
-- Normal range, talking
exports['PHud']:UpdateVoice(2, true)

-- Shout range, not talking
exports['PHud']:UpdateVoice(3, false)
```

**Parameters:**

* `range` (number): 1 = whisper, 2 = normal, 3 = shout
* `talking` (boolean): `true` if talking, `false` otherwise

**Example with pma-voice:**

```lua
-- In your voice script
AddEventHandler('pma-voice:setTalkingMode', function(mode)
    exports['PHud']:UpdateVoiceRange(mode)
end)

local voiceTarget = LocalPlayer.state['proximity']
CreateThread(function()
    while true do
        local newVoiceTarget = LocalPlayer.state['proximity']
        if newVoiceTarget ~= voiceTarget then
            voiceTarget = newVoiceTarget
            exports['PHud']:UpdateVoiceRange(voiceTarget.index)
        end
        Wait(100)
    end
end)
```

***

### Radio

#### SetRadioFrequency / UpdateRadio

Update the displayed radio frequency.

**Usage:**

```lua
-- Set frequency to 123.4
exports['PHud']:SetRadioFrequency(123.4)

-- Alias (works the same way)
exports['PHud']:UpdateRadio(123.4)

-- Disable radio (set to 0)
exports['PHud']:SetRadioFrequency(0.0)
```

**Parameters:**

* `frequency` (number): Radio frequency (0.0 = disabled)

**Example with pma-voice:**

```lua
AddEventHandler('pma-voice:radioActive', function(radioActive)
    if radioActive then
        local frequency = exports['pma-voice']:getRadioChannel()
        exports['PHud']:UpdateRadio(frequency)
    else
        exports['PHud']:UpdateRadio(0.0)
    end
end)
```

***

### Status

#### SetStress

Update player's stress level.

**Usage:**

```lua
-- Stress at 50%
exports['PHud']:SetStress(50)

-- No stress
exports['PHud']:SetStress(0)

-- Maximum stress
exports['PHud']:SetStress(100)
```

**Parameters:**

* `value` (number): Stress level from 0 to 100

#### SetDead

Indicate if the player is dead (shows an overlay).

**Usage:**

```lua
-- Player is dead
exports['PHud']:SetDead(true)

-- Player is alive
exports['PHud']:SetDead(false)
```

**Parameters:**

* `state` (boolean): `true` if dead, `false` if alive

**Example:**

```lua
AddEventHandler('esx:onPlayerDeath', function()
    exports['PHud']:SetDead(true)
end)

AddEventHandler('esx:onPlayerSpawn', function()
    exports['PHud']:SetDead(false)
end)
```

***

### Settings

#### OpenSettings

Open the HUD settings menu.

**Usage:**

```lua
exports['PHud']:OpenSettings()
```

**Example with command:**

```lua
RegisterCommand('hudsettings', function()
    exports['PHud']:OpenSettings()
end, false)
```

***

### Complete Examples

#### Example 1: ESX Integration

```lua
-- Money update
RegisterNetEvent('esx:setAccountMoney', function(account)
    if account.name == 'money' then
        local xPlayer = ESX.GetPlayerData()
        local cash = account.money
        local bank = xPlayer.accounts[2].money
        exports['PHud']:SetMoney(cash, bank)
    end
end)

-- Death management
AddEventHandler('esx:onPlayerDeath', function()
    exports['PHud']:SetDead(true)
end)

AddEventHandler('esx:onPlayerSpawn', function()
    exports['PHud']:SetDead(false)
end)
```

#### Example 2: Custom Seatbelt System

```lua
local seatbeltOn = false
local lastVehicle = nil

CreateThread(function()
    while true do
        local ped = PlayerPedId()
        local vehicle = GetVehiclePedIsIn(ped, false)

        if vehicle ~= 0 and vehicle ~= lastVehicle then
            lastVehicle = vehicle
            seatbeltOn = false
            exports['PHud']:SetSeatbelt(false)
        end

        Wait(500)
    end
end)

RegisterCommand('seatbelt', function()
    local ped = PlayerPedId()
    if IsPedInAnyVehicle(ped, false) then
        seatbeltOn = not seatbeltOn
        exports['PHud']:SetSeatbelt(seatbeltOn)

        if seatbeltOn then
            TriggerEvent('chat:addMessage', { args = { 'Seatbelt fastened' } })
        else
            TriggerEvent('chat:addMessage', { args = { 'Seatbelt unfastened' } })
        end
    end
end, false)

RegisterKeyMapping('seatbelt', 'Toggle Seatbelt', 'keyboard', 'B')
```

#### Example 3: Hide HUD During Cutscene

```lua
RegisterNetEvent('myserver:startHeist', function()
    -- Hide HUD during briefing
    exports['PHud']:ToggleHUD(false)

    -- Show your cutscene
    -- ...

    Wait(10000) -- 10 seconds

    -- Show HUD again
    exports['PHud']:ToggleHUD(true)
end)
```

#### Example 4: Complete Radio Integration

```lua
local radioChannel = 0.0

RegisterNetEvent('radio:onChannelChange', function(channel)
    radioChannel = channel
    exports['PHud']:UpdateRadio(channel)
end)

RegisterNetEvent('radio:onRadioClose', function()
    radioChannel = 0.0
    exports['PHud']:UpdateRadio(0.0)
end)
```

***

### Important Notes

1. **Client-side only**: All these exports are client-side. Do not call them from the server.
2. **Resource check**: If you're not sure PHud is started, check before calling:

```lua
if GetResourceState('PHud') == 'started' then
    exports['PHud']:ToggleHUD(false)
end
```

3. **Default values**: If you pass an invalid value, the HUD will use its last known value.
4. **Performance**: These exports are optimized and can be called frequently without major performance impact.

***

### Support

If you encounter any issues or have questions about using the exports, check the complete documentation in the `editable/` folder for more integration examples.
