Skip to content

Player Index

getAllPlayers(): readonly EntityPlayer[]

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

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.

readonly EntityPlayer[]


getOtherPlayers(player): readonly EntityPlayer[]

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

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

EntityPlayer

readonly EntityPlayer[]


getPlayerFromIndex(playerIndex): EntityPlayer | undefined

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

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

PlayerIndex

EntityPlayer | undefined


getPlayerIndex(player, differentiateForgottenAndSoul?): PlayerIndex

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

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.

EntityPlayer

boolean = false

PlayerIndex


getPlayerIndexVanilla(playerToFind): int | undefined

Defined in: packages/isaacscript-common/src/functions/playerIndex.ts:132

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.

EntityPlayer

int | undefined


getPlayers(performCharacterExclusions?): readonly EntityPlayer[]

Defined in: packages/isaacscript-common/src/functions/playerIndex.ts:158

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.

boolean = false

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

readonly EntityPlayer[]


getSubPlayerParent(subPlayer): EntityPlayer | undefined

Defined in: packages/isaacscript-common/src/functions/playerIndex.ts:176

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.

EntitySubPlayer

EntityPlayer | undefined


isChildPlayer(player): boolean

Defined in: packages/isaacscript-common/src/functions/playerIndex.ts:197

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.)

EntityPlayer

boolean


isFoundSoul(player): boolean

Defined in: packages/isaacscript-common/src/functions/playerIndex.ts:205

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

EntityPlayer

boolean