How to detect if a Player Is Near Any Vehicle?
#1

[SOLVED]
Reply
#2

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;
}
Reply
#3

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))
Reply
#4

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

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"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)