# Component

Component is a very useful module to manage entity component. The module is designed to create a persistence of component colors if you defined a custom colorway.

## JO Variables

### `[Client]` jo.component.categoryName
Type : *table*  
> Links between the hash and name of a category.  
>> key: category hash  
>> value: category name

### `[Client]` jo.component.order
Type : *table*  
> The order to apply the component  
>> key: order to apply the component  
>> value: category name

### `[Client]` jo.component.wearableStates
Type : *table*  
> The list of available wearable state by category  
>> key: category name  
>> value: table of wearable states

## JO Functions

### `[Client]` jo.component.apply()

A function to apply a component on the ped <br>

#### Syntax

```lua
jo.component.apply(ped, category, _data)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _string|integer_
> The component category
>

`_data` : _table_

> The component data
>

> `_data.hash` : _integer_ - The component hash
> 
> `_data.palette` : _string|integer_ - The color palette of the component `[Optional]`
> 
> `_data.tint0` : _integer_ - The first color number `[Optional]`
> 
> `_data.tint1` : _integer_ - The second color number `[Optional]`
> 
> `_data.tint2` : _integer_ - The third color number `[Optional]`
> 
> `_data.drawable` : _integer_ - The drawable value `[Optional]`
> 
> `_data.albedo` : _integer_ - The albedo value `[Optional]`
> 
> `_data.normal` : _integer_ - The normal value `[Optional]`
> 
> `_data.material` : _integer_ - The material value `[Optional]`
> 

---

### `[Client]` jo.component.applyComponents()

A function to apply multiple components to a ped <br>

#### Syntax

```lua
jo.component.applyComponents(ped, components)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`components` : _table_

> Table of components indexed by category name with component data
>

---

### `[Client]` jo.component.applySkin()

A function to apply a complete skin configuration to a ped <br>

#### Syntax

