PDA

View Full Version : Search nickname for his part



maxdamage99
14th October 2015, 12:52
I make the team for a chat, for example:


Player1 name: ^1Su^7per^3-^2Game^5r^8!!!
Player2 say: !mute super

and now Player2 no inaudible Player1.
How to make a determination on the nick introduced its parts.
PRE TY

Ni3ls
14th October 2015, 14:05
isSubStr(name1, name2)

IzNoGoD
14th October 2015, 17:52
findplayerbydata(string)
{
//assumes you'd rather call a player by its name than by its entitynumber
//doesnt check for entitynumber at all atm
if(!isdefined(string))
return undefined;
string = stripcolors(tolower(string));

tmp = "";
for(i = 0; i < string.size; i++)
{
if(isint(string[i]))
tmp += string[i];
else
{
if(string[i] != " ")
tmp = "";
break;
}
}
players = getentarray("player", "classname");
if(tmp != "")
{
for(i = 0; i < players.size; i++)
{
if(!isdefined(players[i].izno) || !isdefined(players[i].izno["login_completed"]))
continue;
if(players[i] getentitynumber() == int(tmp))
return players[i];
}
}

BONUS_FOR_CHARS_IN_ORDER = 50;
BONUS_CORRECT_CHAR = 25;
BONUS_FOR_COMPLETE = 200;
best_player = undefined;

best_score = 0;

for(i = 0; i < players.size; i++)
{
score = 0;
previous_correct_char = -1;
name = stripcolors(tolower(players[i].name));
found = false;
for(j = 0; j < name.size - string.size + 1; j++)
{
tmp = getsubstr(name, j, j + string.size);
if(tmp == string)
{
score += (BONUS_FOR_CHARS_IN_ORDER + BONUS_CORRECT_CHAR) * string.size + BONUS_FOR_COMPLETE;
found = true;
break;
}
}
if(!found)
{
used = [];
for(j = 0; j < name.size; j++)
{
for(k = 0; k < string.size; k++)
{
if(isdefined(used[k]))
continue;
if(name[j] == string[k])
{
used[k] = true;
if(j == previous_correct_char + 1)
score += BONUS_FOR_CHARS_IN_ORDER;
previous_correct_char = j;
score += BONUS_CORRECT_CHAR;
}
}
}
}
if(score > best_score)
{
best_score = score;
best_player = players[i];
}
else if(score == best_score)
best_player = undefined;
}
if(isdefined(best_player))
{
if(best_score > BONUS_CORRECT_CHAR * string.size)
return best_player;
}
return;
}