GetAllPlayers

From GT-MP
Jump to: navigation, search
GetAllPlayers
Shared Function
Utilities-terminal.png Server-Side System-users.png Client-Side
Csharp.png C# Javascript.png JavaScript

Gets all currently connected players in the server

Syntax

In C#
Server-Side Function

API.getAllPlayers();

Required Arguments


NOTE: This function returns data as a List of Client type.

In Javascript
Client-Side Function

API.getAllPlayers();

Required Arguments


NOTE: This function returns data as a List of Client type.

Usage example

In C#
Server-Side Function

public static void Broadcast(string message)
{
	var players = API.shared.getAllPlayers();

	foreach (var player in players)
	{
		API.shared.sendChatMessageToPlayer(player, message);
	}
}

In Javascript
Client-Side Function

var players = API.getAllPlayers();
for (var i = 0; i < players.Length; i++) {
	API.sendChatMessage(API.getPlayerName(players[i]) + "Is on the Server");
}

References