```lua
jo.component.applySkin(ped, skin)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`skin` : _table_

> The skin configuration data
>

> `skin.model` : _string_ - The model name `[Optional]`
> 
> `skin.headHash` : _integer_ - The head component hash `[Optional]`
> 
> `skin.headIndex` : _integer_ - The head index for skin tone `[Optional]`
> 
> `skin.skinTone` : _integer_ - The skin tone value `[Optional]`
> 
> `skin.bodyUpperHash` : _integer_ - The upper body component hash `[Optional]`
> 
> `skin.bodyLowerHash` : _integer_ - The lower body component hash `[Optional]`
> 
> `skin.bodiesIndex` : _integer_ - The body index for skin tone `[Optional]`
> 
> `skin.bodyType` : _integer_ - The body type outfit preset `[Optional]`
> 
> `skin.bodyWeight` : _integer_ - The body weight outfit preset `[Optional]`
> 
> `skin.expressions` : _table_ - Table of expression values `[Optional]`
> 
> `skin.eyesHash` : _integer_ - The eyes component hash `[Optional]`
> 
> `skin.eyesIndex` : _integer_ - The eyes index `[Optional]`
> 
> `skin.teethHash` : _integer_ - The teeth component hash `[Optional]`
> 
> `skin.teethIndex` : _integer_ - The teeth index `[Optional]`
> 
> `skin.hair` : _table_ - Hair component data `[Optional]`
> 
> `skin.beards_complete` : _table_ - Beard component data `[Optional]`
> 
> `skin.overlays` : _table_ - Table of overlay configurations `[Optional]`
> 
> `skin.bodyScale` : _number_ - The body scale value `[Optional]`
> 

---

### `[Client]` jo.component.bootsAreUnderPant()

A function to know if the boots are under the pant <br>

#### Syntax

```lua
jo.component.bootsAreUnderPant(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if boots are under the pant, `false` otherwise.

---

### `[Client]` jo.component.collarClose()

A function to close the collar <br>

#### Syntax

```lua
jo.component.collarClose(ped, data)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`data` : _table_

> The component data, see the structure in [jo.component.apply()](#jo-component-apply)
>

---

### `[Client]` jo.component.collarIsOpened()

Return if the collar is opened <br>

#### Syntax

```lua
jo.component.collarIsOpened(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the collar is opened, `false` otherwise.

---

### `[Client]` jo.component.collarOpen()

A function to open the collar <br>

#### Syntax

```lua
jo.component.collarOpen(ped, data)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`data` : _table_

> The component data, see the structure in [jo.component.apply()](#jo-component-apply)
>

---

### `[Client]` jo.component.getBaseLayer()

A function to get the base layer of a component <br>

#### Syntax

```lua
jo.component.getBaseLayer(ped, hash, inTable)
```

#### Parameters

`ped` : _integer_
> The entity ID or the metaped type
>

`hash` : _string|integer_
> The component hash
>

`inTable` : _boolean_ `[Optional]`
> `true` to get the result as a table, `false` to get the result as separate values<br> Default: `false`
>

#### Return Value

Type : _table|integer,integer,integer,integer,integer,integer,integer,integer_

> When inTable is true: returns a table with {drawable, albedo, normal, material, palette, tint0, tint1, tint2} <br> When inTable is false: 1st: drawable <br> 2nd: albedo <br> 3rd: normal <br> 4th: material <br> 5th: palette <br> 6th: tint0 <br> 7th: tint1 <br> 8th: tint2

---

### `[Client]` jo.component.getBodiesLowerFromSkinTone()

A function to get the lower body component hash from bodies index and skin tone <br>

#### Syntax

```lua
jo.component.getBodiesLowerFromSkinTone(ped, bodiesIndex, skinTone)
```

#### Parameters

`ped` : _integer|string_
> The entity ID or model name
>

`bodiesIndex` : _integer_ `[Optional]`
> The bodies index, defaults to 1
>

`skinTone` : _integer_ `[Optional]`
> The skin tone, defaults to 1
>

#### Return Value

Type : _string_

> The lower body component hash string

---

### `[Client]` jo.component.getBodiesUpperFromSkinTone()

A function to get the upper body component hash from bodies index and skin tone <br>

#### Syntax

```lua
jo.component.getBodiesUpperFromSkinTone(ped, bodiesIndex, skinTone)
```

#### Parameters

`ped` : _integer|string_
> The entity ID or model name
>

`bodiesIndex` : _integer_ `[Optional]`
> The bodies index, defaults to 1
>

`skinTone` : _integer_ `[Optional]`
> The skin tone, defaults to 1
>

#### Return Value

Type : _string_

> The upper body component hash string

---

### `[Client]` jo.component.getCategoriesEquiped()

 <br>
 <br>
 <br>
 <br>
Return the list of component categories equiped on the ped <br>

#### Syntax

```lua
jo.component.getCategoriesEquiped(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _table_

> Return an table with the category in key and data in value <br> `categories[x].index` : integer - the index of the component on the ped <br> `categories[x].category` : string - the category name if the hash is known

---

### `[Client]` jo.component.getCategoryNameFromHash()

A function to get the category name from a hash value <br>

#### Syntax

```lua
jo.component.getCategoryNameFromHash(category)
```

#### Parameters

`category` : _integer|string_
> The category hash
>

#### Return Value

Type : _string_

> The category name, or "unknown" if not found

---

### `[Client]` jo.component.getCategoryTint()

A function to get the tints of a category <br>

#### Syntax

```lua
jo.component.getCategoryTint(ped, category, inTable)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _string|integer_
> The category of the component
>

`inTable` : _boolean_
> When inTable is `true`, returns a table with {palette, tint0, tint1, tint2} <br> When inTable is `false`, returns four separate values: palette, tint0, tint1, tint2
>

#### Return Value

Type : _table|integer,integer,integer,integer_

> When inTable is true: returns a table with {palette, tint0, tint1, tint2} <br> When inTable is false: 1st: color palette <br> 2nd: tint number 0 <br> 3rd: tint number 1 <br> 4th: tint number 2

---

### `[Client]` jo.component.getComponentCategory()

Return the category hash of a component and if it's a MP component <br>

#### Syntax

```lua
jo.component.getComponentCategory(ped, hash)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`hash` : _integer_
> The component hash
>

#### Return Value

Type : _integer,boolean_

> 1st: Return hash value of the category <br> 2nd: Return `true` if it's a MP component, `false` otherwise

---

### `[Client]` jo.component.getComponentEquiped()

A function to get the hash of the component equiped in a category <br>

#### Syntax

```lua
jo.component.getComponentEquiped(ped, category)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _string|integer_
> The category to get the component
>

#### Return Value

Type : _table_

> Return the component datas

---

### `[Client]` jo.component.getComponentsEquiped()

A function to get all components equiped <br>

#### Syntax

```lua
jo.component.getComponentsEquiped(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _table_

> Return the list of components equiped

---

### `[Client]` jo.component.getEyesFromIndex()

A function to get the eyes component hash from an index <br>

#### Syntax

```lua
jo.component.getEyesFromIndex(ped, index)
```

#### Parameters

`ped` : _integer|string_
> The entity ID or model name
>

`index` : _integer_ `[Optional]`
> The eyes index, defaults to 1
>

#### Return Value

Type : _string_

> The eyes component hash string

---

### `[Client]` jo.component.getHeadFromSkinTone()

A function to get the head component hash from head index and skin tone <br>

#### Syntax

```lua
jo.component.getHeadFromSkinTone(ped, headIndex, skinTone)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`headIndex` : _integer_ `[Optional]`
> The head index, defaults to 1
>

`skinTone` : _integer_ `[Optional]`
> The skin tone, defaults to 1
>

#### Return Value

Type : _string_

> The head component hash string

---

### `[Client]` jo.component.getPaletteNameFromHash()

 <br>
 <br>
 <br>
 <br>
A function to get the palette name from a hash value <br>

#### Syntax

```lua
jo.component.getPaletteNameFromHash(hash)
```

#### Parameters

`hash` : _integer_
> The palette hash
>

#### Return Value

Type : _string_

> The palette name, or "unknown" if not found

---

### `[Client]` jo.component.getTeethFromIndex()

A function to get the teeth component hash from an index <br>

#### Syntax

```lua
jo.component.getTeethFromIndex(ped, index)
```

#### Parameters

`ped` : _integer|string_
> The entity ID or model name
>

`index` : _integer_ `[Optional]`
> The teeth index, defaults to 1
>

#### Return Value

Type : _string_

> The teeth component hash string

---

### `[Client]` jo.component.getWearableState()

Get the wearable state of a category <br>

#### Syntax

```lua
jo.component.getWearableState(ped, category)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _string|integer_
> The category name
>

#### Return Value

Type : _integer_

> Return the wearable state hash of the category

---

### `[Client]` jo.component.getWearableStateNameFromHash()

#### Syntax

```lua
jo.component.getWearableStateNameFromHash(state)
```

---

### `[Client]` jo.component.hairIsPomade()

A function to know if the hair is pomaded <br>

#### Syntax

```lua
jo.component.hairIsPomade(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the hair is pomaded

---

### `[Client]` jo.component.isCategoryEquiped()

A function to know if a specific category is equiped on the ped <br>

#### Syntax

```lua
jo.component.isCategoryEquiped(ped, category)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _string|integer_
> The category name
>

#### Return Value

Type : _integer_

> Return the index of the category

---

### `[Client]` jo.component.isMpComponent()

A function to check if a component is an MP component (multiplayer component) <br>

#### Syntax

```lua
jo.component.isMpComponent(ped, hash)
```

#### Parameters

`ped` : _integer_
> The entity ID OR the metapedType
>

`hash` : _integer_
> The component hash
>

#### Return Value

Type : _boolean_

> Return `true` if it's an MP component, `false` otherwise

---

### `[Client]` jo.component.loadoutIsOnRight()

A function to know if the loadout is on the right <br>

#### Syntax

```lua
jo.component.loadoutIsOnRight(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the loadout in on the right, `false` otherwise

---

### `[Client]` jo.component.neckwearIsUp()

Return if the neckwear is on the face of the player or not <br>

#### Syntax

```lua
jo.component.neckwearIsUp(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the neckwear is on the face, `false` otherwise.

---

### `[Client]` jo.component.refreshPed()

 <br>
 <br>
 <br>
 <br>
A function to refresh the ped components <br>

#### Syntax

```lua
jo.component.refreshPed(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

---

### `[Client]` jo.component.remove()

A function to remove a component component <br>

#### Syntax

```lua
jo.component.remove(ped, category)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _integer|string_
> The category of component to remove
>

---

### `[Client]` jo.component.removeAllClothes()

A function to remove all clothing components from a ped <br>

#### Syntax

```lua
jo.component.removeAllClothes(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

---

### `[Client]` jo.component.setWearableState()

 <br>
 <br>
 <br>
 <br>
A function to edit the wearable state of a category <br>

#### Syntax

```lua
jo.component.setWearableState(ped, category, data, state)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`category` : _integer|string_
> The category of the component
>

`data` : _table_

> The component data, see the structure in [jo.component.apply()](#jo-component-apply)
>

`state` : _integer|string_
> The wearable state to apply on the component <br>  The list of wearable state can be find in the `jo_libs>module>component>client.lua` file `line 76`
>

---

### `[Client]` jo.component.sleeveIsRolled()

Return if the sleeve are rolled <br>

#### Syntax

```lua
jo.component.sleeveIsRolled(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the sleeve are rolled, `false` otherwise.

---

### `[Client]` jo.component.sleeveRoll()

A function to roll sleeve <br>

#### Syntax

```lua
jo.component.sleeveRoll(ped, data)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`data` : _table_

> The component data, see the structure in [jo.component.apply()](#jo-component-apply)
>

---

### `[Client]` jo.component.sleeveUnroll()

A function to unroll sleeve <br>

#### Syntax

```lua
jo.component.sleeveUnroll(ped, hash)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

`data` : _table_

> The component data, see the structure in [jo.component.apply()](#jo-component-apply)
>

---

### `[Client]` jo.component.vestIsUnderPant()

A function to know if the vest is under the pant <br>

#### Syntax

```lua
jo.component.vestIsUnderPant(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

#### Return Value

Type : _boolean_

> Return `true` if the vest is in the pant, `false` otherwise

---

### `[Client]` jo.component.waitPedLoaded()

A function to wait the refresh of ped <br>

#### Syntax

```lua
jo.component.waitPedLoaded(ped)
```

#### Parameters

`ped` : _integer_
> The entity ID
>

---

### `[Shared]` jo.component.formatComponentData()

 <br>
 <br>
 <br>
 <br>
A function to format component data <br>

#### Syntax

```lua
jo.component.formatComponentData(_data, hashData)
```

#### Parameters

`_data` : _string|number|table_
> The component data
>

`hashData` : _boolean_
> Hash the value is true
>

#### Return Value

Type : _any_

---

### `[Shared]` jo.component.getCategoryHash()

A fonction to get the category hash from its string <br>

#### Syntax

```lua
jo.component.getCategoryHash(category)
```

#### Parameters

`category` : _string|integer_
> The category string
>

#### Return Value

Type : _integer_

> The category hash

---

### `[Shared]` jo.component.getFullHorseComponentList()

A function to get the list of horse's components sorted by category <br>

#### Syntax

```lua
jo.component.getFullHorseComponentList()
```

#### Return Value

Type : _table_

---

### `[Shared]` jo.component.getFullPedComponentList()

 <br>
 <br>
A function to get the list of clothes sorted by sex and category <br>

#### Syntax

```lua
jo.component.getFullPedComponentList()
```

#### Return Value

Type : _table_
