# Entity `[Client]`

A library with useful functions to manage entity client side

## JO Functions

### jo.entity.create()

Create a new entity at specified location <br>
- if coords is a vector4, heading is not required <br>

#### Syntax

```lua
jo.entity.create(model, coords, ...)
```

#### Parameters

`model` : _string_
> The model name of the entity to create
>

`coords` : _vector3|vector4_
> The coordinates where the entity will be created
>

`heading` : _number_ `[Optional]`
> The heading direction for the entity if coords is vec3
>

`networked` : _boolean_ `[Optional]`
> Whether the entity should be networked <br> default: `false`
>

`fadeDuration` : _integer_ `[Optional]`
> Duration of the fade-in effect in ms <br> default: `0`
>

#### Return Value

Type : _integer_

> The created entity ID

---

### jo.entity.createWithMouse()

Create an entity that follows the mouse cursor for placement <br>

#### Syntax

```lua
jo.entity.createWithMouse(model, keepEntity, networked, mouse, heading)
```

#### Parameters

`model` : _string_
> The model name of the entity to create
>

`keepEntity` : _boolean_ `[Optional]`
> Whether to keep the entity after placement <br> default:true
>

`networked` : _boolean_ `[Optional]`
> Whether the entity should be networked <br> default:false
>

`mouse` : _vector2_ `[Optional]`
> Mouse coordinates normalized between 0-1 <br> default:`vec2(0.5, 0.5)`
>

`heading` : _number_ `[Optional]`
> The heading direction for the entity <br> default:0
>

#### Return Value

Type : _integer,vector3,number,boolean_

> The created entity ID, final position, final heading, is canceled

---

### jo.entity.delete()

Delete an entity if it exists <br>

#### Syntax

```lua
jo.entity.delete(entity)
```

#### Parameters

`entity` : _integer_
> The entity ID to delete
>

---

### jo.entity.deleteScenariosFromEntity()

Delete all scenarios from an entity <br>

#### Syntax

```lua
jo.entity.deleteScenariosFromEntity(entity, size, maxScenario, maxAttempt, waitTime)
```

#### Parameters

`entity` : _integer_
> The entity ID to delete scenarios from
>

`size` : _number_ `[Optional]`
> The size of the area to search for scenarios <br> default:2.0
>

`maxScenario` : _number_ `[Optional]`
> The maximum number of scenarios to search for <br> default:8
>

`maxAttempt` : _number_ `[Optional]`
> The maximum number of attempts to delete scenarios <br> default:10
>

`waitTime` : _number_ `[Optional]`
> The time to wait between attempts to delete scenarios <br> default:100
>

---

### jo.entity.fadeAndDelete()

Fade out an entity and then delete it <br>

#### Syntax

```lua
jo.entity.fadeAndDelete(entity, duration)
```

#### Parameters

`entity` : _integer_
> The entity ID to fade and delete
>

`duration` : _integer_ `[Optional]`
> Duration of the fade effect in ms <br> default:1000
>

---

### jo.entity.fadeIn()

Fade in an entity from transparent to fully visible <br>

#### Syntax

```lua
jo.entity.fadeIn(entity, duration)
```

#### Parameters

`entity` : _integer_
> The entity ID to fade in
>

`duration` : _integer_ `[Optional]`
> Duration of the fade effect in ms <br> default:1000
>

---

### jo.entity.fadeOut()

Fade out an entity from visible to transparent <br>

#### Syntax

```lua
jo.entity.fadeOut(entity, duration)
```

#### Parameters

`entity` : _integer_
> The entity ID to fade out
>

`duration` : _integer_ `[Optional]`
> Duration of the fade effect in ms - default:1000
>

---

### jo.entity.getEntityInCrosshair()

Raycast from the camera through the screen center and return what was hit <br>
Displays a small crosshair sprite at screen center <br>
Must be called each frame to render the crosshair <br>

#### Syntax

```lua
jo.entity.getEntityInCrosshair(distance, flags, toIgnore)
```

#### Parameters

`distance` : _number_ `[Optional]`
> Maximum raycast distance <br> default:`100`
>

`flags` : _integer_ `[Optional]`
> [Flags](https://docs.fivem.net/natives/?_0x7EE9F5D83DD4F90E) for the raycast <br> default:`16`
>

`toIgnore` : _integer_ `[Optional]`
> Entity to ignore in the raycast <br> default:`PlayerPedId()`
>

#### Return Value

Type : _boolean,vector3,integer_

> Hit status, hit coordinates, hit entity

---

### jo.entity.noReactions()

Make a ped totally inert: it will not react, flee, panic, ragdoll, be targeted or take damage <br>
- Useful for decorative NPCs like shopkeepers or mannequins <br>
- Does not freeze the ped: call `FreezeEntityPosition()` yourself if needed <br>

#### Syntax

```lua
jo.entity.noReactions(entity)
```

#### Parameters

`entity` : _integer_
> The ped ID to make inert
>

---

### jo.entity.requestControl()

Request control of an entity and wait until it's granted <br>

#### Syntax

```lua
jo.entity.requestControl(entity)
```

#### Parameters

`entity` : _integer_
> The entity ID to request control of
>
