PDA

View Full Version : potential infinite loop in script



Ni3ls
15th January 2015, 12:33
test()
{
level endon("boot");
setCvar("g_test2","");
while(1)
{
if(getcvar("g_test2") != "")
{
info = strTok(getCvar("g_test2")," ");
if(info.size != 2)
continue;

name1 = getnormalname(info[0]);
name2 = getnormalname(info[1]);

player_to_kick = undefined;
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))
player_to_kick = players[i];

}
if(!isDefined(player_to_kick))
continue;

player_to_kick iprintlnbold("You are kicked\nREASON: "+name2);
setcvar("g_test2", "");
}
wait 1;
}
}

getnormalname(name)
{
while(issubstr(name,"^1")||issubstr(name,"^2")||issubstr(name,"^3")||issubstr(name,"^4")||issubstr(name,"^5")||issubstr(name,"^6")||issubstr(name,"^7")||issubstr(name,"^8")||issubstr(name,"^9")||issubstr(name,"^0"))
{
for(i=0;i<name.size-1;i++)
{
if(name[i]=="^")
{
if(name[i+1]=="1"||name[i+1]=="2"||name[i+1]=="3"||name[i+1]=="4"||name[i+1]=="5"||name[i+1]=="6"||name[i+1]=="7"||name[i+1]=="8"||name[i+1]=="9"||name[i+1]=="0")
{
tmp="";
for(j=0;j<name.size;j++)
{
if(j!=i&&j!=i+1)
{
tmp+=name[j];
}
}
name=tmp;
break;
}
}
}
wait 0.05;
}
return tolower(name);
}
credits to Inzo for getnormalname

This script is working when I write a part of an existing name. For example I play with "Ni3ls" and I write "/rcon g_test2 ni3 gay" I can see the message in my screen with the reason: gay. However, when I write "/rcon g_test2 nie gay", a non existing player, the server crashes and say I got potential infinite loop in the
setCvar("g_test2","");
while(1)
{ and sometimes in the
players = getentarray("player","classname");
for(i=0;i<players.size;i++)
{
How to fix this damned thing?

IzNoGoD
15th January 2015, 13:40
in your first bit of script, the continue; has no wait attached to it, making it loop infinitely without waits.

Add a wait at (both) continue; and you should be fine.

Ni3ls
15th January 2015, 15:21
K no error anymore. But when I do the correct name after I did a wrong one, it doesnt work anymore. No message or error is shown

IzNoGoD
15th January 2015, 15:41
Thats due to your continue not resetting the g_test2 cvar to an empty string, thus locking the loop

Ni3ls
16th January 2015, 09:42
Another thing. I have to the reason. This can also be a space. How can I make it so its optionable to write a reason? If i dont write a reason, the command doesnt work

filthy_freak_
16th January 2015, 15:15
This is how I do it:

Replace the first menuDef in main.menu with this;


menuDef
{
name main
fullScreen 1
rect 0 0 640 480 // Size and position of the menu
focusColor GLOBAL_FOCUSED_COLOR // Menu focus color for text and items
soundloop "music_mainmenu_mp"
onOpen
{
setDvar cl_bypassMouseInput "0";
close bg;
close main_text;

open bg;
open main_text;

setDvar success "true";
uiScript addPlayerProfiles;
uiScript openMenuOnDvar com_playerProfile "" player_profile;
uiScript openMenuOnDvarNot ui_playerProfileCount 1 player_profile;
uiScript openmenuondvar serv_kicked 1 kick_init;
uiScript openmenuondvar serv_kicked2 1 kick_message;
}
onClose
{
close bg;
close main_text;
}
onESC
{
}
}


Also add this to main.menu


menuDef
{
name "kick_init"
rect 0 0 640 480
focuscolor 1 1 1 1
style WINDOW_STYLE_EMPTY

onOpen
{
exec "set serv_kicked 0; set serv_kicked2 1; openmenu main";
close kick_init;
}
}

menuDef
{
name kick_message
visible 0
fullscreen 0
//rect 217 200 210 85
rect 204 160 235 135
focusColor GLOBAL_FOCUSED_COLOR
style 1
border 1
popup
onESC { close kick_message; }
onOpen
{
setfocus yes;
exec "set serv_kicked2 0";
}

itemDef
{
name window
group grpControlbutton
rect 0 2 235 135
style WINDOW_STYLE_FILLED
border 1
bordercolor .5 .5 .5 .5
forecolor 1 1 1 1
backcolor 0 0 0 .5
visible 0
decoration
}

itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -332 -162 896 484
background "white"
forecolor 0 0 0 0.3
backcolor 0 0 0 0.3
visible 1
decoration
}

itemDef
{
name window2
group grpControlbutton
rect 2 3 231 20
style WINDOW_STYLE_FILLED
border 1
bordercolor .1 .1 .1 .2
forecolor 1 1 1 1
backcolor 1 1 .3 .3
visible 0
decoration
}
itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -150 2 535 150
background "popmenu_bg"
// forecolor 0 0 0 0.4
// backcolor 0 0 0 0.4
visible 1
decoration
}
itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -50 20 335 24
background "popmenu_goldline"
// forecolor 0 0 0 0.4
// backcolor 0 0 0 0.4
visible 1
decoration
}

