new
Float: X2,
Float: Y2,
Float: X,
Float: Y,
Float: Z;
// Getting current player's position and the position infront of him
GetPlayerPos(playerid, X, Y, Z);
GetXYInFrontOfPlayer(playerid, X2, Y2, 2.0);
// Calculating the difference between the current possition and the position infront of the player
X = X - X2;
Y = Y - Y2;
// "Charging" him towards?
SetPlayerVelocity(playerid, X, Y, 0.2);
GetVehicleInfrontID (vehid)
{
new Float: temp = 7.0;
new j = 0;
for (new i = 1; i <= MAX_VEHICLES; i++)
{
new Float: a, Float: x1, Float: y1, Float: z1, Float: x2, Float: y2, Float: z2;
GetVehiclePos (vehid, x1, y1, z1);
GetVehicleZAngle (vehid, a);
if (i != vehid)
{
if (GetVehiclePos (i, x2, y2, z2))
{
new Float: distance = floatsqroot (floatpower ((x1 - x2), 2) + floatpower ((y1 - y2), 2) + floatpower ((z1 - z2), 2));
GetVehicleZAngle (vehid, a);
if (distance < 300.0)
{
x1 = x1 + (distance * floatsin(-a, degrees));
y1 = y1 + (distance * floatcos(-a, degrees));
distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2)));
if (temp > distance)
{
temp = distance;
j = i;
}
}
}
}
}
if (temp < 7.0) return j;
return -1;
}
First off all i thnik you gotta set the velocity like this: SetPlayerVeloCity(playerid, 0.2, 0.2, 0.2);
Second I have a script wich checks the speed of player infront of him when i got the thing out how i did it i will tell you Edit: This is to get vehicleid but since i see your post count i guess you know how to change it for anything pawn Код:
|
new
Float: a,
Float: x1,
Float: y1,
Float: z1,
Float: x2,
Float: y2,
Float: z2,
Float: distance;
GetPlayerPos(playerid, x1, y1, z1);
GetPlayerFacingAngle(playerid, a);
GetXYInFrontOfPlayer(playerid, x2, y2, 2.0);
//distance = floatsqroot (floatpower ((x1 - x2), 2) + floatpower ((y1 - y2), 2) + floatpower ((z1 - z2), 2));
//x1 = x1 + (distance * floatsin(-a, degrees));
//y1 = y1 + (distance * floatcos(-a, degrees));
//distance = floatsqroot ((floatpower ((x1 - x2), 2)) + (floatpower ((y1 - y2), 2)));
x1 = floatsqroot( floatpower( (x1 - x2), 2) );
y1 = floatsqroot( floatpower( (y1 - y2), 2) );
//x2 = x1 + (x1 * floatsin(-a, degrees));
//y2 = y1 + (y1 * floatcos(-a, degrees));
SetPlayerVelocity(playerid, x1, y1, 0.1);