a_angles.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // a_angles.inc
  2. // Angle functions
  3. // Created by:
  4. // Tannz0rz
  5. #if defined _a_angles_included
  6. #endinput
  7. #endif
  8. #define _a_angles_included
  9. #include <a_samp>
  10. stock IsPlayerBehindPlayer(playerid, targetid, Float:dOffset)
  11. {
  12. new
  13. Float:pa,
  14. Float:ta;
  15. if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
  16. GetPlayerFacingAngle(playerid, pa);
  17. GetPlayerFacingAngle(targetid, ta);
  18. if(AngleInRangeOfAngle(pa, ta, dOffset) && IsPlayerFacingPlayer(playerid, targetid, dOffset)) return true;
  19. return false;
  20. }
  21. stock SetPlayerToFacePlayer(playerid, targetid)
  22. {
  23. new
  24. Float:pX,
  25. Float:pY,
  26. Float:pZ,
  27. Float:X,
  28. Float:Y,
  29. Float:Z,
  30. Float:ang;
  31. if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
  32. GetPlayerPos(targetid, X, Y, Z);
  33. GetPlayerPos(playerid, pX, pY, pZ);
  34. if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  35. else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  36. else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  37. if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
  38. else ang = (floatabs(ang) - 180.0);
  39. SetPlayerFacingAngle(playerid, ang);
  40. return 0;
  41. }
  42. stock IsPlayerFacingPlayer(playerid, targetid, Float:dOffset)
  43. {
  44. new
  45. Float:pX,
  46. Float:pY,
  47. Float:pZ,
  48. Float:pA,
  49. Float:X,
  50. Float:Y,
  51. Float:Z,
  52. Float:ang;
  53. if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
  54. GetPlayerPos(targetid, pX, pY, pZ);
  55. GetPlayerPos(playerid, X, Y, Z);
  56. GetPlayerFacingAngle(playerid, pA);
  57. if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  58. else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  59. else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  60. if(AngleInRangeOfAngle(-ang, pA, dOffset)) return true;
  61. return false;
  62. }
  63. stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
  64. {
  65. a1 -= a2;
  66. if((a1 < range) && (a1 > -range)) return true;
  67. return false;
  68. }