Loop - 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: Loop (
/showthread.php?tid=522282)
Loop -
babecka - 26.06.2014
Hello!
I have this loop in my script:
PHP код:
for(new i; i <MAX_VEHICLES; i ++)
{
if(Occupied[i] == false)
{
PutPlayerInVehicle(playerid, Vehicles[random(2)], 0);
Occupied[i] = true;
}
}
The loop loops thru all vehicles and checks whetever they're occpupied or not. If not, a random vehicle is picked and the player is put in it, however there is one problem: I need to make that vehicle occupied, so no one can be put in it.
Above you can see that the loop sets all vehicles to occupied. My problem is, I don't know how to recognize the random vehicle the player was put in.
Thank you for help!
Re: Loop -
Vince - 26.06.2014
https://sampwiki.blast.hk/wiki/Keywords:Statements#break
Re: Loop -
babecka - 26.06.2014
I am not sure if this code - in matters of logic - is correct or not, but it is working.
PHP код:
for(new i; i <MAX_VEHICLES; i ++)
{
if(Occupied[i] == false)
{
PutPlayerInVehicle(playerid, Vehicles[random(2)], 0);
Occupied[i] = true;
if(Occupied[Vehicles[random(2)]] == true)
{
break;
}
}
}
Or is it false?