get player id/name - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: get player id/name (
/showthread.php?tid=510271)
get player id/name -
iBots - 30.04.2014
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?
Re: get player id/name -
MattTucker - 30.04.2014
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
Re: get player id/name -
Vince - 30.04.2014
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:
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.
|
Re: get player id/name -
iBots - 30.04.2014
cant you help me to create the command?
Re: get player id/name -
Danyal - 30.04.2014
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
Re: get player id/name -
Dignity - 30.04.2014
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;
}
Re: get player id/name -
Konstantinos - 30.04.2014
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.
Re: get player id/name -
Dignity - 30.04.2014
Oh, I didn't know that. I also thought MAX_PLAYERS looped through all online players, not the value. Thanks for correcting me!
Re: get player id/name -
Danyal - 01.05.2014
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