How to make /getid?
#1

I want to make a Command /getid [PartOfName] and please see Carefully PartOfName not /getid [playerid] and it will say name not that
i want it types a players partofname and it will get id.
Reply
#2

Do you use sscanf?
Reply
#3

Yes i use zcmd and sscanf
Reply
#4

pawn Код:
CMD:getid(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, "USAGE: /getid <part of name>");
    //The u parameter is playerid / part of name
    format(str, sizeof(str), "ID: %d is %s", id, Name(id)); //the name of the player..I used my stock here
    SendClientMessage(playerid, -1, str);
    return 1;
}
Reply
#5

pawn Код:
CMD:getid( playerid, params[ ] )
{
    new found, string[128], playername[MAX_PLAYER_NAME];
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /getid [PartOfName] ");
    format(string,sizeof(string),"Searched for: \"%s\"",params);
    SendClientMessage(playerid, -1,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, -1 ,string);
                        searched = true;
                    }
                }
            }
        }
    }
    if(found == 0)
    SendClientMessage(playerid, -1, "No Players Localized!");
    return 1;
}
Reply
#6

\"%s\
Why these are used?
( \ \ )?
And also i have a GetName(playerid) stock so please convert it to that.
Reply
#7

The \" is so you can use quotes inside of a string...\"HI\" = "HI"
Reply
#8

Quote:
Originally Posted by Spooky
Посмотреть сообщение
\"%s\
Why these are used?
( \ \ )?
And also i have a GetName(playerid) stock so please convert it to that.
pawn Код:
CMD:getid( playerid, params[ ] )
{
    new found, string[128];
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /getid [PartOfName] ");
    format(string,sizeof(string),"Searched for: %s",params);
    SendClientMessage(playerid, -1,string);
    for(new i=0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new namelen = strlen(GetName(i));
            new bool:searched=false;
            for(new pos=0; pos <= namelen; pos++)
            {
                if(searched != true)
                {
                    if(strfind(GetName(i),params,true) == pos)
                    {
                        found++;
                        format(string,sizeof(string),"%d. %s (ID: %d)",found,GetName(i),i);
                        SendClientMessage(playerid, -1 ,string);
                        searched = true;
                    }
                }
            }
        }
    }
    if(found == 0)
    SendClientMessage(playerid, -1, "No Players Localized!");
    return 1;
}
Reply
#9

We cannot write simple as %s?
And whats Bool?
And can you convert GetPlayerName to GetName(playerid) cause i have a stock for it.
Reply
#10

Quote:
Originally Posted by Spooky
Посмотреть сообщение
We cannot write simple as %s?
And whats Bool?
And can you convert GetPlayerName to GetName(playerid) cause i have a stock for it.
Converted.

pawn Код:
CMD:getid( playerid, params[ ] )
{
    new found, string[128];
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /getid [PartOfName] ");
    format(string,sizeof(string),"Searched for: %s",params);
    SendClientMessage(playerid, -1,string);
    for(new i=0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new namelen = strlen(GetName(i));
            new bool:searched=false;
            for(new pos=0; pos <= namelen; pos++)
            {
                if(searched != true)
                {
                    if(strfind(GetName(i),params,true) == pos)
                    {
                        found++;
                        format(string,sizeof(string),"%d. %s (ID: %d)",found,GetName(i),i);
                        SendClientMessage(playerid, -1 ,string);
                        searched = true;
                    }
                }
            }
        }
    }
    if(found == 0)
    SendClientMessage(playerid, -1, "No Players Localized!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)