any way to get players id form the part of name
#1

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
Reply
#2

For example :

pawn Код:
new tPlayer;
if(sscanf(params, "u", tPlayer)) return SendClientMessage(playerid, -1, "Usage : /cmd [PlayerID/PartOfName]");
Reply
#3

thanks but the only problem is how i set it to 1 ?? and if multiple names found any message like there are multiple names for it please be specific
Reply
#4

it was there but i didn't find how to change it to 1
i wanted was like my name is sasuke_uchiha and i use command get the command get ha "u" sscanf if i type uchiha it will not get me but if i use sasuke it will get me all i want is that if i type uchi it should get the player but if there is an other player named sasuke_uchia it would return a message to command user that be more specific found multiple names
Reply
#5

pawn Код:
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;}
the cmd the I got made maybe it will work for you
Reply
#6

i can't use the same command in every other command
****** can u explain me more i can't get how to use it in here
pawn Код:
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.");
??
Reply
#7

Код:
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;
}
Reply
#8

Quote:
Originally Posted by ball
Посмотреть сообщение
Код:
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;
}
i don't want the i mean that if we enter the part of name the command get's executed and i think ****** got what i meant
Reply
#9

Give an example, you want to get all players id or one id?
Reply
#10

Probably this will help:

pawn Код:
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;
}
Have fun
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)