Command: /id [player name or part of name]
#1

As the title says, the following command is supposed to show a list of players with the name containing what was typed.

EG: If I type in game: /id jam

It should appear as (If there are 3 people online with the letters jam in the name):

James Girvan - ID 1
Jamie Clark - ID 5
Chris Jameson - ID 24

But it doesn't.

pawn Код:
command(id, playerid, params[])
{
    new name[24], string[1024];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
    {
        format(string, sizeof(string), "%s\n%s - ID %d", string, RemoveUnderScore(GetPlayerIDFromName(name, 1)), GetPlayerIDFromName(name, 1));
        SendClientMessage(playerid, WHITE, string);
    }
    return 1;
}
If anyone can help, I'd be grateful.
Reply
#2

use u. instead of s.
u = playername/id.

pawn Код:
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
Reply
#3

That wouldn't find the players that are also containing the same name though?
Reply
#4

Actually.
I think it will find the players that are also containing the same name.

However.
Read the sscanf topic for more information.
https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#5

Quote:
Originally Posted by Romel
Посмотреть сообщение
use u. instead of s.
u = playername/id.

pawn Код:
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
No, what you posted is just wrong.

Here is an example on how it should be done OP
pawn Код:
CMD:id(playerid, params[]) {
    if(isnull(params)) {
        return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /id [player name]");
    }

    new
        szMessage[64],
        szPlayerName[MAX_PLAYER_NAME],
        iTargetID = strval(params);

    if(IsNumeric(params) && IsPlayerConnected(strval(params))) {
        format(szMessage, sizeof szMessage, "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", iTargetID, GetPlayerNameEx(iTargetID), PlayerInfo[iTargetID][pLevel], GetPlayerPing(iTargetID));
        return SendClientMessageEx(playerid, COLOR_WHITE, szMessage);
    }
    else if(strlen(params) < 3) {
        return SendClientMessageEx(playerid, COLOR_GREY, "Input at least 3 characters to search.");
    }
    else foreach(new i: Player) {
        GetPlayerName(i, szPlayerName, sizeof szPlayerName);
        if(strfind(szPlayerName, params, true) != -1) {
            format(szMessage, sizeof szMessage, "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
            SendClientMessageEx(playerid, COLOR_WHITE, szMessage);
        }
    }
    return 1;
}
Reply
#6

pawn Код:
command(id, playerid, params[])
{
    new name[24];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
    format(string, sizeof(string), "%s\n%s - ID %d", string, RemoveUnderScore(GetPlayerID(name, 1)), GetPlayerID(name, 1));
    SendClientMessage(playerid, WHITE, string);
    return 1;
}
pawn Код:
stock GetPlayerID(const playername[], partofname=0) //By Jan "DracoBlue" Schќtze (edited by Gabriel "Larcius" Cordes) || Or ******, I don't remember.
{
    new i;
    new playername1[MAX_STRING];
    for (i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i,playername1,sizeof(playername1));
            if (strcmp(playername1,playername,true)==0)
            {
                return i;
            }
        }
    }
    new correctsigns_userid=-1;
    new tmpuname[MAX_STRING];
    new hasmultiple=-1;
    if(partofname)
    {
        for (i=0;i<MAX_PLAYERS;i++)
        {
            if (IsPlayerConnected(i))
            {
                GetPlayerName(i,tmpuname,sizeof(tmpuname));
                if (strfind(tmpuname,partofname,true)==0)
                {
                    hasmultiple++;
                    correctsigns_userid=i;
                }
                if (hasmultiple>0)
                {
                    return -2;
                }
            }
        }
    }
    return correctsigns_userid;
}
Reply
#7

Try this:
pawn Код:
CMD:id(playerid, params[])
{
    new name[MAX_PLAYER_NAME], string[1024];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name/part of name]");  
    new count = 0;
    new playername[MAX_PLAYER_NAME];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, playername, MAX_PLAYER_NAME);
            if(strfind(playername, name, true) != -1)
            {
                if(count == 0)
                {
                    format(string,sizeof(string),"%s - ID %d",playername, i);
                    count++;
                    continue;
                }
                count++;
                format(string,sizeof(string),"%s\n%s - ID %d",string, playername, i);
            }
        }
    }
    if(count == 0) return SendClientMessage(playerid, WHITE, "No players were found.");
    SendClientMessage(playerid, WHITE, string);
    return 1;
}
Reply
#8

The new sscanf 2.8 has some new array sort of feature for player's names. Read up on that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)