public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/blue", cmdtext, true, 10) == 0)
{
if(GetPlayerColor(playerid) == 0x00137FAA) //0x00137FFAA = Blue color
{
SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
new names[MAX_PLAYER_NAME], string[44];
GetPlayerName(playerid, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
return 1;
}
return 0;
}
//Like:
// |_List of blue players_|
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// ect...
public OnPlayerCommandText(playerid, cmdtext[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
if (strcmp("/blue", cmdtext, true, 10) == 0)
{
if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
{
SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
new names[MAX_PLAYER_NAME], string[44];
GetPlayerName(playerid, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
return 1;
}
return 0;
}
#include <a_samp>
#include <zcmd>
#include <foreach>
COMMAND:blue( playerid, params [ ] )
{
new
string [ 10 + MAX_PLAYER_NAME ],
pName [ MAX_PLAYER_NAME ]
;
SendClientMessage ( playerid, 0xFFFFFFAA, "|_List of blue players_|" );
foreach (Player, i)
{
if ( GetPlayerColor ( i ) == 0x00137FAA )
{
GetPlayerName ( i, pName, MAX_PLAYER_NAME );
format ( string, sizeof ( string ), "%s - ( %d ), " );
SendClientMessage ( playerid, 0xFFFFFFAA, string );
}
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/blue", cmdtext, true, 5) == 0)
{
SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
for(new i=0; i<MAX_PLAYERS; i++)
{
if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
{
new names[MAX_PLAYER_NAME], string[44];
GetPlayerName(i, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
}
return 1;
}
return 0;
}
@Benjo, you're creating a string which is 65 characters long, 500 times which is a total waste of CPU/Memory and people could just spam the command all day long and imagine the lag you get.
|
#define DIALOG_LOGIN_BLUE 1 // This is the dialogid
#define BLUE_PASSWORD "qwerty1" // changethis
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case(DIALOG_LOGIN_BLUE):
if(!response) { /* user cancelled */ } else
{
if(strcmp(inputtext, BLUE_PASSWORD, false, strlen(BLUE_PASSWORD)) == 0)
{
SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
new names[MAX_PLAYER_NAME], string[44];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
{
GetPlayerName(i, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
}
} else {
SendClientMessage(playerid, 0xDEEE20FF, "Incorrect password.");
}
}
default:{printf("DEBUG: Undefined dialogid.");}
}
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/blue", cmdtext, true, 5) == 0)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN_BLUE, DIALOG_STYLE_INPUT, "Authentication", "Please type the password for the blue team.", "Ok", "Cancel");
return 1;
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/blue", cmdtext, true, 5) == 0)
{
SendClientMessage(playerid,0xDEEE20FF, "|_List Of Blue Players_|");
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
{
new names[MAX_PLAYER_NAME], string[MAX_PLAYER_NAME+7];
GetPlayerName(i, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
}
}
return 1;
}
return 0;
}
**How to say "No blue players online" when no blue players is online?**
|
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case(DIALOG_LOGIN_BLUE):
if(!response) { /* user cancelled */ } else
{
if(strcmp(inputtext, BLUE_PASSWORD, false, strlen(BLUE_PASSWORD)) == 0 && strlen(inputtext) > 0)
{
new names[MAX_PLAYER_NAME], string[44], bool:flag = false; // <--- ADDED flag VARIABLE HERE
for(new i=0; i<MAX_PLAYERS; i++)
{
if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
{
if(!flag)
{
SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
flag = true;
}
GetPlayerName(i, names, sizeof(names));
format(string, sizeof(string), "%s(%d)",names ,playerid);
SendClientMessage(playerid, 0x7F0037AA, string);
}
}
if(!flag)
{
SendClientMessageToAll(0xDEEE20FF, "There are no players on the blue team.");
}
} else {
SendClientMessage(playerid, 0xDEEE20FF, "Incorrect password.");
}
return 1;
}
default:{printf("DEBUG: Undefined dialogid.");}
}
return 0;
}