14.05.2014, 18:39
anyone here who played the cb cnr server will know that in it we can get players id/name by just part of name how to use it in sscanf2
i use the "u" for id's
i use the "u" for id's
new tPlayer;
if(sscanf(params, "u", tPlayer)) return SendClientMessage(playerid, -1, "Usage : /cmd [PlayerID/PartOfName]");
CMD:getid(playerid,params[]) {
if(isnull(params)) return SendClientMessage(playerid,blue,"Correct Usage: /getid [part of nick]");
new found, string[128], playername[MAX_PLAYER_NAME];
format(string,sizeof(string),"Searched for: \"%s\" ",params);
SendClientMessage(playerid,blue,string);
for(new i=0; i <= MAX_PLAYERS; i++){
if(IsPlayerConnected(i)){
GetPlayerName(i, playername, MAX_PLAYER_NAME);
new namelen = strlen(playername);
new bool:searched=false;
for(new pos=0; pos <= namelen; pos++){
if(searched != true){
if(strfind(playername,params,true) == pos){
found++;
format(string,sizeof(string),"%d. %s (ID %d)",found,playername,i);
SendClientMessage(playerid, green ,string);
searched = true;}}}}}
if(found == 0) SendClientMessage(playerid, lightblue, "No players have this in their nick");
return 1;}
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.");
stock getID(pName[]) { new name[25]; for(new playerid; playerid != MAX_PLAYERS; playerid++) { if(IsPlayerConnected(playerid)) { GetPlayerName(playerid, name, 25); if(strfind(name, pName) != -1) return playerid; } } return INVALID_PLAYER_ID; }
CMD:getid(playerid, params[])
{
new string[128], name[25];
if(sscanf(params, "s[25]", name))
{
format(string, sizeof (string), "[USAGE]: /getid (name).");
SendClientMessage(playerid, 0xFF0000FF, string);
return 1;
}
if(!IsPlayerConnected(GetPlayerIDFromName(name)))
{
format(string, sizeof (string), "[ERROR]: The player entered is unknown.");
SendClientMessage(playerid, 0xFF0000FF, string);
return 1;
}
format(string, sizeof (string), "%s's player id is %d.", PlayerName(GetPlayerIDFromName(name)), GetPlayerIDFromName(name));
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
stock GetPlayerIDFromName(playername[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(i, playername2, sizeof(playername2));
if(strcmp(playername2, playername, true, strlen(playername)) == 0)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
stock PlayerName(playerid)
{
new pname[25];
GetPlayerName(playerid, pname, sizeof(pname));
return pname;
}