Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: potential infinite loop in script

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    potential infinite loop in script

    PHP Code:
    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(namename1))
                        
    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;
        }

    PHP Code:
    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
    PHP Code:
        setCvar("g_test2","");
        while(
    1)
        { 
    and sometimes in the
    PHP Code:
                players getentarray("player","classname");
                for(
    i=0;i<players.size;i++)
                { 
    How to fix this damned thing?

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    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.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (15th January 2015)

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    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

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Thats due to your continue not resetting the g_test2 cvar to an empty string, thus locking the loop
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    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

  7. #6
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    This is how I do it:

    Replace the first menuDef in main.menu with this;
    Code:
    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
    Code:
    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;
    Code:
    	self setClientCvar("serv_kick_reason", "Reason: testing");
    	self setClientCvar("serv_kick_length", "");
    	self setClientCvar("serv_kicked", "1");
    	kick(self getentitynumber());
    Results:



    I use this with libcod b3 commands. Example: !ban <player> <reason>
    Last edited by filthy_freak_; 16th January 2015 at 15:23.

  8. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    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.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. #8
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by IzNoGoD View Post
    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
    Code:
                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]); 
    	    }

  10. #9
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by filthy_freak_ View Post
    This is how I do it:

    Replace the first menuDef in main.menu with this;
    Code:
    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
    Code:
    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;
    Code:
    	self setClientCvar("serv_kick_reason", "Reason: testing");
    	self setClientCvar("serv_kick_length", "");
    	self setClientCvar("serv_kicked", "1");
    	kick(self getentitynumber());
    Results:



    I use this with libcod b3 commands. Example: !ban <player> <reason>
    But that is only to show the message in that black box right?

  11. #10
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Quote Originally Posted by Ni3ls View Post
    But that is only to show the message in that black box right?
    Ya.

    10char

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •