GetNearestVehicle modification
#1

hello everyone,

I have a small question regarding this stock code:

pawn Код:
stock GetNearestVehicle(playerid, Float:dis)
{
    new Float:L, Float:O, Float:II;
    if(GetPlayerPos(playerid, L, O, II))
    {
        new vehicleid = INVALID_VEHICLE_ID;
        for(new v, Float:temp, Float:VL, Float:VO, Float:VII; v != MAX_VEHICLES; v++)
        {
            if(GetVehiclePos(v, VL, VO, VII))
            {
                VL -= L, VO -= O, VII -= II;
                temp = VL * VL + VO * VO + VII * VII;
                if(temp < dis) dis = temp, vehicleid = v;
            }
        }
        dis = floatpower(dis, 0.5);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}
It is working, that is not the problem, but when i am inside the vehicle, and use this function, offcoarse it returns the vehicle i am in, because it is the closest to me.
What i want to achieve here, is that it skips the vehicle the player is sitting in (if sitting in one), so it get's the closest vehicle to a vehicle(the vehicle the player is not sitting in).

I hope someone understands me, i can explain things chaotic sometimes, i know, but i hope someone can help me.
Thanks in advance
Reply
#2

Hmm just check if v is not the player's vehicle id:
pawn Код:
if(GetVehiclePos(v, VL, VO, VII) && v != GetPlayerVehicleID(playerid))
{
    VL -= L, VO -= O, VII -= II;
    temp = VL * VL + VO * VO + VII * VII;
    if(temp < dis)
     dis = temp, vehicleid = v;
}
Edit:

Just missed a thing. You might like to use IsPlayerInAnyVehicle first to check if the player is even in a vehicle.
Reply
#3

Lol, thanks alot man, i think i was thinking too difficult
thanks
Reply
#4

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
Lol, thanks alot man, i think i was thinking too difficult
thanks
That's the main problem with good coders, sometimes they think too difficult and forget the basic stuff xD glad you got helped
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)