get player id/name
#1

How could i make like when i /id d it sends me all of the names which have letter d in it
example:
if there are names with Mike,and i do:
/id mike
it shows:
Mike John2
Mike Test1
John Mikeson
Mike
how?
Reply
#2

Loop all the active players, get their names, and use strfind, if it has "mike" in it then you send a message with the name/playerid.

https://sampwiki.blast.hk/wiki/Strfind
Reply
#3

https://sampforum.blast.hk/showthread.php?tid=120356
Quote:
Originally Posted by ******
Посмотреть сообщение
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
This code:

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.");
Will output:

Код:
id = 0
id = 1
Too many matches
Searching "Les" instead will give:

Код:
id = 0
id = 1
And searching without "MATCH_NAME_PARTIAL" will give:

Код:
No matching players found.
Basically, if an array of size "N" is passed, this code will return the first N-1 results. If there are less than "N" players whose name matches the given name then that many players will be returned and the next slot will be "INVALID_PLAYER_ID" to indicate the end of the list. On the other hand if there are MORE than "N - 1" players whose name matches the given pattern, then the last slot will be "cellmin" to indicate this fact.

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.
Reply
#4

cant you help me to create the command?
Reply
#5

pawn Код:
CMD:id(playerid, params[]) {
    if(isnull(params)) {
        return SendClientMessage(playerid, -1, "USAGE: /id [player name]");
    }

    new
        string[128],
        Playername[MAX_PLAYER_NAME];

    foreach(new i: Player)
    {
        GetPlayerName(i, Playername, sizeof Playername);
        if(strfind(Playername, params, true) != -1) {
            format(string, sizeof string, "%s (ID: %d)", Playername, i);
            SendClientMessage(playerid, -1, string);
        }
    }
    return 1;
}
I havent tested but should work
Reply
#6

Has been tested and works:

pawn Код:
CMD:id(playerid, params[])
{
    new id, targetname[MAX_PLAYER_NAME+1], string[128];

    if(sscanf(params, "i", id)) return SendClientMessage(playerid, -1, "/id [id]");

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(id == i) GetPlayerName(i, targetname, sizeof(targetname));
    }

    format(string, sizeof(string), "ID %d is %s", id, targetname);
    SendClientMessage(playerid, -1, string);

    return 1;
}
Reply
#7

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Has been tested and works:

pawn Код:
CMD:id(playerid, params[])
{
    new id, targetname[MAX_PLAYER_NAME+1], string[128];

    if(sscanf(params, "i", id)) return SendClientMessage(playerid, -1, "/id [id]");

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(id == i) GetPlayerName(i, targetname, sizeof(targetname));
    }

    format(string, sizeof(string), "ID %d is %s", id, targetname);
    SendClientMessage(playerid, -1, string);

    return 1;
}
He wants to enter a part of name and gets a list with players that have that part to their name. Using sscanf - what Vince posted is the best way. The most common would be what Danyal posted with the exception that in the format function, the first argument should be "Playername" instead of "GetPlayerName(i, Playername, sizeof Playername)".

Your code loops without any reason to check if the number is between 0 and MAX_PLAYERS's value.
Reply
#8

Oh, I didn't know that. I also thought MAX_PLAYERS looped through all online players, not the value. Thanks for correcting me!
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
He wants to enter a part of name and gets a list with players that have that part to their name. Using sscanf - what Vince posted is the best way. The most common would be what Danyal posted with the exception that in the format function, the first argument should be "Playername" instead of "GetPlayerName(i, Playername, sizeof Playername)".

Your code loops without any reason to check if the number is between 0 and MAX_PLAYERS's value.
Oh yeah thanks for correcting meh i edited the code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)