02.11.2015, 20:19
Function stops working after "return".
Let's run your code:
We have2 vehicles:
ID 1 - far away from you
ID 2 - near you
Your script looks first at ID 1, then at ID 2. When it looks at ID 1 (the car is far away), it returns 1 and sends that message.
To do it right, you should do this in another way (for example, if you want to get the first car with smallest ID nearby):
Let's run your code:
We have2 vehicles:
ID 1 - far away from you
ID 2 - near you
Your script looks first at ID 1, then at ID 2. When it looks at ID 1 (the car is far away), it returns 1 and sends that message.
To do it right, you should do this in another way (for example, if you want to get the first car with smallest ID nearby):
PHP код:
new Float: P[3];
GetPlayerPos( playerid, P[0], P[1], P[2] );
new vehiclesNearby = 0;
for (new v; v < MAX_VEHICLES; v++) {
if ( GetVehicleDistanceFromPoint( v, P[0], P[1], P[2] ) <= Radius ) {
// There's a vehicle nearby
vehiclesNearby = 1;
break;
}
}
if ( vehiclesNearby == 0 ) {
SendClientMessage(playerid, -1, "Car isnt near");
} else {
SendClientMessage(playerid, -1, "Car near you. you can do what you wanna ");
// ...
}