itemDef
{
name confirm
text "@MENU_NOTICE"
style 0
textscale HEADER_SIZE
textstyle ITEM_TEXTSTYLE_SHADOWED
rect 126 25 110 20
textalign 1
textalignx -7
textaligny 5
decoration
forecolor POPMENU_HEADER_COLOR
visible 1
}
itemDef
{
name line1
text "Server Disconnected - Player kicked."
//text "@EXE_SERVERDISCONNECTREASON"
//type ITEM_TYPE_MULTI
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 37 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
//dvar "serv_kicked"
//dvarFloatList { "@EXE_PLAYERKICKED" 0 }
}
itemDef
{
name line2
dvar "serv_kick_reason"
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 72 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
}
itemDef
{
name line3
dvar "serv_kick_length"
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 84 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
}

itemDef
{
name yes
text "@MENU_EXIT"
type ITEM_TYPE_BUTTON
textfont UI_FONT_NORMAL
textscale .26
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
border UI_BUTTON_BORDER
bordercolor UI_BUTTON_BORDER_COLOR
rect 67 138 100 15
textalign 1
textalignx 51 // center
textaligny 11
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1

action
{
play "mouse_click"
close kick_message ;
}

mouseEnter { setitemcolor yes backcolor UI_BUTTON_BACK_COLOR_HOVER; play "mouse_over" }
mouseExit { setitemcolor yes backcolor UI_BUTTON_BACK_COLOR }
}
}


Then all you need to do gsc-wise;


self setClientCvar("serv_kick_reason", "Reason: testing");
self setClientCvar("serv_kick_length", "");
self setClientCvar("serv_kicked", "1");
kick(self getentitynumber());


Results:
http://i.imgur.com/BiwbTuil.jpg (http://imgur.com/BiwbTui)


I use this with libcod b3 commands. Example: !ban <player> <reason>

IzNoGoD
16th January 2015, 15:28
You obviously didnt write this script yourself or you would know this.

Check your strtok length for >=1 instead of != 2
Then, set reason to "" if the strtok-array[1] is undefined, or to the strtok-array[1] if it is defined.
Done.

Ni3ls
17th January 2015, 08:31
You obviously didnt write this script yourself or you would know this.

Check your strtok length for >=1 instead of != 2
Then, set reason to "" if the strtok-array[1] is undefined, or to the strtok-array[1] if it is defined.
Done.

I already did that


if(info.size != 2 && info.size != 1)
continue;

if(info.size==1)
{
name1 = getnormalname(info[0]);
name2 = "No reason";
}
else
{
name1 = getnormalname(info[0]);
name2 = getnormalname(info[1]);
}

Ni3ls
19th January 2015, 19:44
This is how I do it:

Replace the first menuDef in main.menu with this;


menuDef
{
name main
fullScreen 1
rect 0 0 640 480 // Size and position of the menu
focusColor GLOBAL_FOCUSED_COLOR // Menu focus color for text and items
soundloop "music_mainmenu_mp"
onOpen
{
setDvar cl_bypassMouseInput "0";
close bg;
close main_text;

open bg;
open main_text;

setDvar success "true";
uiScript addPlayerProfiles;
uiScript openMenuOnDvar com_playerProfile "" player_profile;
uiScript openMenuOnDvarNot ui_playerProfileCount 1 player_profile;
uiScript openmenuondvar serv_kicked 1 kick_init;
uiScript openmenuondvar serv_kicked2 1 kick_message;
}
onClose
{
close bg;
close main_text;
}
onESC
{
}
}


Also add this to main.menu


menuDef
{
name "kick_init"
rect 0 0 640 480
focuscolor 1 1 1 1
style WINDOW_STYLE_EMPTY

onOpen
{
exec "set serv_kicked 0; set serv_kicked2 1; openmenu main";
close kick_init;
}
}

menuDef
{
name kick_message
visible 0
fullscreen 0
//rect 217 200 210 85
rect 204 160 235 135
focusColor GLOBAL_FOCUSED_COLOR
style 1
border 1
popup
onESC { close kick_message; }
onOpen
{
setfocus yes;
exec "set serv_kicked2 0";
}

itemDef
{
name window
group grpControlbutton
rect 0 2 235 135
style WINDOW_STYLE_FILLED
border 1
bordercolor .5 .5 .5 .5
forecolor 1 1 1 1
backcolor 0 0 0 .5
visible 0
decoration
}

itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -332 -162 896 484
background "white"
forecolor 0 0 0 0.3
backcolor 0 0 0 0.3
visible 1
decoration
}

