Function: while, freezing server
#1

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.
Reply
#2

bump
Reply
#3

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.
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)