static bool:FAI_IsPlayerInAggroViewingAngle(playerid, npcid) {
// Get NPC position
new Float:xn, Float:yn, Float:zn;
FCNPC_GetPosition(npcid, xn, yn, zn);
// Get player position
new Float:xp, Float:yp, Float:zp;
if(!IsPlayerNPC(playerid)) {
GetPlayerPos(playerid, xp, yp, zp);
} else {
FCNPC_GetPosition(playerid, xp, yp, zp);
}
// Calculate the angle between these 2 points
new Float:angleBetweenPoints = atan2(xp - xn, yp - yn);
// Get the NPC facing angle adjusted for the weird GTA angle system
new Float:npcFacingAngle = 360.0 - FCNPC_GetAngle(npcid);
// Calculate the smallest difference between these 2 angles as a value between -180.0 and 180.0
new Float:angleDifference = angleBetweenPoints - npcFacingAngle;
if(angleDifference > 180.0) {
angleDifference -= 360.0;
}
if(angleDifference < -180.0) {
angleDifference = 360.0;
}
// Get the absolute value of this angle
angleDifference = floatabs(angleDifference);
// Check if the player is within the aggro viewing angle
if(angleDifference <= FAI_NPCs[npcid][FAI_NPC_AGGRO_VIEWING_ANGLE][playerid]/2) {
return true;
}
return false;
}