11.11.2010, 14:15
I was searching an stock like this but i couldnt find it, does someone have this? and it should return vehicle id!
CMD:test(playerid,params[]){ new TimerOld=GetTickCount(); new VehID; new Dist,DistLower=8500,DistLowerSA; new Float:X,Float:Y,Float:Z; new Float:pX,Float:pY,Float:pZ; new XX,YY,ZZ; new sXX,sYY,sZZ; GetPlayerPos(playerid,pX,pY,pZ); for(new v=0;v<MAX_VEHICLES;v++) { if(IsPlayerInVehicle(playerid,v)==1) continue; GetVehiclePos(v,X,Y,Z); if(IsPlayerInRangeOfPoint(playerid,DistLower,X,Y,Z)) { XX=floatround(X-pX,floatround_floor); YY=floatround(Y-pY,floatround_floor); ZZ=floatround(Z-pZ,floatround_floor); sXX=XX*XX; sYY=YY*YY; sZZ=ZZ*ZZ; DistLowerSA=sXX+sYY+sZZ; DistLower=floatround(floatsqroot(DistLowerSA),floatround_floor); VehID=v; } } new TimerNew=GetTickCount(); new string[48]; format(string,sizeof(string),"Closest Veh:%d Dist:%d ms:%d",VehID,DistLower,TimerNew-TimerOld); SendClientMessage(playerid,0x33cc33ff,string); return VehID; }
stock GetClosestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}