Foreach.
#1

Hi, i use foreach include. I want to make i cycle through all vehicles what have a variable:

Код:
if( CARUSE[ i ] == 1 )
Because i have about 700 cars in server and i don't want to do cycle 700 times if this variable have only 5 cars.
Reply
#2

You will have to loop though all the vehicles, I don't think there's any other way.

You'll have to use:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
The foreach include is for players only, it's a efficient way of this:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) {
    if(IsPlayerConnected(i)) {
        // Code
    }
}
Edit: Ignore this - Inaccurate.
Reply
#3

Here is an example :


pawn Код:
new Iterator:CarUse<700>;



public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/usecar", true))
    {
        Iter_Add(CarUse, GetPlayerVehicleID(playerid) - 1);
        return 1;
    }
    if(!strcmp(cmdtext, "/stopusingcar", true))
    {
        Iter_Remove(CarUse, GetPlayerVehicleID(playerid) - 1);
        return 1;
    }
    if(!strcmp(cmdtext, "/carsbeingused", true))
    {
        foreach(CarUse, x)
        {
            printf("ID: %d", x + 1);
        }
        return 1;
    }
    return 0;
}


I hope that I have helped .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)