dcmd_list(playerid, params[])
{
return 1;
}
dcmd_list(playerid, params[])
{
SendClientMessage(playerid, 0x55FF55FF, "--- Present Players"); // Send a message before we list the online players
new ListCount = 0; // A value we will use later.
new string[130]; // Create our new string
format(string, sizeof(string), "Players: "); // Set the start of each message. Meaning if we have a lot of players on, and their names go off the screen we can continue it down to another line. So we will start each line with, "Players: "
return 1;
}
dcmd_list(playerid, params[])
{
SendClientMessage(playerid, 0x55FF55FF, "--- Present Players"); // Send a message before we list the online players
new ListCount = 0; // A value we will use later.
new string[130]; // Create our new string
format(string, sizeof(string), "Players: "); // Set the start of each message. Meaning if we have a lot of players on, and their names go off the screen we can continue it down to another line. So we will start each line with, "Players: "
for(new i = 0; i < MAX_PLAYERS; i++) // Setup the loop
{
if(IsPlayerConnected(i)) // Only continue if someone is connected to the player slot.
{
}
}
return 1;
}
dcmd_list(playerid, params[])
{
SendClientMessage(playerid, 0x55FF55FF, "--- Present Players"); // Send a message before we list the online players
new ListCount = 0; // A value we will use later.
new string[130]; // Create our new string
format(string, sizeof(string), "Players: "); // Set the start of each message. Meaning if we have a lot of players on, and their names go off the screen we can continue it down to another line. So we will start each line with, "Players: "
for(new i = 0; i < MAX_PLAYERS; i++) // Setup the loop
{
if(IsPlayerConnected(i)) // Only continue if someone is connected to the player slot.
{
new PlayerName[24]; // Set a new variable to store the player's name to.
GetPlayerName(i, PlayerName, 24); // Get and store the player's name to PlayerName.
if(ListCount == 0) // We set this to 0 earlier. Basically the purpose of the ListCount value is so we can have the, "Players: " display correctly. Notice the first thing in each of the strings below. The first one is just %s which will be filled in by "Players: " the second one is %s, so we can list names. We don't want it to say, "Players: , Name(ID), Name(ID)" because there is just a random coma there in the beginning so we use this solution.
{
format(string, sizeof(string), "%s %s(%d)", string, PlayerName, i); // Format the first message of each line.
} else format(string, sizeof(string), "%s, %s(%d)", string, PlayerName, i); // Format the list of all the other players.
ListCount++; // This is equivalent to, "ListCount = ListCount + 1;" So we are adding 1 onto it. Technically all we need to do is set this to anything over 0 but this works anyway.
if(strlen(string) > 100) // Alright so this is where we create a new line. If the length of the list gets to be over 100 characters we will continue here.
{
SendClientMessage(playerid, 0xB4B4B4FF, string); // First we send what we currently have to the player.
format(string, sizeof(string), "Players: "); // Then we format the string back to the original
ListCount = 0; // And we also set this value back to the original, and continue with the process until all the players have been marked.
}
}
}
if(ListCount > 0) SendClientMessage(playerid, 0xB4B4B4FF, string); // Now we first check if ListCount is greater than 0. This is because if there are no other names, we don't want to send a line that just says, "Players: " That would look silly :) But anyway if ListCount is greater than 0, that means there is at least one name still in the list that hasn't been sent to the player yet. So we send the last line.
return 1;
}
Originally Posted by NeRoSiS
Nice guide, it's always a nice thing to see because it shows how much you want the community to go on.
Respect. |