Find more than one nearby vehicle? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Find more than one nearby vehicle? (
/showthread.php?tid=534867)
Find more than one nearby vehicle? -
austin070 - 31.08.2014
I'm using this to find one nearest vehicle, but how can I convert it to find all vehicles in a given range?
pawn Код:
stock GetNearestVehicle(playerid, Float:range)
{
new Float:x, Float:y, Float:z, Float:Distance;
new nearbyveh = -1;
for(new i=1; i < MAX_VEHICLES+1; i++)
{
if(i == GetPlayerVehicleID(playerid)) continue;
GetVehiclePos(i, x, y, z);
Distance = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(Distance <= range)
{
nearbyveh = i;
range = Distance;
}
}
return nearbyveh;
}
Re: Find more than one nearby vehicle? -
jakejohnsonusa - 31.08.2014
Do you need to find all the vehicleid's or just the number of vehicles in a given range?
Re: Find more than one nearby vehicle? -
austin070 - 31.08.2014
All of the vehicleids in a given range.
Re: Find more than one nearby vehicle? -
jakejohnsonusa - 31.08.2014
How do you want to use them afterwards, since there are various ways of doing this?
You could add each vehicle ID to a string, but I'm not sure why you would want to get each ID...?
Re: Find more than one nearby vehicle? -
austin070 - 31.08.2014
Quote:
Originally Posted by jakejohnsonusa
How do you want to use them afterwards, since there are various ways of doing this?
You could add each vehicle ID to a string, but I'm not sure why you would want to get each ID...?
|
I'm making a radar command that catches the speed of all the vehicles in a given radius.
AW: Find more than one nearby vehicle? -
Nero_3D - 31.08.2014
Just use a loop with IsPlayerInRangeOfPoint
pawn Код:
new
v,
Float: X,
Float: Y,
Float: Z
;
while(++v < MAX_VEHICLES) {
if(GetVehiclePos(v, X, Y, Z) && IsPlayerInRangeOfPoint(playerid, 30.0, X, Y, Z)) {
// your code
}
}
That would return all vehicles in 30.0 radius of the player