Vehicle in Rage of Vehicle?
#1

Hey, how can I check if is a vehicle in rage of another vehicle ?
Reply
#2

what do you mean?
Reply
#3

He means is V1 in range of V2, which is simply getting each vehicles position calculating the distance between the two then checking if they are in the specified range.

pawn Код:
stock IsVehicleInRangeOfVehicle(VehicleID_1, VehicleID_2, Float:range)
{
    if(IsVehicleValid(VehicleID_1) && IsVehicleValid(VehicleID_2))
    {
        new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
        GetVehiclePos(VehicleID_1, x1, y1, z1);
        GetVehiclePos(VehicleID_2, x2, y2, z2);
        if(range <= floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) ) return 1;
    }
    return 0;
}
Reply
#4

Searched a bit and found this:
pawn Код:
forward Float:GetDistanceBetweenVehicles(vehicleid,carid);
public Float:GetDistanceBetweenVehicles(vehicleid,carid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    GetVehiclePos(vehicleid,x1,y1,z1);
    GetVehiclePos(carid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
Untested.
Reply
#5

ocmd:test(playerid,params[])
{
if(GetDistanceBetweenVehicles(vehicleid,carid,<20) ;
{
SendClientMessage(player,white,"Test");
}
}
return 1;
}

How must I use it ?
Reply
#6

Quote:
Originally Posted by zxc1
Посмотреть сообщение
Searched a bit and found this:
pawn Код:
forward Float:GetDistanceBetweenVehicles(vehicleid,carid);
public Float:GetDistanceBetweenVehicles(vehicleid,carid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    GetVehiclePos(vehicleid,x1,y1,z1);
    GetVehiclePos(carid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
Untested.
He asked for the range not the distance.
Reply
#7

yeah
Reply
#8

noboy can help me ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)