PlayerCount

From ZDoom Wiki

Jump to: navigation, search

int PlayerCount (void)

Usage

Returns the number of players currently in the game. For single-player games, this will always be 1. For multi-player games, it can also return 1 when all but one of the players has quit the game.

Examples

A common issue is how to check if all players have entered a certain area. That is, if the number of players that have entered the area is equal to PlayerCount().

Using 'Actor enters sector' and 'Actor leaves sector' things it is possible to implement a primitive counter.

int count = 0;

// Use for Actor enters sector
script 10 (void)
{
	count++;
}

// Use for Actor leaves sector
script 11 (void)
{
	count--;
}

script 1000 OPEN
{
	while (count < PlayerCount())
		Delay(35);
	
	PrintBold(s:"All players ready!");
	
	//etc.
}

This counter will keep track of the number of players currently in the sector and when script 1000 finds the counter to equal PlayerCount, a special action occurs.

Note that this does not account for such events as players dying in the sector, or players disconnecting from the game in the sector. It is possible to prevent these problems by using an array of boolean variables, one for each player, and checking the total against PlayerCount. DEATH and DISCONNECT scripts can reset the particular player's state.

Personal tools