Getting Closest vehicleid to player - 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: Getting Closest vehicleid to player (
/showthread.php?tid=407868)
Getting Closest vehicleid to player -
jakejohnsonusa - 15.01.2013
How do I get the vehicleid of the closest vehicle to a player? It's going to be for my RP GM's /scanlicenseplate command. So any ideas how to do this?
Thanks in advance!
Re: Getting Closest vehicleid to player -
Hoss - 15.01.2013
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) && v != GetPlayerVehicleID(playerid))
{
VL -= L, VO -= O, VII -= II;
temp = VL * VL + VO * VO + VII * VII;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 1.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
Re: Getting Closest vehicleid to player -
jakejohnsonusa - 15.01.2013
EDIT: OH this is a stock. So when I'm using under the " if(strcmp(cmd, "/scanlicenseplate", true) == 0) " how would I add it?
Re: Getting Closest vehicleid to player -
Hoss - 15.01.2013
I'll show u a example:
pawn Код:
CMD:repaircar(playerid, params[])
{
new nearest = GetNearestVehicle(playerid, 25.0); // It searches the nearest vehicle in radius of 25 metters
RepairVehicle(nearest); // Repairs Vehicle
return true;
}
Re: Getting Closest vehicleid to player -
jakejohnsonusa - 15.01.2013
Thanks! I'll try it now!