15.06.2011, 17:59
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID) {
new pos = 0;
while (text[pos] < 0x21) {
if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos])) {
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS) {
if(!IsPlayerConnected(userid)) {
userid = INVALID_PLAYER_ID;
}
else {
return userid; // A player was found
}
}
}
new len = strlen(text[pos]), count = 0, name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; ++i) {
if (IsPlayerConnected(i)) {
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0)
{
if (len == strlen(name)) {
return i;
}
else {
count++;
userid = i;
}
}
}
}
if (count != 1) {
if (playerid != INVALID_PLAYER_ID) {
if (count) {
SendClientMessage(playerid, 0xFF0000AA, "Encontrado mъltiplos jogadores(ReturnUser)");
}
else {
SendClientMessage(playerid, 0xFF0000AA, "Jogador nгo encontrado(ReturnUser)");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_USER_ID for bad return
}