# Clothing Integration

### 🎨 Supported Clothing Scripts

| Script                 | Framework | Auto-Detected |
| ---------------------- | --------- | ------------- |
| bl\_appearance         | All       | ✅             |
| illenium-appearance    | All       | ✅             |
| fivem-appearance       | All       | ✅             |
| rcore\_clothing        | All       | ✅             |
| qb-clothing            | QBCore    | ✅             |
| skinchanger            | ESX       | ✅             |
| crm-appearance         | All       | ✅             |
| 0r-clothing (v1/v2/v3) | All       | ✅             |

***

### ⚙️ Configuration

Located in `config/config.lua`:

#### Loading Appearance

```lua
Config.ClothingExports = function(cacheped, skinData)
    -- Automatically detects and uses your clothing script
    if GetResourceState('bl_appearance') == 'started' then
        exports.bl_appearance:SetPlayerPedAppearance(skinData)
    elseif GetResourceState('illenium-appearance') == 'started' then
        exports['illenium-appearance']:setPedAppearance(cacheped, skinData)
    -- ... more scripts
    end
end
```

#### Creating New Character Appearance

```lua
Config.CreateCharacterExports = function()
    -- Opens the clothing/creator menu for new characters
    if GetResourceState('bl_appearance') == 'started' then
        exports.bl_appearance:InitialCreation(function()
            TriggerServerEvent('0r-multicharacterv3:server:changeRoutingBucket', true)
        end)
    -- ... more scripts
    end
end
```

***

### 🔧 Custom Clothing Script

If you use a clothing script not listed above, add support:

#### Step 1: Add to ClothingExports

```lua
Config.ClothingExports = function(cacheped, skinData)
    -- Add your script at the top
    if GetResourceState('my-clothing') == 'started' then
        exports['my-clothing']:setPedAppearance(cacheped, skinData)
        return
    end
    
    -- Existing scripts below...
    if GetResourceState('bl_appearance') == 'started' then
        -- ...
    end
end
```

#### Step 2: Add to CreateCharacterExports

```lua
Config.CreateCharacterExports = function()
    if GetResourceState('my-clothing') == 'started' then
        exports['my-clothing']:openCreator(function()
            TriggerServerEvent('0r-multicharacterv3:server:changeRoutingBucket', true)
        end)
        return
    end
    
    -- Existing scripts below...
end
```

#### Step 3: Add to getskin.lua (Server-side)

Edit `server/getskin.lua`:

```lua
lib.callback.register('0r-multicharacterv3:callback:getSkin', function(source, cid)
    -- Add your script
    if GetResourceState('my-clothing') == 'started' then
        local skin = exports['my-clothing']:getSkin(cid)
        if skin then
            return skin.model, skin
        end
        return nil, nil
    end
    
    -- Existing scripts below...
end)
```

***

### 📊 How Appearance Data is Stored

#### QBCore / QBox

Appearance stored in `playerskins` table:

```sql
SELECT model, skin FROM playerskins WHERE citizenid = ? AND active = 1
```

#### ESX

Appearance stored in `users` table:

```sql
SELECT skin, sex FROM users WHERE identifier = ?
```

#### bl\_appearance

Uses its own storage:

```lua
exports.bl_appearance:GetPlayerAppearance(citizenid)
```

#### rcore\_clothing

Uses its own storage:

```lua
exports.rcore_clothing:getSkinByIdentifier(citizenid)
```

***

### 🎭 Default Models

If no skin data is found, default models are used:

| Gender | Model               |
| ------ | ------------------- |
| Male   | mp\_m\_freemode\_01 |
| Female | mp\_f\_freemode\_01 |

```lua
-- In server/getskin.lua
model = (skin and skin.model) or 
        ((player.sex == 'm' or tonumber(player.sex) == 0) 
        and 'mp_m_freemode_01' 
        or 'mp_f_freemode_01')
```

***

### 📋 Complete Configuration Example

```lua
Config.ClothingExports = function(cacheped, skinData)
    if GetResourceState('rcore_clothing') == 'started' then
        exports.rcore_clothing:setPedSkin(cacheped, skinData)
    elseif GetResourceState('illenium-appearance') == 'started' then
        exports['illenium-appearance']:setPedAppearance(cacheped, skinData)
    elseif GetResourceState('bl_appearance') == 'started' then
        exports.bl_appearance:SetPlayerPedAppearance(skinData)
    elseif GetResourceState('fivem-appearance') == 'started' then
        exports['fivem-appearance']:setPedAppearance(cacheped, skinData)
    elseif GetResourceState('qb-clothing') == 'started' then
        TriggerEvent('qb-clothing:client:loadPlayerClothing', skinData, cacheped)
    elseif GetResourceState('skinchanger') == 'started' then
        exports["skinchanger"]:LoadSkin(skinData)
    elseif GetResourceState('crm-appearance') == 'started' then
        exports['crm-appearance']:crm_set_ped_appearance(cacheped, skinData)
    else
        -- Fallback or custom script
        print('No supported clothing script found!')
    end
end

Config.CreateCharacterExports = function()
    if GetResourceState('bl_appearance') == 'started' then
        exports.bl_appearance:InitialCreation(function()
            TriggerServerEvent('0r-multicharacterv3:server:changeRoutingBucket', true)
        end)
    elseif GetResourceState('qb-clothing') == 'started' then
        TriggerEvent('qb-clothes:client:CreateFirstCharacter')
    elseif GetResourceState('skinchanger') == 'started' then
        TriggerEvent('esx_skin:openSaveableMenu', function()
            TriggerServerEvent('0r-multicharacterv3:server:changeRoutingBucket', true)
        end)
    end
end
```

***

### ❓ Troubleshooting

#### Character Appears Naked/Default

1. Check if clothing script is started
2. Verify skin data exists in database
3. Check console for errors

#### Creator Doesn't Open

1. Ensure `CreateCharacterExports` is configured
2. Check if clothing script supports the event/export

#### Appearance Doesn't Save

1. This is handled by your clothing script
2. Check clothing script documentation
3. Verify database permissions
