Skip to content

GetPlayersList()

GetPlayersList(): Player[]

CAUTION

Do not modify the returned array. It is a reference to the internal array.

Description

The GetPlayersList function retrieves a list of all player entities.

Returned

  • Player[] - array of all player entities.

Example

ts
let exampleScript: ScriptDescription = {};

exampleScript.OnScriptLoad = () => {
	// Check if we are in the game, because otherwise the list of players will be empty
	if(!GameRules.IsActiveGame()) {
		return;
	}
	
	let players = EntitySystem.GetPlayersList();
	for(let player of players) {
		// Display the nickname of each player on the map
		console.log(player.GetName());
    }
}

RegisterScript(exampleScript, "Example script");