itemDef
{
name window2
group grpControlbutton
rect 2 3 231 20
style WINDOW_STYLE_FILLED
border 1
bordercolor .1 .1 .1 .2
forecolor 1 1 1 1
backcolor 1 1 .3 .3
visible 0
decoration
}
itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -150 2 535 150
background "popmenu_bg"
// forecolor 0 0 0 0.4
// backcolor 0 0 0 0.4
visible 1
decoration
}
itemDef
{
name backimage2fade
style WINDOW_STYLE_SHADER
rect -50 20 335 24
background "popmenu_goldline"
// forecolor 0 0 0 0.4
// backcolor 0 0 0 0.4
visible 1
decoration
}

itemDef
{
name confirm
text "@MENU_NOTICE"
style 0
textscale HEADER_SIZE
textstyle ITEM_TEXTSTYLE_SHADOWED
rect 126 25 110 20
textalign 1
textalignx -7
textaligny 5
decoration
forecolor POPMENU_HEADER_COLOR
visible 1
}
itemDef
{
name line1
text "Server Disconnected - Player kicked."
//text "@EXE_SERVERDISCONNECTREASON"
//type ITEM_TYPE_MULTI
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 37 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
//dvar "serv_kicked"
//dvarFloatList { "@EXE_PLAYERKICKED" 0 }
}
itemDef
{
name line2
dvar "serv_kick_reason"
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 72 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
}
itemDef
{
name line3
dvar "serv_kick_length"
textfont UI_FONT_NORMAL
textscale .25
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
rect 65 84 100 15
textalign 1
textalignx 51 // center
textaligny 11
decoration
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1
}

itemDef
{
name yes
text "@MENU_EXIT"
type ITEM_TYPE_BUTTON
textfont UI_FONT_NORMAL
textscale .26
style UI_BUTTON_STYLE
textstyle UI_BUTTON_TEXT_STYLE
border UI_BUTTON_BORDER
bordercolor UI_BUTTON_BORDER_COLOR
rect 67 138 100 15
textalign 1
textalignx 51 // center
textaligny 11
backcolor UI_BUTTON_BACK_COLOR
forecolor UI_BUTTON_TEXT_COLOR
visible 1

action
{
play "mouse_click"
close kick_message ;
}

mouseEnter { setitemcolor yes backcolor UI_BUTTON_BACK_COLOR_HOVER; play "mouse_over" }
mouseExit { setitemcolor yes backcolor UI_BUTTON_BACK_COLOR }
}
}


Then all you need to do gsc-wise;


self setClientCvar("serv_kick_reason", "Reason: testing");
self setClientCvar("serv_kick_length", "");
self setClientCvar("serv_kicked", "1");
kick(self getentitynumber());


Results:
http://i.imgur.com/BiwbTuil.jpg (http://imgur.com/BiwbTui)


I use this with libcod b3 commands. Example: !ban <player> <reason>

But that is only to show the message in that black box right?

filthy_freak_
19th January 2015, 22:52
But that is only to show the message in that black box right?

Ya.

10char

Ni3ls
20th January 2015, 08:03
I prefer using this


self setClientCvar("com_errorTitle", "BANNED");
self setClientCvar("com_errorMessage", "You have been disconnected, because you are banned");


But that still doesnt solve my problem :P

Mitch
20th January 2015, 10:26
I prefer using this


self setClientCvar("com_errorTitle", "BANNED");
self setClientCvar("com_errorMessage", "You have been disconnected, because you are banned");


But that still doesnt solve my problem :P

It might be possible to use libcod to make a custom kick with reason.

https://github.com/PJayB/Quake-III-Arena-D3D11/blob/master/code/server/sv_client.c
See SV_DropClient. (now the reason is 'was kicked')


// tell everyone why they got dropped
SV_SendServerCommand( NULL, "print \"%s" S_COLOR_WHITE " %s\n\"", drop->name, reason );
SV_SendServerCommand( drop, "disconnect \"%s\"", reason);


Edit: CoD2 uses SV_DropClient(clientnum, "EXE_PLAYERKICKED") by default

Ni3ls
21st January 2015, 17:30
The only thing I need help with is the function to do the kick with reason or optinional reason. The messages arent hard to do

Mitch
21st January 2015, 19:20
The only thing I need help with is the function to do the kick with reason or optinional reason. The messages arent hard to do


Like IzNoGoD said before you can split the cvar value with StrTok.
It returns an array. Based on the size of this array you can check if you got an optional parameter or not.



