# API

## Client side

### Before shop opens

```lua
AddEventHandler('rcore_clothing:onClothingShopOpened', function()
    -- do something before shop opens
end)
```

### After shop closes

```lua
AddEventHandler('rcore_clothing:onClothingShopClosed', function()
    -- do something after shop closes
end)
```

### Called when player's skin is loaded (on spawn or after /reloadskin)

```lua
AddEventHandler('rcore_clothing:afterSkinLoaded', function()
    -- do something after skin is loaded    
end)
```

### After character creator is finished

```lua
AddEventHandler('rcore_clothing:charcreator:done', function()
    -- do something after character creator is finished
end)
```

### Before/after decorations clear

* Should not be required, whenever clothing removes decorations, it keeps non-clothing related ones

### Reapply clothing decorations

```lua
TriggerEvent('rcore_clothing:reapplyDecorations')
```

### Reload player skin

```lua
TriggerServerEvent('rcore_clothing:reloadSkin')
```

### Save current skin

```lua
TriggerEvent('rcore_clothing:saveCurrentSkin')
```

### Open changing room

Shows player's purchased clothes and saved outfits.

```lua
TriggerEvent('rcore_clothing:openChangingRoom')
```

### Open clothing with everything available, for free

For admins primarily.

```lua
TriggerEvent('rcore_clothing:openClothingShopWithEverythingAndFree')
```

### After purchasing an item

{% hint style="warning" %}
Our script does not and will not support clothing as items.

This event is not supposed to help with it, nor help with creating an integration for it. Do not use it for that purpose.
{% endhint %}

```lua
AddEventHandler('rcore_clothing:onItemPurchase', function(componentId, drawableId, textureId, label)
    print('Purchased item: ' .. componentId .. ' ' .. drawableId .. ' ' .. textureId .. ' ' .. label)
end)
```

### Open clothing shop

Opens a clothing shop for the player.

* `shopType` - required, type of the shop, you can open shops defined in config, like `binco`, or write any other type
* `shopConfig` - optional, table with shop configuration, see [Shop configs](https://documentation.rcore.cz/paid-resources/rcore_clothing/configs/shop_configs) documentation

```lua
TriggerEvent('rcore_clothing:openShop', shopType, shopConfig)
```

### Open job changing room

Opens a job changing room for the player.

* ⚠️ The job changing room will not have any outfits unless someone permitted to will create them using the [outfit editor](https://documentation.rcore.cz/paid-resources/admin/modes#outfit-editor).
* `jobName` - required, name of the job, like `police`, `ambulance`, etc.
* `shopConfig` - optional, table with shop configuration, see [Shop configs](https://documentation.rcore.cz/paid-resources/rcore_clothing/configs/shop_configs) documentation

```lua
TriggerEvent('rcore_clothing:openJobChangingRoom', jobName, shopConfig)
```

### Exports

#### Get skin by identifier

```lua
local skin = exports["rcore_clothing"]:getSkinByIdentifier(identifier)
```

#### Get current player skin

* `includeCharacter` - if true, returns character data as well (face, hair, etc.), if false, returns only clothing data

```lua
local skin = exports['rcore_clothing']:getPlayerSkin(includeCharacter)
```

#### Set player skin

* `forceReload` - if true, players ped will be reloaded (respawned)

```lua
exports['rcore_clothing']:setPlayerSkin(skin, forceReload)
```

#### Set ped skin

```lua
exports['rcore_clothing']:setPedSkin(ped, skin)
```

#### Fix clipping or wrong arms

This export will attempt to set correct arms for the current top player is wearing.

It is not 100% accurate, but it should fix most of the issues.

```lua
exports['rcore_clothing']:fixArms()
```

#### Get player clothing (without character features)

Unlike the getters for player skin above, this one will return only clothing data, without character features (face, hair, etc.).

The return value can then be passed to `setPedSkin`.

```lua
local playerClothing = exports['rcore_clothing']:getPlayerClothing()
```

## Server side

### Exports

#### Get skin by identifier

```lua
local skin = exports["rcore_clothing"]:getSkinByIdentifier(identifier)
```
