car check near player
#1

im always geting fist message car isnt near

Код:
if(IsPlayerInCheckpointEx(playerid, cpid))
    {
        new Float: P[3];
   GetPlayerPos(playerid,P[0],P[1],P[2]);
   for(new v; v < MAX_VEHICLES; v++)
   {
   if(GetVehicleDistanceFromPoint(v,P[0],P[1],P[2])<= Radius) return SendClientMessage(playerid, -1, "Car isnt near");
   {
        SendClientMessage(playerid, -1, "Car near you. you can do what you wanna ");
 
        DisablePlayerCheckpointEx(playerid, 0);
Reply
#2

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):
PHP код:
   new FloatP[3];
   
GetPlayerPosplayeridP[0], P[1], P[2] );

   new 
vehiclesNearby 0;
   for (new 
vMAX_VEHICLESv++) {
      if ( 
GetVehicleDistanceFromPointvP[0], P[1], P[2] ) <= Radius ) {
         
// There's a vehicle nearby
         
vehiclesNearby 1;
         break;
      }
   }

   if ( 
vehiclesNearby == ) {
      
SendClientMessage(playerid, -1"Car isnt near");
   } else {
      
SendClientMessage(playerid, -1"Car near you. you can do what you wanna ");
      
// ...
   

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)