GetNearestVehicle modification -
Jstylezzz - 04.08.2012
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
Re: GetNearestVehicle modification -
[KHK]Khalid - 04.08.2012
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.
Re: GetNearestVehicle modification -
Jstylezzz - 04.08.2012
Lol, thanks alot man, i think i was thinking too difficult
![Smiley](images/smilies/smile.png)
thanks
Respuesta: Re: GetNearestVehicle modification -
HarlemSAMP - 04.08.2012
Quote:
Originally Posted by Jari_Johnson*
Lol, thanks alot man, i think i was thinking too difficult ![Smiley](images/smilies/smile.png)
thanks
|
That's the main problem with good coders, sometimes they think too difficult and forget the basic stuff xD glad you got helped