SA-MP Forums Archive
Function: while, freezing server - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Function: while, freezing server (/showthread.php?tid=425760)



Function: while, freezing server - CoaPsyFactor - 26.03.2013

I am not able to find what is wrong here, but every time player use command /b or any chat server freezes, here is code that should SendClientMessage

pawn Код:
Loop = 0;
    while(Loop < MAX_PLAYERS){
        if(IsPlayerConnected(Loop) && Int == GetPlayerInterior(Loop) && Viwo == GetPlayerVirtualWorld(Loop)){
            if(PlayerNearPlayer(playerid, Loop, radius/16)){
                if(Num < 2) SendClientMessage(Loop, color1, message);
                else {
                    while(i < Num){
                        if(i) format(Message, 92, "...%s", message[(i*64)+1]);
                        else format(Message, 67, "%.64s...", message);
                        SendClientMessage(Loop, color1, Message);
                        i++;
                    }
                }
            }else if(PlayerNearPlayer(playerid, Loop, radius/8)){
                if(Num < 2) SendClientMessage(Loop, color2, message);
                else {
                    i = 0;
                    while(i < Num){
                        if(i) format(Message, 92, "...%s", message[(i*64)+1]);
                        else format(Message, 67, "%.64s...", message);
                        SendClientMessage(Loop, color2, Message);
                        i++;
                    }
                }
            }else if(PlayerNearPlayer(playerid, Loop, radius/4)){
                if(Num < 2) SendClientMessage(Loop, color3, message);
                else {
                    i = 0;
                    while(i < Num){
                        if(i) format(Message, 92, "...%s", message[(i*64)+1]);
                        else format(Message, 67, "%.64s...", message);
                        SendClientMessage(Loop, color3, Message);
                        i++;
                    }
                }
            }else if(PlayerNearPlayer(playerid, Loop, radius/2)){
                if(Num < 2) SendClientMessage(Loop, color4, message);
                else {
                    i = 0;
                    while(i < Num){
                        if(i) format(Message, 92, "...%s", message[(i*64)+1]);
                        else format(Message, 67, "%.64s...", message);
                        SendClientMessage(Loop, color4, Message);
                        i++;
                    }
                }
            }else if(PlayerNearPlayer(playerid, Loop, radius)){
                if(Num < 2) SendClientMessage(Loop, color5, message);
                else {
                    i = 0;
                    while(i < Num){
                        if(i) format(Message, 92, "...%s", message[(i*64)+1]);
                        else format(Message, 67, "%.64s...", message);
                        SendClientMessage(Loop, color5, Message);
                        i++;
                    }
                }
            }  
        }
        Loop++;
    }
and HERE is txt file with same function, but one is with while and other is with for, the one with for works fine.


Re: Function: while, freezing server - CoaPsyFactor - 27.03.2013

bump


Re: Function: while, freezing server - judothijs - 27.03.2013

Adjust the loop to this:
pawn Код:
for (new loop = 0; loop < MAX_PLAYERS; loop++;)
{
      // your stuff
}
You had loop = 0 standing loose in your script, which would basically put it back to 0 every time, which would cause an infinite loop, crashing your server.


Re: Function: while, freezing server - CoaPsyFactor - 27.03.2013

there is no loop=0 in while so there is no infinite loop, although there is problem where more than 5 players are online