SA-MP Forums Archive
Foreach... F**ks everything up.. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Foreach... F**ks everything up.. (/showthread.php?tid=164616)



Foreach... F**ks everything up.. - GaGlets(R) - 01.08.2010

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);
                }
            }//Targetid connected
        }
        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;
        }
    }
}
Errors
Код:
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1646) : error 004: function "SetPlayerToTeamColor" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1658) : error 029: invalid expression, assumed zero
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1658) : error 004: function "OnPlayerEnterVehicle" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1660) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1662) : error 004: function "IsAnOwnableCar" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1664) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1668) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1669) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1672) : error 004: function "IsACopCar" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1674) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1679) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1680) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1683) : error 004: function "IsNgCar" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1685) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1690) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1691) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1694) : error 004: function "IsAnAmbulance" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1696) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1697) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1697) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1699) : error 004: function "IsATank" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1701) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1702) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1702) : error 017: undefined symbol "playerid"
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1704) : error 004: function "IsAHot" is not implemented
C:\DOCUME~1\User\Desktop\COPYOF~1\GAMEMO~1\larp.pwn(1706) : error 017: undefined symbol "playerid"
Everything was okey with this..
pawn Код:
public Spectator()
{
    for(new i = 0; i < MA_PL; i++) // MA_PL - my slot defination
    {
        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);
                }
            }//Targetid connected
        }
        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;
        }
    }
}



Re: Foreach... F**ks everything up.. - Kar - 01.08.2010

why use foreach?


Re: Foreach... F**ks everything up.. - bigcomfycouch - 01.08.2010

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;
            }
        }
    }
}



Re: Foreach... F**ks everything up.. - GaGlets(R) - 01.08.2010

Hellooo.. i want to fix this..

Ahmm.. I am tired to search but i havent sleep some days.. so main main wont let me to think..

(Returns wont help)




Re: Foreach... F**ks everything up.. - GaGlets(R) - 01.08.2010

oh yeah.. Loled when saw.. I said.. havent sleep for a long time