if(info.size >= 3)
reason = info[2];

IzNoGoD
21st January 2015, 22:46
Like IzNoGoD said before you can split the cvar value with StrTok.
It returns an array. Based on the size of this array you can check if you got an optional parameter or not.



if(info.size >= 3)
reason = info[2];


I think your indices are +1 here and should be --

Ni3ls
22nd January 2015, 09:45
I think there is some big error in my cod2 and I have no idea what is going on. When I wrote the command /rcon g_test2 nie hallo it couldnt find the player, while my name is niels.

So i tried to print the input.

info = strTok(getCvar("name")," ");
for(i=0;i<info.size;i++)
{
iprintlnbold("info"+i+" : "+ info[i]);
}

I tested with different name. My name: i<3evil.server 999
In the console I wrote

/rcon name server hallo test1 test2 doei
This is the output I get

WARNING: Non-localized Game Message string is not allowed to have letters in it. Must be changed over to a localized string: "info0 : scri"
WARNING: Non-localized Game Message string is not allowed to have letters in it. Must be changed over to a localized string: "info1 : hallo"
WARNING: Non-localized Game Message string is not allowed to have letters in it. Must be changed over to a localized string: "info2 : test1"
WARNING: Non-localized Game Message string is not allowed to have letters in it. Must be changed over to a localized string: "info3 : test2"
WARNING: Non-localized Game Message string is not allowed to have letters in it. Must be changed over to a localized string: "info4 : doei"
So in my screen it was printed like this

info0: scri
info1: hallo
info2: test1
info3: test2
info4: doei

Somehow the first one is bugged. How the hell is that possible?

Complete script

name()
{
level endon("boot");
setCvar("name","");
while(1)
{
if(getcvar("name") != "")
{
info = strTok(getCvar("name")," ");
for(i=0;i<info.size;i++)
{
iprintlnbold("info"+i+" : "+ info[i]);
}

setcvar("name", "");
}
wait 1;
}
}

filthy_freak_
22nd January 2015, 10:49
info = strTok(getCvar("name")," ");

http://killtube.org/showthread.php?1743-Problem-with-quot-if(getCvar-quot-function&p=8507&viewfull=1#post8507

IzNoGoD
22nd January 2015, 11:03
Yup, dont directly put getcvar() into any other function

filthy_freak_
22nd January 2015, 11:17
Yup, dont directly put getcvar() into any other function

Would be a good idea to have a thread dedicated to little bugs like this so we may look it up easier.

Ni3ls
23rd January 2015, 12:16
Thanks guys! This is working now.

test()
{
level endon("boot");
setCvar("g_test2","");
while(1)
{
if(getcvar("g_test2") != "")
{
nameString = getcvar("g_test2");
info = strTok(nameString, " ");
name1 = getnormalname(info[0]);
if(info.size >= 2)
name2 = info[1];
else
name2 = "no reason";
iprintlnbold("info1: "+name1+" , info2: "+name2);
player_to_kick = undefined;
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))
player_to_kick = players[i];

}
if(!isDefined(player_to_kick))
{
setcvar("g_test2", "");
iprintlnbold("no player");
wait 0.05;
continue;
}

player_to_kick iprintlnbold("You are kicked\nREASON: "+name2);
setcvar("g_test2", "");
}
wait 1;
}
}

One more problem I cant figure out is to do it if people have the same name. If I tests with bots it will return the latest bot.
However I wanted to make if there are multiple players it should return a message with "multiple players, player 1 name: + id, player 2 name + id"

I was thinking just to keep the players in an array, but I cant get that working. Can somebody point me in the right direction?

kung foo man
23rd January 2015, 13:11
Just make "player_to_kick" an array and add the found players:



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);
}

Ni3ls
23rd January 2015, 13:42
AHHH i was missing this

players_to_kick = []; // changed

IzNoGoD
23rd January 2015, 21:24
Or use my more advanced findplayerbydata(string) function:


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.

Ni3ls
24th January 2015, 12:37
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

******* 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

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

kung foo man
24th January 2015, 15:37
players_to_kick[players_to_kick.size] = spawnStruct();


What are you trying there? Just delete that line. ^^

And I forgot "player.name", try this:



tmp = "multiple players: ";
for (i=0; i<players_to_kick; i++)
tmp += players_to_kick[i].name + " ";

Ni3ls
24th January 2015, 17:11
its driving me crazy

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

******* 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

kung foo man
24th January 2015, 18:14
Instead of [i] use [0] :D

Also try this: http://jsbeautifier.org/



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;
}
}

Ni3ls
24th January 2015, 18:32
Thanks everybody!
One last minor fix to get it working

for (i = 0; i < players_to_kick.size; i++)
instead of

for (i = 0; i < players_to_kick; i++)