
|
Originally Posted by ^Psycho^
чо посоветуем-с
Dr.Psycho (17:52:33 23/02/2010) у меня есть массив с 10ью никами Dr.Psycho (17:52:41 23/02/2010) я хочу чтобы введя кусокчек ника Dr.Psycho (17:52:51 23/02/2010) выдало первый похожий результат Dr.Psycho (17:52:59 23/02/2010) strfind не помогает, там ищет полные совпадения Dup1ex (17:54:07 23/02/2010) хы.. напиши свой аналог.. Dup1ex (17:54:26 23/02/2010) чтоб там искало совпадения от 3х символов Dr.Psycho (17:54:45 23/02/2010) хм Dr.Psycho (17:54:47 23/02/2010) это вариант Dr.Psycho (17:56:09 23/02/2010) ведь была какая то стандартная функция |
stock name[500][24], p; // ... for ( p = 0; p < 500; p++ ) if ( strfind( name[p], "ego", true ) >= 0 ) break; // в name[p] сейчас имя 1го совпавшего ника
|
if(strcmp(cmd, "/nstats", true) == 0){ tmp = strrest(cmdtext, idx); if(!strlen(tmp)){ SendClientMessage(playerid, COLOR_MSG, "Ïèøèòå: /nstats < íèê èãðîêà >"); return 1; } if(24 < strlen(tmp) || strlen(tmp) < 3) { SendClientMessage(playerid, COLOR_MSG, "Äëèíà íèêà äîëæíà áûòü 3-24 ñèìâîëà."); return 1; } new result; new wtf = GetFromServerStats("regplayers"); for(new i = 0; i < wtf; i++){ if(result == 0) { if(strfind(ImportAccountInfo[i][importnickname],tmp, true)){ ReturnPlayerStatsAsTextDraw(playerid,ImportAccount Info[i][importnickname]); print(ImportAccountInfo[i][importnickname]); result = 1; } } } if(result == 0){ format(string,256,"%s íå íàéäåí â ñòàòèñòèêå.",tmp); SendClientMessage(playerid, COLOR_MSG, string); } return 1; } |
|
Originally Posted by ^Psycho^
Dr.Psycho (17:56:09 23/02/2010)
ведь была какая то стандартная функция |
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) // Strip out leading spaces
{
if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos])) // Check whole passed string
{
// If they have a numeric name you have a problem (although names are checked on id failure)
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
/*if (playerid != INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF0000AA, "User not connected");
}*/
userid = INVALID_PLAYER_ID;
}
else
{
return userid; // A player was found
}
}
/*else
{
if (playerid != INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
}
userid = INVALID_PLAYER_ID;
}
return userid;*/
// Removed for fallthrough code
}
// They entered [part of] a name or the id search failed (check names just incase)
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
{
if (len == strlen(name)) // Exact match
{
return i; // Return the exact player on an exact match
// Otherwise if there are two players:
// Me and MeYou any time you entered Me it would find both
// And never be able to return just Me's id
}
else // Partial match
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_USER_ID for bad return
}
NameCheck(name[])
{
new
i,
ch;
while ((ch = name[i++]) && (ch == '_') || ('0' <= ch <= '9') || ((ch |= 0x20) && ('a' <= ch <= 'z')))) {}
return !ch;
}
|
NameCheck(name[]) { new lol; for(new i = 0; i < strlen(name); i++) { switch (name[i]) { case '0'..'9', 'a'..'z', 'A'..'Z', '_', ']', '[', ')', '(' : lol++; } } if(lol != strlen(name)) { return 0; } return 1; } |