Foreach... F**ks everything up..
#3

Foreach is faster and simpler than a regular loop. Indent your code properly and the issue is easily visible.

pawn Код:
public Spectator()
{
    foreach (Player, i)
    {
        if(PlayerInfo[i][pAdmin] >= 1 && Specing[i] == 1)
        {
            SetPlayerColor(i,COLOR_SPEC);
            TogglePlayerControllable(i, 0);
            new targetid = Spectate[i];
            if(IsPlayerConnected(targetid))
            {
                TogglePlayerSpectating(i, 1);
                if(PlayerInfo[i][pAdmin] >= 1)
                {
                   
                    if(IsPlayerInAnyVehicle(targetid))
                    {
                        new carid = GetPlayerVehicleID(targetid);
                        PlayerSpectateVehicle(i, carid);
                    }
                    else
                    {
                        PlayerSpectatePlayer(i, targetid);
                    }
                    if(GetPlayerInterior(targetid) != GetPlayerInterior(i))
                    {
                        SetPlayerInterior(i,0);
                    }
                }
            }
            if(Spectate[i] == 254)
            {
                TogglePlayerControllable(i, 1);
                SetPlayerInterior(i,Unspec[i][sPint]);
                PlayerInfo[i][pInt] = Unspec[i][sPint];
                PlayerInfo[i][pLocal] = Unspec[i][sLocal];
                SetPlayerPos(i, Unspec[i][sPx],  Unspec[i][sPy], Unspec[i][sPz]);
                Spectate[i] = 255;
            }
            if(Spectate[i] == 256)
            {
                SetPlayerToTeamColor(i);
                Spectate[i] = 255;
            }
            if(Spectate[i] == 257)
            {
                Spectate[i] = 254;
            }
        }
    }
}
Reply


Messages In This Thread
Foreach... F**ks everything up.. - by GaGlets(R) - 01.08.2010, 06:17
Re: Foreach... F**ks everything up.. - by Kar - 01.08.2010, 06:19
Re: Foreach... F**ks everything up.. - by bigcomfycouch - 01.08.2010, 06:43
Re: Foreach... F**ks everything up.. - by GaGlets(R) - 01.08.2010, 06:49
Re: Foreach... F**ks everything up.. - by GaGlets(R) - 01.08.2010, 08:12

Forum Jump:


Users browsing this thread: 2 Guest(s)