PlayerNumber

From ZDoom Wiki
Revision as of 17:16, 12 June 2008 by HotWax (talk | contribs)
Jump to navigation Jump to search

int PlayerNumber (void)

Usage

Returns the player number for the player who activated the script, starting at 0. For scripts that were not activated by a player, PlayerNumber() will return -1.

Examples

A useful application of this command is to give each player an individual TID. The code to do this is:

script 1000 ENTER
{
	Thing_ChangeTID(0, 1000 + PlayerNumber());
}

This will assign players TIDs of 1000, 1001, 1002... so they can be accessed individually. They can also be accessed as a group using for loops. The following script gives all players maximum health based on the TIDs from script 1000.

script 5 (void)
{
	for (int n = 0; n < PlayerCount(); n  )
		SetActorProperty(1000 + n, APROP_HEALTH, 200);
}

This example will add to a map level variable if the activator of the script is a player. It takes advantage of the fact that PlayerNumber will return -1 for a non-player activator.

int teamkills;
 
script 10 (void)
{
	if (PlayerNumber() >= 0)
	{
		teamkills++;
	}
}