16.08.2015, 12:14
PHP код:
new player1, tmp[256], playername[MAX_PLAYER_NAME];
new count = 0;
tmp = strtok(cmdtext, idx);
if(IsNumeric(tmp))
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
if(strval(tmp) == i)
player1 = i;
else
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
player1 = INVALID_PLAYER_ID;
}
}
}
else
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerName(i, playername, sizeof(playername));
if(IsPlayerConnected(i))
if(strfind(playername, tmp, true) != -1)
count++;
}
if(count == 0)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Player not connected.");
player1 = INVALID_PLAYER_ID;
}
else
{
if(count > 7)
{
SendClientMessage(playerid, COLOR_WHITE, "Error: Too many players matched your searched.");
player1 = INVALID_PLAYER_ID;
}
else if(count == 1)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, tmp, true) != -1)
player1 = j;
}
}
}
else if(count <= 7)
{
for(new j = 0; j < MAX_PLAYERS; j++)
{
if(IsPlayerConnected(j))
{
GetPlayerName(j, playername, sizeof(playername));
if(strfind(playername, tmp, true) != -1)
{
format(string,sizeof(string),"%s (%d)", playername, j);
SendClientMessage(playerid, COLOR_WHITE, string);
player1 = INVALID_PLAYER_ID;
continue;
}
}
}
SendClientMessage(playerid, COLOR_WHITE, "Error: More than one player found. Choose one of the IDs above.");
}
}
}