PrintHintText(attacker, "doing calculation");
new Float:attacker_pos[3];
new Float:victim_pos[3];
new Float:victim_fwd[3];
new Float:victim_eyes[3];
new Float:angle_diff;
new Float:angle_vec[3];
GetClientAbsOrigin(attacker, attacker_pos);
GetClientAbsOrigin(victim, victim_pos);
attacker_pos[2] = victim_pos[2]; //the game ignores Z in the calculation. If you can hit them, you can backstab them regardless of height.
GetClientEyeAngles(victim, victim_eyes);
GetAngleVectors(victim_eyes, victim_fwd, NULL_VECTOR, NULL_VECTOR);
MakeVectorFromPoints(victim_pos, attacker_pos, angle_vec);
NormalizeVector(angle_vec, angle_vec);
angle_diff = GetVectorDotProduct(victim_fwd, angle_vec);
PrintToChatAll("Angle diff is %f", angle_diff);
if (angle_diff < 0.3)
{
PrintToChatAll("backstab");
}
This is something I had lyin' around my snippets folder. When I tested it it worked pretty well, but you might have to adjust the 0.3 for different games/weapons/whatever