stock GetClosestVehicle(playerid, Float:range)
{
new Float:p_X;
new Float:p_Y;
new Float:p_Z;
new Float:Distance;
new Float:PretendentDistance = range +1;
new Pretendent;
GetPlayerPos(playerid, p_X, p_Y, p_Z);
for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++)
{
Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z);
if(Distance <= range && Distance <= PretendentDistance)
{
Pretendent = vehicleid;
PretendentDistance = Distance;
}
}
return Pretendent;
}
for(new vehicleid=0; vehicleid < MAX_VEHICLES; vehicleid++)
new Float:PretendentDistance = range +1; // creates a variable that has the range + 1;
if(Distance <= range && Distance <= PretendentDistance) // checks if the vehicle is within the normal range, and within the range of the normal range +1;
new Float:p_X;
new Float:p_Y;
new Float:p_Z;
new Float:Distance;
new Float:PretendentDistance = range +1;
new Pretendent;
new
Float:p_X,
Float:p_Y,
Float:p_Z,
Float:Distance,
Float:PretendentDistance = range +1,
Pretendent
;
|
I wonder why you start with vehicleid 1, instead of 0, vehicle ids start with 0, not with one, so what you should be using is:
|
|
False. Vehicleids do start at 1. This is probably done to give GetPlayerVehicleID a proper return value.
|
|
False. Vehicleids do start at 1. This is probably done to give GetPlayerVehicleID a proper return value.
|
|
I wonder why you start with vehicleid 1, instead of 0, vehicle ids start with 0, not with one, so what you should be using is:
pawn Code:
not sure if this will fix it, but the rest of the code seems fine to me; this is the only thing I could find. tho, I also wonder why you do this: pawn Code:
also, you should change this pawn Code:
pawn Code:
|
new testrsadas[128]; format(testrsadas,sizeof(testrsadas),"masina cea mai apropriata %i",GetClosestVehicle(playerid, 10)); SendClientMessage(playerid,0xFF0000FF, testrsadas);
GetClosestVehicle(playerid, Float: range)
{
new
vehicleid = INVALID_VEHICLE_ID,
Float: pX,
Float: pY,
Float: pZ,
Float: distance = 9999.0,
Float: tmp_distance;
GetPlayerPos(playerid, pX, pY, pZ);
for (new v = 1; v != MAX_VEHICLES; ++v)
{
if (!GetVehicleModel(v)) continue;
tmp_distance = GetVehicleDistanceFromPoint(v, pX, pY, pZ);
if (tmp_distance <= range && tmp_distance < distance)
{
distance = tmp_distance;
vehicleid = v;
}
}
return vehicleid;
}