> For the complete documentation index, see [llms.txt](https://golua.fatality.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://golua.fatality.win/documentation/namespaces/entities.md).

# Entities

entities namespace

## Functions

### get\_entity

```lua
entities.get_entity(engine.get_local_player())
```

| [Parameter](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) | [Description](/documentation/namespaces/entities.md) |
| :------------------------------------------------: | :-----------------------------------------------: | :--------------------------------------------------: |
|                    entity index                    |                       number                      |                 entity's server index                |

#### Returns:

| [Value](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |
| :--------------------------------------------: | :-----------------------------------------------: |
|                 entity's object                |    [entity](/documentation/datatypes/entity.md)   |

### get\_entity\_from\_handle

```lua
entities.get_entity_from_handle(local_player:get_prop("m_hMyWeapons", 1))
```

| [Parameter](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |  [Description](/documentation/namespaces/entities.md)  |
| :------------------------------------------------: | :-----------------------------------------------: | :----------------------------------------------------: |
|                    entity handle                   |                       number                      | <p>a handle to the entity<br>ex: m\_hMyWeapons\[1]</p> |

#### Returns:

| [Value](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |
| :--------------------------------------------: | :-----------------------------------------------: |
|                 entity's object                |    [entity](/documentation/datatypes/entity.md)   |

### for\_each

```lua
entities.for_each(function(entity)
    print(string.format("Entity's index: %i", entity:get_index()))
end)
```

| [Parameter](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |                 [Description](/documentation/namespaces/entities.md)                |
| :------------------------------------------------: | :-----------------------------------------------: | :---------------------------------------------------------------------------------: |
|                  function callback                 |                      function                     | <p>A function to use as a callback. </p><p>Must have 1 argument for the entity.</p> |

#### Usage:

Runs for each entity on the server.

### for\_each\_z

```lua
entities.for_each_z(function(entity)
    print(string.format("Entity's index: %i", entity:get_index()))
end)
```

| [Parameter](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |                 [Description](/documentation/namespaces/entities.md)                |
| :------------------------------------------------: | :-----------------------------------------------: | :---------------------------------------------------------------------------------: |
|                  function callback                 |                      function                     | <p>A function to use as a callback. </p><p>Must have 1 argument for the entity.</p> |

#### Usage:

Runs for each entity on the server starting from the end.

### for\_each\_player

```lua
entities.for_each_player(function(player)
    print(string.format("Player: %i has %i health", 
    player:get_index(), 
    player:get_prop("m_iHealth")))
end)
```

| [Parameter](/documentation/namespaces/entities.md) | [Datatype](/documentation/namespaces/entities.md) |                 [Description](/documentation/namespaces/entities.md)                |
| :------------------------------------------------: | :-----------------------------------------------: | :---------------------------------------------------------------------------------: |
|                  function callback                 |                      function                     | <p>A function to use as a callback. </p><p>Must have 1 argument for the player.</p> |

#### Usage:

Runs for each player on the server.
