A vehicle near a vehicle?
#1

hello,
Is there a way or function which can let me know distance between 2 vehicles of which one is occupied and the other is unoccupied.
For example if there is a occupied vehicle A near unoccupied vehicle B, the player presses CTRL and something happens.
Reply
#2

When you create a vehicle, it gets a unique id. Like when I spawn a NRG its id will be 217 and when I spawn another NRG, its id will be 218. So you can use the function GetPlayerVehicleID and use the stored ID which you spawned. Then find the distance between them by creating a point at it. Hope you got it.
Reply
#3

Good idea but i can't use that because i want if a player brings his vehicle near some other vehicle and presses fire something happens. I don't want to calculate distance between 2 SPECIFIC vehicles.
Reply
#4

i've made that, this should return the distance and the id of the vehicle.with this, u can do whatever you want.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:distance,id;
    nearestvehicle(vehicleid,distance,id);
    printf(#distance:%f - vehicleid: %d,distance,id);
    // lets check if the car is empty.
    for( new i; i  < MAX_PLAYERS; ++i)
    {
       if(IsPlayerInVehicle(i, id))
       {
          // stuff.
       }
    }
    return 1;
}
nearestvehicle(vehicleid,&Float:distance = 99999.9,&id = -1)
{
   new Float:x,Float:y,Float:z;
   GetVehiclePos(vehicleid,x,y,z); // we get the pos o your vehicle.
   for(new a = 1; a < MAX_VEHICLES;++a)
   {
       if(distance > GetVehicleDistanceFromPoint(a,x,y,z)) // if it's less.
       {
           distance = GetVehicleDistanceFromPoint(a,x,y,z); // we just replace it.
           id = a; // same for car id.
       }
   }
   return distance,id; // return the distance,and the id.
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)