CMD:id(playerid, params[])
{
new string[128], name[24];
if(sscanf(params, "s[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
else
{
new count;
foreach(Player, i)
{
new pname[24];
GetPlayerName(i, pname, sizeof(pname));
if(strfind(pname, name, true) != -1)
{
format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
SendClientMessageEx(playerid, COLOR_WHITE, string);
count ++;
}
}
if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, " No players found.");
}
return 1;
}
CMD:id(playerid, params[])
{
new string[128], name[24];
if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
else
{
new count;
foreach(Player, i)
{
new pname[24];
GetPlayerName(i, pname, sizeof(pname));
if(strfind(pname, name, true) != -1)
{
format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
SendClientMessageEx(playerid, COLOR_WHITE, string);
count ++;
}
}
if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, " No players found.");
}
return 1;
}
CMD:id(playerid, params[])
{
new string[128], name[24];
if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
else
{
new count;
foreach(Player, i)
{
new pname[24];
GetPlayerName(i, pname, sizeof(pname));
if(strfind(pname, name, true) != -1)
{
format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
SendClientMessageEx(playerid, COLOR_WHITE, string);
count ++;
}
}
if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, " No players found.");
}
return 1;
}
The "u", "q", and "r" specifiers search for a user by name or ID. The method of this search has changed in the latest versions of "sscanf". Additionally "U", "Q", and "R" used to take a name or ID as their default value - this has since been changed to JUST a number, and sscanf will not try and determine if this number is online: Users can now optionally return an ARRAY of users instead of just one. This array is just a list of matched IDs, followed by "INVALID_PLAYER_ID". Given the following players: Код:
0) ****** 1) [CLAN]****** 2) Jake 3) Alex 4) Hass Код:
new ids[3], i; if (sscanf("Le", "?<MATCH_NAME_PARTIAL=1>u[3]", ids)) printf("Error in input"); for (i = 0; ids[i] != INVALID_PLAYER_ID; ++i) { if (ids[i] == cellmin) { printf("Too many matches"); break; } printf("id = %d", ids[i]); } if (i == 0) printf("No matching players found."); Код:
id = 0 id = 1 Too many matches Код:
id = 0 id = 1 Код:
No matching players found. When combined with "U" and returning the default, the first slot is always exactly the default value (even if that's not a valid connected player) and the next slot is always "INVALID_PLAYER_ID". Note also that user arrays can't be combined with normal arrays or enums, but normal single-return user specifiers still can be. |
it should be u instead of s
so it will be: pawn Код:
|
COMMAND:id(playerid, params[])
{
new targetid[128],targetid2,string[128],giveplayer[MAX_PLAYER_NAME];
if(sscanf(params, "s[128]", targetid)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /id {FFFFFF}[playerid/PartOfName]");
else
{
targetid2 = ReturnUser(targetid);
if(IsPlayerConnected(targetid2))
{
format(giveplayer, sizeof(giveplayer), "%s", PlayerName(targetid2));
GiveNameSpace(giveplayer);
format(string, sizeof(string), "ID: (%d) %s Ping: %d",targetid2,GetPlayerPing(targetid2));
SendClientMessage(playerid, COLOR_GREY, string);
}
else SendClientMessage(playerid, COLOR_GREY, "User was not found !");
}
return 1;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21)
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
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;
}
}
new len = strlen(text[pos]), count = 0, name[MAX_PLAYER_NAME];
foreach (Player,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, "Multiple users found, please narrow earch");
else SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
userid = INVALID_PLAYER_ID;
}
return userid;
}