# getElementsInRange (Shared)

> Lists the elements whose position is inside a sphere.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Elements
- **URL**: https://wiki.mymp.gg/en/getElementsInRange

## Syntax

```lua
table getElementsInRange(float x, y, z, float radius [, string type = "", int interior = -1, int dimension = -1])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x, y, z` | `float` | The sphere's centre. |
| `radius` | `float` | Radius in metres. A negative number raises an error. |
| `type` | `string` | Only elements of this type. Empty takes any type. *(default: `""`)* |
| `interior` | `int` | Only elements in this interior. `-1` takes any interior. *(default: `-1`)* |
| `dimension` | `int` | Only elements in this dimension. `-1` takes any dimension. *(default: `-1`)* |

## Returns

A table with the elements found, empty if there are none.

Elements without a position never match. When filtering by interior, those without an interior are left out.

## Example

```lua
local pos = getElementPosition(localPlayer)
local nearby = getElementsInRange(pos, 30, "vehicle", 0, getElementDimension(localPlayer))
outputDebugString(#nearby .. " vehicles nearby")
```

### Coming from MTA

In MTA this function is called `getElementsWithinRange`.

## See also

- [getElementsByType (Server)](https://wiki.mymp.gg/en/getElementsByType-server.md): Lists every element of a type below an element of the tree on the server.
- [getElementPosition (Shared)](https://wiki.mymp.gg/en/getElementPosition.md): Reads an element's position in the world.
