Skip to main content

Player Index

Functions

getAllPlayers

getAllPlayers(): readonly EntityPlayer[]

Helper function to get every player with no restrictions, by using Game.GetNumPlayers and Isaac.GetPlayer.

This function is almost never what you want to use. For most purposes, use the getPlayers helper function instead to get a filtered list of players.

Returns

readonly EntityPlayer[]

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:25


getOtherPlayers

getOtherPlayers(player): readonly EntityPlayer[]

Helper function to get all of the other players in the room besides the one provided. (This includes "child" players.)

Parameters

NameType
playerEntityPlayer

Returns

readonly EntityPlayer[]

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:41


getPlayerFromIndex

getPlayerFromIndex(playerIndex): EntityPlayer | undefined

Helper function to get the corresponding EntityPlayer object that corresponds to a PlayerIndex.

Parameters

NameType
playerIndexPlayerIndex

Returns

EntityPlayer | undefined

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:53


getPlayerIndex

getPlayerIndex(player, differentiateForgottenAndSoul?): PlayerIndex

Mods often have to track variables relating to the player. In naive mods, information will only be stored about the first player. However, in order to be robust, mods must handle up to 4 players playing at the same time. This means that information must be stored on a map data structure. Finding a good index for these types of map data structures is difficult:

  • We cannot use the index from Isaac.GetPlayer(i) since this fails in the case where there are two players and the first player leaves the run.
  • We cannot use EntityPlayer.ControllerIndex as an index because it fails in the case of Jacob & Esau or Tainted Forgotten. It also fails in the case of a player changing their controls mid-run.
  • We cannot use EntityPlayer.GetData().index because it does not persist across saving and continuing.
  • We cannot use GetPtrHash() as an index because it does not persist across exiting and relaunching the game.
  • We cannot use EntityPlayer.InitSeed because it is not consistent with additional players beyond the first.

Instead, we use the EntityPlayer.GetCollectibleRNG method with an arbitrary value of Sad Onion (1). This works even if the player does not have any Sad Onions.

Note that by default, this returns the same index for both The Forgotten and The Soul. (Even though they are technically different characters, they share the same inventory and InitSeed.) If this is not desired, pass true for the differentiateForgottenAndSoul argument, and the RNG of Spoon Bender (3) will be used for The Soul.

Also note that this index does not work in the POST_PLAYER_INIT function for players 2 through 4. With that said, in almost all cases, you should be lazy-initializing your data structures in other callbacks, so this should not be an issue.

Parameters

NameTypeDefault value
playerEntityPlayerundefined
differentiateForgottenAndSoulbooleanfalse

Returns

PlayerIndex

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:90


getPlayerIndexVanilla

getPlayerIndexVanilla(playerToFind): int | undefined

Helper function to return the index of this player with respect to the output of the Isaac.GetPlayer method.

Note that if you storing information about a player in a data structure, you never want to use this index; use the getPlayerIndex function instead.

Parameters

NameType
playerToFindEntityPlayer

Returns

int | undefined

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:147


getPlayers

getPlayers(performCharacterExclusions?): readonly EntityPlayer[]

This function always excludes players with a non-undefined parent, since they are not real players (e.g. the Strawman Keeper).

If this is not desired, use the getAllPlayers helper function instead.

Parameters

NameTypeDefault valueDescription
performCharacterExclusionsbooleanfalseWhether to exclude characters that are not directly controlled by the player (i.e. Esau & Tainted Soul). Default is false.

Returns

readonly EntityPlayer[]

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:173


getSubPlayerParent

getSubPlayerParent(subPlayer): EntityPlayer | undefined

Helper function to get a parent EntityPlayer object for a given EntitySubPlayer object. This is useful because calling the EntityPlayer.GetSubPlayer method on a sub-player object will return undefined.

Parameters

NameType
subPlayerEntitySubPlayer

Returns

EntityPlayer | undefined

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:191


isChildPlayer

isChildPlayer(player): boolean

Helper function to detect if a particular player is a "child" player, meaning that they have a non-undefined EntityPlayer.Parent field. (For example, the Strawman Keeper.)

Parameters

NameType
playerEntityPlayer

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:212


isFoundSoul

isFoundSoul(player): boolean

Helper function to detect if a particular player is the Found Soul player provided by the trinket.

Parameters

NameType
playerEntityPlayer

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/playerIndex.ts:220