How to check the nearest vehicle
#1

Allright, so I need to check what vehicle that is the nearest to a player. I need this for my /carlock command.
I also need to know how to make that if the nearest one is more than for example 5 metres away it will just return 1;.
Reply
#2

pawn Код:
public Naechstecar(playerid, Float:radius)
{
    new Float:SpielerX, Float:SpielerY, Float:SpielerZ, Float:CarX, Float:CarZ, Float:CarY;
    GetPlayerPos(playerid, SpielerX, SpielerY, SpielerZ);
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        GetVehiclePos(i, CarX, CarY, CarZ);
        if((floatabs(SpielerX-CarX)<radius)&&(floatabs(SpielerY-CarY)<radius)&&(floatabs(SpielerZ-CarZ)<radius))
        {
            return i;
        }
    }
    return false;
}
^^
Reply
#3

Thank you GooMan. Do I use it like

Код:
if(GetNearestCar(playerid, < 5 ))   ?
I changed it to GetNearestCar :P
Reply
#4

pawn Код:
GetNearestCar(playerid,5)
Reply
#5

Quote:
Originally Posted by GooMan
Посмотреть сообщение
pawn Код:
public Naechstecar(playerid, Float:radius)
{
    new Float:SpielerX, Float:SpielerY, Float:SpielerZ, Float:CarX, Float:CarZ, Float:CarY;
    GetPlayerPos(playerid, SpielerX, SpielerY, SpielerZ);
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        GetVehiclePos(i, CarX, CarY, CarZ);
        if((floatabs(SpielerX-CarX)<radius)&&(floatabs(SpielerY-CarY)<radius)&&(floatabs(SpielerZ-CarZ)<radius))
        {
            return i;
        }
    }
    return false;
}
^^
This will actually get the first car that is in radius of 5 points from the player, not the nearest.
And use..
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, radius, CarX, CarY, CarZ))
.. it's faster.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)