SA-MP Forums Archive
How to detect if a Player Is Near Any 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)
+--- Thread: How to detect if a Player Is Near Any Vehicle? (/showthread.php?tid=409761)



[SOLVED] - Vexus - 22.01.2013

[SOLVED]


Re: How to detect if a Player Is Near Any Vehicle? - Jefff - 22.01.2013

pawn Код:
stock GetClosestVehicleForPlayer(playerid)
{
    new
        Float:Pos[4],
        Float:DefaultDistance = 999999999.9,
        ClosestVehicleID = INVALID_VEHICLE_ID;

    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);

    for(new vehicleid = 1; vehicleid != MAX_VEHICLES; vehicleid++)
        if(IsValidVehicle(vehicleid))
        {
            Pos[3] = GetVehicleDistanceFromPoint(vehicleid,Pos[0],Pos[1],Pos[2]);
            if(Pos[3] < DefaultDistance)
            {
                DefaultDistance = Pos[3];
                ClosestVehicleID = vehicleid;
            }
        }

    return ClosestVehicleID;
}



Re: How to detect if a Player Is Near Any Vehicle? - Vexus - 23.01.2013

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
stock GetClosestVehicleForPlayer(playerid)
{
    new
        Float:Pos[4],
        Float:DefaultDistance = 999999999.9,
        ClosestVehicleID = INVALID_VEHICLE_ID;

    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);

    for(new vehicleid = 1; vehicleid != MAX_VEHICLES; vehicleid++)
        if(IsValidVehicle(vehicleid))
        {
            Pos[3] = GetVehicleDistanceFromPoint(vehicleid,Pos[0],Pos[1],Pos[2]);
            if(Pos[3] < DefaultDistance)
            {
                DefaultDistance = Pos[3];
                ClosestVehicleID = vehicleid;
            }
        }

    return ClosestVehicleID;
}
Many, many thanks for this, but how exactly am I to use this within the script?

Just like so?

pawn Код:
if (IsAValidVehicle(vehicleid))



Re: How to detect if a Player Is Near Any Vehicle? - Scenario - 23.01.2013

pawn Код:
if(GetClosestVehicleForPlayer(playerid) != INVALID_VEHICLE_ID)
Use it like this.


Re: How to detect if a Player Is Near Any Vehicle? - Vexus - 23.01.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
if(GetClosestVehicleForPlayer(playerid) != INVALID_VEHICLE_ID)
Use it like this.
Only error I got with that is

pawn Код:
C:\Users\Khloe\Desktop\Censored\Censored\gamemodes\Censored.pwn(3410) : error 017: undefined symbol "IsValidVehicle"