20.06.2013, 22:07
Here's a useful function:
pawn Код:
stock IsVehicleAimingAtPlayer(vid, pid, Float:r = 2.0)
{
new
Float:d,
Float:sx,
Float:sz,
Float:cx,
Float:cz,
Float:px,
Float:py,
Float:pz,
Float:rx,
Float:ry,
Float:rz;
GetVehiclePos(vid, px, py, pz);
GetVehicleRot(vid, rx, ry, rz);
d = GetPlayerDistanceFromPoint(pid, px, py, pz);
sx = floatsin(rx, degrees);
sz = floatsin(rz, degrees);
cx = floatcos(rx, degrees);
cz = floatcos(rz, degrees);
px = px + d *-cx * sz;
py = py + d * cx * cz;
pz = pz + d * sx;
if (IsPlayerInRangeOfPoint(pid, r, px, py, pz))
{
return 1;
}
return 0;
}
stock GetVehicleRot(vehicleid, &Float:rx, &Float:ry, &Float:rz)
{
new
Float:qw,
Float:qx,
Float:qy,
Float:qz;
GetVehicleRotationQuat(vehicleid, qw, qx, qy, qz);
ConvertQuatToEuler(qw, -qx, -qy, -qz, rx, ry, rz);
return 1;
}
stock ConvertQuatToEuler(Float:qw, Float:qx, Float:qy, Float:qz, &Float:rx, &Float:ry, &Float:rz)
{
new
Float:sqw = qw * qw,
Float:sqx = qx * qx,
Float:sqy = qy * qy,
Float:sqz = qz * qz;
rx = asin (2 * (qw * qx + qy * qz) / (sqw + sqx + sqy + sqz));
ry = atan2(2 * (qw * qy - qx * qz), 1 - 2 * (sqy + sqx));
rz = atan2(2 * (qw * qz - qx * qy), 1 - 2 * (sqz + sqx));
return 1;
}