SA-MP Forums Archive
How to check the nearest vehicle - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to check the nearest vehicle (/showthread.php?tid=158253)



How to check the nearest vehicle - Mystique - 09.07.2010

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


AW: How to check the nearest vehicle - GooMan - 09.07.2010

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;
}
^^


Re: How to check the nearest vehicle - Mystique - 09.07.2010

Thank you GooMan. Do I use it like

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


Re: How to check the nearest vehicle - Hiddos - 09.07.2010

pawn Код:
GetNearestCar(playerid,5)



Re: AW: How to check the nearest vehicle - CaHbKo - 09.07.2010

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.