stock GetNearestVehicle(playerid, Float:distance)
{
new
Float:xX,
Float:yY,
Float:zZ,
retElement = -1
;
for(new i = 0; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i, xX, yY, zZ);
new Float:odist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ);
if (retElement == -1)
{
retElement = i;
distance = odist;
}
else if (odist < distance)
{
retElement = i;
distance = odist;
}
}
return retElement;
}
GetNearestVehicle(playerid, 66);
it brings to you the nearest vehicle. i think, because that's what happens in the mod sobit
|
It allows you to search in an area I believe,
like pawn Код:
|
Because if the nearest vehicle is 67 units away, the function will fail to find a vehicle.
|
stock GetNearestVehicle(playerid, Float:distance) { new Float:xX, Float:yY, Float:zZ, retElement = -1 ; for(new i = 0; i < MAX_VEHICLES; i++) { GetVehiclePos(i, xX, yY, zZ); new Float:odist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ); if (retElement == -1) { retElement = i; distance = odist; } else if (odist < distance) { retElement = i; distance = odist; } else if (odist > distance) { return -1; } } return retElement; }
Look at the code, it shows you what it's suppose to do if it doesn't find a vehicle within 66 units.
It will just return the ID of the last vehicle looped through. This will return -1 if there is no vehicle within 66 units. Код:
stock GetNearestVehicle(playerid, Float:distance) { new Float:xX, Float:yY, Float:zZ, retElement = -1 ; for(new i = 0; i < MAX_VEHICLES; i++) { GetVehiclePos(i, xX, yY, zZ); new Float:odist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ); if (retElement == -1) { retElement = i; distance = odist; } else if (odist < distance) { retElement = i; distance = odist; } else if (odist > distance) { return -1; } } return retElement; } |
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");
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;
}
}
}
}
}