From ZDoom Wiki
Jump to: navigation, search

int PlayerNumber (void)


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.


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

script 5 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 5.

script 10 (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 15 (void)
	if (PlayerNumber() >= 0)