# createSpotLight (Client)

> Creates a light that shines inside a cone, like a spotlight. The light exists on this client only.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Lights
- **URL**: https://wiki.mymp.gg/en/createSpotLight

## Syntax

```lua
light|false createSpotLight(float x, y, z, float dirX, dirY, dirZ [, float radius = 15, color color = tocolor(255, 255, 255), float cone = 30, float hardness = 0.5])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x, y, z` | `float` | The light's position in the world, three numbers or a vec3. |
| `dirX, dirY, dirZ` | `float` | Where the light points. Three numbers or a vec3, finite and non-zero; it is normalised. |
| `radius` | `float` | Range in metres, above 0 and up to 1000. *(default: `15`)* |
| `color` | `color` | Three numbers `r, g, b` (integers from 0 to 255) or a `tocolor` value. Alpha is ignored. *(default: `tocolor(255, 255, 255)`)* |
| `cone` | `float` | Half the cone's opening, in degrees from its axis, above 0 and up to 90. *(default: `30`)* |
| `hardness` | `float` | Fraction of the cone lit fully, from 0 to 1. Anything above 0.99 counts as 0.99. *(default: `0.5`)* |

## Returns

The created `light` element, or `false` if it could not be created.

Its source radius starts at 0.1 metres (or the range, if smaller); change it with `setLightSourceRadius`. A light outside the focused dimension or area is not drawn.

## Example

```lua
local pos = getElementPosition(localPlayer)
local light = createSpotLight(pos.x, pos.y, pos.z + 6, 0, 0, -1, 20, 255, 240, 200, 25, 0.7)
setLightCastShadow(light, true)
```

### Coming from MTA

MTA has no dynamic lights. To light a single frame without creating an element, use `dxDrawSpotLight`.

## See also

- [createPointLight (Client)](https://wiki.mymp.gg/en/createPointLight.md): Creates a light that shines in every direction from a point. The light exists on this client only.
- [setLightCone (Client)](https://wiki.mymp.gg/en/setLightCone.md): Changes the opening and the edge hardness of a spot light's cone.
- [setLightDirection (Client)](https://wiki.mymp.gg/en/setLightDirection.md): Changes where a spot or rect light points.
- [dxDrawSpotLight (Client)](https://wiki.mymp.gg/en/dxDrawSpotLight.md): Lights a cone for a single frame, without creating an element.
