31.10.2010, 01:29
pawn Код:
forward VehicleToPlayer(playerid,vehicleid);
public VehicleToPlayer(playerid,vehicleid)
{
new Float:pX,Float:pY,Float:pZ,Float:cX,Float:cY,Float:cZ,Float:distance;
GetPlayerPos(playerid,pX,pY,pZ);
GetVehiclePos(vehicleid,cX,cY,cZ);
distance = floatsqroot(floatpower(floatabs(floatsub(cX,pX)),2) + floatpower(floatabs(floatsub(cY,pY)),2) + floatpower(floatabs(floatsub(cZ,pZ)),2));
return floatround(distance);
}
forward GetClosestVehicle(playerid);
public GetClosestVehicle(playerid)
{
new Float:distance = 99999.000+1,Float:distance2,result = -1;
for(new i = 0; i < MAX_VEHICLES; i++)
{
distance2 = VehicleToPlayer(playerid,i);
if(distance2 < distance)
{
distance = distance2;
result = i;
}
}
return result;
}
stock GetXYBehindOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
new
Float:a;
GetVehiclePos( vehicleid, x, y, a );
GetVehicleZAngle( vehicleid, a );
x += ( distance * floatsin( -a+180, degrees ));
y += ( distance * floatcos( -a+180, degrees ));
}