19.02.2015, 13:15
Like there are players using /spec,i want to see how many of them are speccing with names
new Spectating[MAX_PLAYERS]; // Creates a variable for MAX_PLAYERS(500)
Spectating[playerid] = 1; // Sets "Specating" to 1 for the player
new string[128], name[MAX_PLAYER_NAME], spectators; // Creates 2 strings, "string" and "name", and a "spectators" variable
format(string, sizeof(string), "Players spectating:"); // Formats "string", making it contain: "Players spectating:"
foreach(Player, i) // Loops through all players, and defines them as "i"
{
if(Spectating[playerid] == 1) // Checks if "Spectating" is set to 1
{
GetPlayerName(i, name, sizeof(name)); // Get's the name of "i"
strcat(string, " %s", name); // Add's on the name to the string
spectators ++; // Increases "spectators" by 1
}
}
switch(spectators) // Creates a switch, checking the value of "spectators"
{
case 0: SendClientMessage(playerid, -1, "No players are currently spectating anyone.");
// If "spectators" hasn't been increased (therefore it's value is 0) it will send this message instead
default: SendClientMessage(playerid, -1, string);
// If it's set to something else than 0 (players are spectating), it will send the original string
}