Foreach. - 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)
+--- Thread: Foreach. (
/showthread.php?tid=388023)
Foreach. -
budelis - 27.10.2012
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.
Re: Foreach. -
ryansheilds - 28.10.2012
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.
Re: Foreach. - rjjj - 28.10.2012
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

.