# PlayerTracker

## Summary

<table><thead><tr><th width="116">Type</th><th>Function</th></tr></thead><tbody><tr><td>Iterator</td><td><code>EntityPlayer</code> <a href="#iterplayers">IterPlayers</a>()</td></tr><tr><td>Iterator</td><td><p><code>EntityPlayer</code> <a href="#undefined">IterPlayersWithCollectible</a>(</p><p><code>CollectibleType</code> collectible, <code>boolean?</code> ignoreModifiers = false)</p></td></tr><tr><td>Function</td><td><code>string</code> <a href="#getplayerindex">GetPlayerIndex</a>(<code>player</code>)</td></tr><tr><td>Function</td><td><code>EntityPlayer[]</code> <a href="#getplayers">GetPlayers</a>()</td></tr><tr><td>Function</td><td><code>boolean</code> <a href="#hastwin">HasTwin</a>(<code>PlayerType</code> playerType)</td></tr><tr><td>Function</td><td><p><code>EntityPlayer[]</code> <a href="#getplayerswithcollectible">GetPlayersWithCollectible</a>(</p><p><code>CollectibleType</code> collectible, <code>boolean?</code> ignoreModifiers = false)</p></td></tr></tbody></table>

## Iterators

### IterPlayers()

`EntityPlayer IterPlayers()`

Returns an EntityPlayer on each iteration.

<details>

<summary>Example</summary>

{% code lineNumbers="true" %}

```lua
local PlayerTracker = IsaacHelper.GetModule("PlayerTracker")

for player in PlayerTracker.IterPlayers() do
    player:AnimateHappy() -- Makes them do a thumbs up
end
```

{% endcode %}

</details>

### IterPlayersWithCollectible()

`EntityPlayer IterPlayersWithCollectible(CollectibleType collectible, boolean? ignoreModifiers)`&#x20;

Returns an EntityPlayer that has the specified collectible on each iteration.

## Methods

### GetPlayerIndex()

`string GetPlayerIndex(EntityPlayer player)`

Returns a string that can be used to identify the player. Each player has a unique string that stays consistent throughout the run. No two players can have the same string.

### GetPlayers()

`EntityPlayer[] GetPlayers()`

Returns an array with every player.

### HasTwin()

`boolean HasTwin(PlayerType playerType)`

Checks if a player has a twin and returns true if they do. [See here](https://wofsauge.github.io/IsaacDocs/rep/EntityPlayer.html#getothertwin) for a list of characters and their twins.

{% hint style="warning" %}
Will return false for any modded character.
{% endhint %}

### GetPlayersWithCollectible()

`EntityPlayer[] GetPlayersWithCollectible(CollectibleType collectible, boolean? ignoreModifiers)`

Returns an array with every player that has a specified collectible. If no players have the collectible, the array will be empty. [See here](https://wofsauge.github.io/IsaacDocs/rep/EntityPlayer.html#hascollectible) for more information about the `ignoreModifiers` argument.

<details>

<summary>Example</summary>

{% code lineNumbers="true" %}

```lua
local PlayerTracker = IsaacHelper.GetModule("PlayerTracker")

local PlayersWithCollectible = PlayerTracker.GetPlayersWithCollectible(CollectibleType.COLLECTIBLE_SAD_ONION)
if #PlayersWithCollectible == 0 then
    print("Nobody has a Sad Onion. This make Sad Onion even sadder.")
end
```

{% endcode %}

</details>
