Loop issue
#2

pawn Код:
if(strcmp(cmd, "/getcarid", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            new Float:x,Float:y,Float:z;
            for(new c = 0; c < sizeof(CarInfo); c++)
            {
                GetVehiclePos(CarInfo[c][cID], x, y, z);
                if(PlayerToPoint(3, playerid, x, y, z))
                {
                    format(string, sizeof(string), "Car ID: %d", CarInfo[c][cID]);
                    SendClientMessage(playerid, COLOR_WHITE, string);
                    return 1;
                }
            }
            SendClientMessage(playerid, COLOR_RED, "You are not near any Car Ownership vehicle.");
            return 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Only admins with Adm Level 4 can use this command.");
            return 1;
        }
    }
    return 1;
}
The problem was that you used return even if the player wasn't near to the vehicle, it made the loop stop in the first loop. I moved that return outside the loop, so it says that message AFTER it has gone through the whole loop.

Also I moved floats x, y and z outside the loop, so it won't create them again and again. Saves time.
Reply


Messages In This Thread
Loop issue - by Dujma - 21.02.2009, 09:55
Re: Loop issue - by Finn - 21.02.2009, 10:44
Re: Loop issue - by Dujma - 21.02.2009, 10:48
Re: Loop issue - by yom - 21.02.2009, 10:55
Re: Loop issue - by Dujma - 21.02.2009, 10:58
Re: Loop issue - by yom - 21.02.2009, 11:01
Re: Loop issue - by Dujma - 21.02.2009, 11:03

Forum Jump:


Users browsing this thread: 1 Guest(s)