SA-MP Forums Archive
car check near player - 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: car check near player (/showthread.php?tid=593206)



car check near player - Karolukas123 - 02.11.2015

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);



Re: car check near player - prineside - 02.11.2015

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 ");
      
// ...