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; }
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; }
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 pawn Код:
Код:
id = 0 id = 1 Too many matches Код:
id = 0 id = 1 Код:
No matching players found. 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. |
Why explain? Its specifier . It work like this: If you enter /id John and If there is only one with strating name John it will select him if there are more with starting name John then it will select nothing :P. http://prntscr.com/b7tx8h
|
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.");
CMD:id(playerid, params[]) { extract params -> new string:szName[MAX_PLAYER_NAME + 1]; else { SendClientMessage(playerid, C_DUMMY, "Используйте: /id [ник или часть ника]"); return true; } new szMessage[64]; new arrPlayers[8]; new bTooMany; new index; if(sscanf(szName, "?<MATCH_NAME_PARTIAL=1>u[8]", arrPlayers)) { SendClientMessage(playerid, C_ERROR, "Произошла неизвестная ошибка при поиске"); //Unknown error return true; } for(index = 0; arrPlayers[index] != INVALID_PLAYER_ID; ++index) { if(arrPlayers[index] == cellmin) { bTooMany = 1; break; } format(szMessage, 64, "%i. %s - %i", index + 1, Players[index][m_szName], arrPlayers[index]); SendClientMessage(playerid, -1, szMessage); } if(index == 0) { SendClientMessage(playerid, C_DUMMY, "Совпадений не найдено"); return true; } if(bTooMany == 1) { SendClientMessage(playerid, C_DUMMY, "Показано 7 первых найденых игроков"); return true; } return true; }
I didn't understood how to find a player with 'u' specifier.
Код:
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."); |
new ids, i;
if (sscanf("Le", "r", ids)) print("Error in input"); //what is Le?
//check if player is connected
if(!IsPlayerConnected(ids)) return print("Player is not connected');
printf("id = %d", ids);
So, the final command is:
Код:
CMD:id(playerid, params[]) { extract params -> new string:szName[MAX_PLAYER_NAME + 1]; else { SendClientMessage(playerid, C_DUMMY, "Используйте: /id [ник или часть ника]"); return true; } new szMessage[64]; new arrPlayers[8]; new bTooMany; new index; if(sscanf(szName, "?<MATCH_NAME_PARTIAL=1>u[8]", arrPlayers)) { SendClientMessage(playerid, C_ERROR, "Произошла неизвестная ошибка при поиске"); //Unknown error return true; } for(index = 0; arrPlayers[index] != INVALID_PLAYER_ID; ++index) { if(arrPlayers[index] == cellmin) { bTooMany = 1; break; } format(szMessage, 64, "%i. %s - %i", index + 1, Players[index][m_szName], arrPlayers[index]); SendClientMessage(playerid, -1, szMessage); } if(index == 0) { SendClientMessage(playerid, C_DUMMY, "Совпадений не найдено"); return true; } if(bTooMany == 1) { SendClientMessage(playerid, C_DUMMY, "Показано 7 первых найденых игроков"); return true; } return true; } |
Players[index][m_szName]
Players[arrPlayers[index]][m_szName]