Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: potential infinite loop in script

  1. #21
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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(namename1)) 
                        
    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=0i<players_to_kicki++)
                        
    tmp += players_to_kick[i] + " ";
                    
    iprintlnbold(tmp);
                } 
    timescale 0.01

  2. #22
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    AHHH i was missing this
    Code:
    players_to_kick = [];  // changed

  3. #23
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Or use my more advanced findplayerbydata(string) function:
    PHP Code:
    findplayerbydata(string)
    {
        if(!
    isdefined(string))
            return 
    undefined;
        
    string stripcolors(tolower(string));

        
    tmp "";
        for(
    0string.sizei++)
        {
            if(
    isint(string[i]))
                
    tmp += string[i];
            else
            {
                if(
    string[i] != " ")
                
    tmp "";
                break;
            }
        }
        
    players getentarray("player""classname");
        if(
    tmp != "")
        {
            for(
    0players.sizei++)
            {
                if(!
    isdefined(players[i].izno) || !isdefined(players[i].izno["login_completed"]))
                    continue;
                if(
    players[igetentitynumber() == 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(
    0players.sizei++)
        {
            
    score 0;
            
    previous_correct_char = -1;
            
    name stripcolors(tolower(players[i].name));
            
    found false;
            for(
    0name.size string.size 1j++)
            {
                
    tmp getsubstr(namejstring.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(
    0name.sizej++)
                {
                    for(
    0string.sizek++)
                    {
                        if(
    isdefined(used[k]))
                            continue;
                        if(
    name[j] == string[k])
                        {
                            
    used[k] = true;
                            if(
    == 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.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    Ni3ls (24th January 2015)

  5. #24
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    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[iiprintlnbold("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(namename1)) 
                        
    players_to_kick[players_to_kick.size] = players[i]; // changed

                
    }

                
    // changed:
                
    if(players_to_kick.size == 2
            {
                    
    players_to_kick[iiprintlnbold("You are kicked, REASON: "+name2); 
                } 
            else if(
    players_to_kick.size >= 2
              {
                    
    tmp "multiple players: ";
                    for (
    i=0i<players_to_kicki++)
                        
    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
    Last edited by Ni3ls; 24th January 2015 at 13:40.

  6. #25
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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=0i<players_to_kicki++)
                        
    tmp += players_to_kick[i].name " "
    timescale 0.01

  7. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (24th January 2015)

  8. #26
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    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(namename1)) 
                        
    players_to_kick[players_to_kick.size] = players[i]; // changed

                
    }

                
    // changed:
                
    if(players_to_kick.size == 1
            {
                    
    players_to_kick[iiprintlnbold("You are kicked, REASON: "+name2); 
                } 
            else if(
    players_to_kick.size >= 2
              {
                    
    tmp "multiple players: ";
                    for (
    i=0i<players_to_kicki++)
                        
    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

  9. #27
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Instead of [i] use [0]

    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 (
    0players.sizei++) {
                    
    name getnormalname(players[i].name);
                    if (
    name == name1 || isSubStr(namename1))
                        
    players_to_kick[players_to_kick.size] = players[i]; // changed

                
    }

                
    // changed:
                
    if (players_to_kick.size == 1) {
                    
    players_to_kick[0iprintlnbold("You are kicked, REASON: " name2);
                } else if (
    players_to_kick.size >= 2) {
                    
    tmp "multiple players: ";
                    for (
    0players_to_kicki++)
                        
    tmp += players_to_kick[i].name " ";
                    
    iprintlnbold(tmp);
                } else {
                    
    iprintlnbold("NO PLAYER");
                }
                
    setcvar("g_test2""");
            }
            
    wait 1;
        }

    timescale 0.01

  10. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (24th January 2015)

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

Posting Permissions

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