24.08.2012, 00:58
That code didnt work, it returned the vehicleid even when i was outside of the range. Thanks for trying though!
Anyway i got what i've wanted + some more!
All credits and thanks goes to Pottus, for making such a multi-function, thanks dyyd!
Usage:
Anyway i got what i've wanted + some more!
All credits and thanks goes to Pottus, for making such a multi-function, thanks dyyd!
Usage:
pawn Код:
new vehicleID, Float:distance;
GetNearestVehicleEx(playerid, 5.0, true, vehicleID, distance);
if(vehicleID == INVALID_VEHICLE_ID) return SendClientMessage(playerid, -1, "You are not near any vehicle.");
printf("%f meters distance from a player");
printf("Vehicle ID: %d is closest in a range of 5meters");
pawn Код:
stock GetNearestVehicleEx(playerid, Float:distance, StreamedOnly, &retElement, &Float:retDistance)
{
new
Float:xX,
Float:yY,
Float:zZ,
Float:tempdist;
retDistance = 0.0;
retElement = INVALID_VEHICLE_ID;
for(new i = 1; i < MAX_VEHICLES; i++)
{
if(StreamedOnly == 1) { if(!IsVehicleStreamedIn(i, playerid)) continue; }
GetVehiclePos(i, xX, yY, zZ);
tempdist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ);
if(distance > 0.0)
{
if(tempdist < distance)
{
if(retDistance == 0.0)
{
retDistance = tempdist;
retElement = i;
}
else if(tempdist < distance)
{
retDistance = tempdist;
retElement = i;
}
}
}
else
{
if(retDistance == 0.0)
{
retDistance = tempdist;
retElement = i;
}
else
{
if(tempdist < retDistance)
{
retDistance = tempdist;
retElement = i;
}
}
}
}
}