-
Just make "player_to_kick" an array and add the found players:
PHP Code:
players_to_kick = []; // changed
player_warn = undefined;
players = getentarray("player","classname");
for(i=0;i<players.size;i++)
{
name = getnormalname(players[i].name);
if(name == name1 || isSubStr(name, name1))
players_to_kick[players_to_kick.size] = players[i]; // changed
}
// changed:
if(players_to_kick.size == 1) {
// only one, normal kick code
} else {
tmp = "multiple players: ";
for (i=0; i<players_to_kick; i++)
tmp += players_to_kick[i] + " ";
iprintlnbold(tmp);
}
-
AHHH i was missing this
Code:
players_to_kick = []; // changed
-
Or use my more advanced findplayerbydata(string) function:
PHP Code:
findplayerbydata(string)
{
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;
}
Needs some adjustments for your mod.
-
It's working almost now with the method from kung. However, if I am the only player it returns size=2 and when there are 2 players with the same name it returns size=3. Shouldn't be that size=1 and size=2?
EDIT:
It is driving me crazy...
When Im the only player and I do the command it will show me the message. But when I add bots and do the exact same command, the server crashes
PHP Code:
******* script runtime error *******
undefined is not an entity: (file 'maps/mp/gametypes/_admin_tools.gsc', line 330)
players_to_kick[i] iprintlnbold("You are kicked, REASON: "+name2);
script what I have now
PHP Code:
test()
{
level endon("boot");
setCvar("g_test2","");
while(1)
{
if(getcvar("g_test2") != "")
{
nameString = getcvar("g_test2");
info = strTok(nameString, " ");
if(info[0].size>2)
name1 = getnormalname(info[0]);
else
{
iprintlnbold("too short");
setcvar("g_test2", "");
wait 0.05;
continue;
}
if(info.size >= 2)
name2 = info[1];
else
name2 = "no reason";
iprintlnbold("info1: "+name1+" , info2: "+name2);
players_to_kick = []; // changed
players_to_kick[players_to_kick.size] = spawnStruct();
player_warn = undefined;
players = getentarray("player","classname");
for(i=0;i<players.size;i++)
{
name = getnormalname(players[i].name);
if(name == name1 || isSubStr(name, name1))
players_to_kick[players_to_kick.size] = players[i]; // changed
}
// changed:
if(players_to_kick.size == 2)
{
players_to_kick[i] iprintlnbold("You are kicked, REASON: "+name2);
}
else if(players_to_kick.size >= 2)
{
tmp = "multiple players: ";
for (i=0; i<players_to_kick; i++)
tmp += players_to_kick[i] + " ";
iprintlnbold(tmp);
}
else if(players_to_kick.size == 1)
{
iprintlnbold("NO PLAYER");
}
setcvar("g_test2", "");
}
wait 1;
}
}
So when I add bots, the size is still 2(it recoginizes me as the playe to be kicked) but then it throws an error that I m undefined
-
PHP Code:
players_to_kick[players_to_kick.size] = spawnStruct();
What are you trying there? Just delete that line. ^^
And I forgot "player.name", try this:
PHP Code:
tmp = "multiple players: ";
for (i=0; i<players_to_kick; i++)
tmp += players_to_kick[i].name + " ";
-
its driving me crazy
PHP Code:
test()
{
level endon("boot");
setCvar("g_test2","");
while(1)
{
if(getcvar("g_test2") != "")
{
nameString = getcvar("g_test2");
info = strTok(nameString, " ");
if(info[0].size>2)
name1 = getnormalname(info[0]);
else
{
iprintlnbold("too short");
setcvar("g_test2", "");
wait 0.05;
continue;
}
if(info.size >= 2)
name2 = info[1];
else
name2 = "no reason";
iprintlnbold("info1: "+name1+" , info2: "+name2);
players_to_kick = []; // changed
players = getentarray("player","classname");
for(i=0;i<players.size;i++)
{
name = getnormalname(players[i].name);
if(name == name1 || isSubStr(name, name1))
players_to_kick[players_to_kick.size] = players[i]; // changed
}
// changed:
if(players_to_kick.size == 1)
{
players_to_kick[i] iprintlnbold("You are kicked, REASON: "+name2);
}
else if(players_to_kick.size >= 2)
{
tmp = "multiple players: ";
for (i=0; i<players_to_kick; i++)
tmp += players_to_kick[i].name + " ";
iprintlnbold(tmp);
}
else
{
iprintlnbold("NO PLAYER");
}
setcvar("g_test2", "");
}
wait 1;
}
}
Error
Code:
******* script runtime error *******
undefined is not an entity: (file 'maps/mp/gametypes/_admin_tools.gsc', line 328)
players_to_kick[i] iprintlnbold("You are kicked, REASON: "+name2);
*
started from:
(file 'maps/mp/gametypes/_admin_tools.gsc', line 409)
wait 0.05;
*
************************************
********************
That is when size==1
-
Instead of [i] use [0] :D
Also try this: http://jsbeautifier.org/
PHP Code:
test() {
level endon("boot");
setCvar("g_test2", "");
while (1) {
if (getcvar("g_test2") != "") {
nameString = getcvar("g_test2");
info = strTok(nameString, " ");
if (info[0].size > 2)
name1 = getnormalname(info[0]);
else {
iprintlnbold("too short");
setcvar("g_test2", "");
wait 0.05;
continue;
}
if (info.size >= 2)
name2 = info[1];
else
name2 = "no reason";
iprintlnbold("info1: " + name1 + " , info2: " + name2);
players_to_kick = []; // changed
players = getentarray("player", "classname");
for (i = 0; i < players.size; i++) {
name = getnormalname(players[i].name);
if (name == name1 || isSubStr(name, name1))
players_to_kick[players_to_kick.size] = players[i]; // changed
}
// changed:
if (players_to_kick.size == 1) {
players_to_kick[0] iprintlnbold("You are kicked, REASON: " + name2);
} else if (players_to_kick.size >= 2) {
tmp = "multiple players: ";
for (i = 0; i < players_to_kick; i++)
tmp += players_to_kick[i].name + " ";
iprintlnbold(tmp);
} else {
iprintlnbold("NO PLAYER");
}
setcvar("g_test2", "");
}
wait 1;
}
}
-
Thanks everybody!
One last minor fix to get it working
Code:
for (i = 0; i < players_to_kick.size; i++)
instead of
Code:
for (i = 0; i < players_to_kick; i++)