YCMD:closestcar(playerid, params[], help) {
if(!PlayerInfo[playerid][pAdmin]) return SCM(playerid, -1, AdminOnly);
new vehicle = GetClosestVehicle2(playerid); gString[0] = (EOS);
if(vehicle == INVALID_VEHICLE_ID) return SCM(playerid, COLOR_GREY, "Nu e nici un vehicul in apropierea ta.");
PutPlayerInVehicleEx(playerid, vehicle, 0);
return 1;
}
stock GetClosestVehicle2(playerid) {
new Float: Distance;
if(!Distance) Distance = 200.0;
new Float:X[2], Float:Y[2], Float:Z[2], Float:NearestPos = floatabs(Distance), NearestVehicle = INVALID_VEHICLE_ID;
GetPlayerPos(playerid, X[0], Y[0], Z[0]);
for(new i; i < MAX_VEHICLES; i++) {
if(!IsVehicleStreamedIn(i, playerid) || IsPlayerInVehicle(playerid, i)) continue;
GetVehiclePos(i, X[1], Y[1], Z[1]);
if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
}
return NearestVehicle;
}