> For the complete documentation index, see [llms.txt](https://nayzeee-dev.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nayzeee-dev.gitbook.io/docs/nayzeee-scripts/nayzeee-ped-menu/exports.md).

# Exports

***

### Client Exports

> 💡 **Note:** This script primarily uses events for integration. However, the following functions are available globally and can be called from other client scripts.

<details>

<summary>OpenPedMenu</summary>

```lua
OpenPedMenu()
```

*Opens the ped selection menu for the local player. This is the same function called by the `/pedmenu` command.*

***

**Example:**

```lua
-- From another client script
CreateThread(function()
    -- Wait for nayzeee-pedmenu to load
    while not OpenPedMenu do
        Wait(100)
    end
    
    -- Open the menu
    OpenPedMenu()
end)
```

> ⚠️ **Note:** This function is defined globally. For cleaner integration, consider using the event instead:
>
> ```lua
> TriggerEvent('nayzeee-pedmenu:client:openMenu')
> ```

</details>

<details>

<summary>GetPedVariationsData</summary>

```lua
GetPedVariationsData()
```

*Returns a table of all available variation data for the current player ped.*

***

**Returns:** `table` - Array of variation objects

**Return Structure:**

```lua
{
    {
        id = 0,                    -- Component ID (0-11) or Prop ID (0-2)
        name = "Face",             -- Display name
        drawable = 0,              -- Current drawable index
        maxDrawable = 5,           -- Maximum drawable index
        texture = 0,               -- Current texture index
        maxTexture = 3,            -- Maximum texture index
        hasDrawables = true,       -- Has multiple drawable options
        hasTextures = true,        -- Has multiple texture options
        isProp = false             -- Is this a prop (hat, glasses, ears)
    },
    -- ... more components
}
```

***

**Example:**

```lua
-- Get all variations for current ped
local variations = GetPedVariationsData()

for _, v in ipairs(variations) do
    print(v.name .. ': ' .. v.drawable .. '/' .. v.maxDrawable)
end
```

</details>

<details>

<summary>SetPedVariation</summary>

```lua
SetPedVariation(componentId, drawable, texture, isProp)
```

*Sets a specific variation (drawable/texture) on the player's current ped.*

***

**Parameters:**

| Parameter     | Type    | Description                                     |
| ------------- | ------- | ----------------------------------------------- |
| `componentId` | number  | Component ID (0-11) or Prop ID (0-2)            |
| `drawable`    | number  | Drawable index to set                           |
| `texture`     | number  | Texture index to set                            |
| `isProp`      | boolean | `true` if setting a prop, `false` for component |

***

**Returns:** `table` - Updated variation data

**Return Structure:**

```lua
{
    drawable = 1,       -- Applied drawable index
    maxDrawable = 5,    -- Maximum drawable index
    texture = 0,        -- Applied texture index
    maxTexture = 3      -- Maximum texture index
}
```

***

**Example:**

```lua
-- Change torso (component 3) to drawable 2, texture 1
local result = SetPedVariation(3, 2, 1, false)
print('Applied drawable: ' .. result.drawable)

-- Change hat (prop 0) to drawable 1, texture 0
local result = SetPedVariation(0, 1, 0, true)
```

</details>

***

### Server Exports

> 💡 **Note:** Server-side functionality is primarily handled through events and database operations. Direct exports are not currently exposed, but you can interact with the system using the following methods.

#### Database Integration

The script stores ped data in the `players_peds` table:

```sql
SELECT * FROM players_peds WHERE identifier = ?
```

**Table Structure:**

| Column       | Type        | Description                   |
| ------------ | ----------- | ----------------------------- |
| `identifier` | VARCHAR(50) | Player identifier             |
| `list`       | LONGTEXT    | JSON array of ped model names |
| `favorite`   | VARCHAR(50) | Favorite ped model name       |

***

#### Adding Peds via Database

You can add peds directly to a player's list via SQL:

```sql
-- Add new player with peds
INSERT INTO players_peds (identifier, list, favorite) 
VALUES ('char1:abc123', '["a_m_y_hipster_01","s_m_y_cop_01"]', 'a_m_y_hipster_01');

-- Update existing player's ped list
UPDATE players_peds 
SET list = '["a_m_y_hipster_01","s_m_y_cop_01","s_m_m_paramedic_01"]' 
WHERE identifier = 'char1:abc123';

-- Set favorite ped
UPDATE players_peds 
SET favorite = 's_m_y_cop_01' 
WHERE identifier = 'char1:abc123';
```

***

### Integration Examples

#### Opening Menu from Target System (ox\_target/qb-target)

```lua
-- ox_target example
exports.ox_target:addGlobeZone({
    coords = vec3(100.0, 200.0, 30.0),
    radius = 2.0,
    options = {
        {
            name = 'open_pedmenu',
            label = 'Open Ped Menu',
            icon = 'fa-solid fa-user',
            onSelect = function()
                TriggerEvent('nayzeee-pedmenu:client:openMenu')
            end
        }
    }
})
```

#### Opening Menu from NPC Interaction

```lua
-- When player interacts with NPC
RegisterNetEvent('your-script:openPedShop', function()
    TriggerEvent('nayzeee-pedmenu:client:openMenu')
end)
```

#### Giving Ped from Job Script

```lua
-- Server-side: Give ped when player gets hired
RegisterNetEvent('your-jobs:hired', function(playerId, jobName)
    local src = source
    
    if jobName == 'police' then
        -- Use the admin command logic
        ExecuteCommand('giveplayerped ' .. playerId .. ' s_m_y_cop_01')
    end
end)
```

#### Checking Player's Current Ped Model

```lua
-- Client-side: Check if player is using a custom ped
CreateThread(function()
    while true do
        Wait(1000)
        local ped = PlayerPedId()
        local model = GetEntityModel(ped)
        
        -- Compare with known ped hashes
        if model == GetHashKey('s_m_y_cop_01') then
            print('Player is using cop ped')
        end
    end
end)
```
