# Entities

## Functions

### get\_entity

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

| [Parameter](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Description](broken://pages/UU4tqPUKMSAYAyywZ4hX) |
| :----------------------------------------------: | :---------------------------------------------: | :------------------------------------------------: |
|                   entity index                   |                      number                     |                entity's server index               |

#### Returns:

| [Value](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |
| :------------------------------------------: | :---------------------------------------------: |
|                entity's object               |  [entity](broken://pages/r9AdrdKuqfx1ehYTW5QN)  |

### get\_entity\_from\_handle

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

| [Parameter](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |   [Description](broken://pages/UU4tqPUKMSAYAyywZ4hX)   |
| :----------------------------------------------: | :---------------------------------------------: | :----------------------------------------------------: |
|                   entity handle                  |                      number                     | <p>a handle to the entity<br>ex: m\_hMyWeapons\[1]</p> |

#### Returns:

| [Value](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |
| :------------------------------------------: | :---------------------------------------------: |
|                entity's object               |  [entity](broken://pages/r9AdrdKuqfx1ehYTW5QN)  |

### for\_each

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

| [Parameter](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |                  [Description](broken://pages/UU4tqPUKMSAYAyywZ4hX)                 |
| :----------------------------------------------: | :---------------------------------------------: | :---------------------------------------------------------------------------------: |
|                 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](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |                  [Description](broken://pages/UU4tqPUKMSAYAyywZ4hX)                 |
| :----------------------------------------------: | :---------------------------------------------: | :---------------------------------------------------------------------------------: |
|                 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](broken://pages/UU4tqPUKMSAYAyywZ4hX) | [Datatype](broken://pages/UU4tqPUKMSAYAyywZ4hX) |                  [Description](broken://pages/UU4tqPUKMSAYAyywZ4hX)                 |
| :----------------------------------------------: | :---------------------------------------------: | :---------------------------------------------------------------------------------: |
|                 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fecality-api.gitbook.io/docs/documentation/namespaces/entities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
