Advertisement
Guest User

Seif's Body Part Detection Include

a guest
Feb 9th, 2012
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.84 KB | None | 0 0
  1. /*
  2.                                     Body Part Detection - Detect a player'ss body part
  3.                                                     By Seif
  4. */
  5. /*x---------------------------------Important-------------------------------------x*/
  6. //**INCLUDES**//
  7. #include <a_samp>
  8. /*x---------------------------------Defining-------------------------------------x*/
  9. #define MAX_DISTANCE_UNIT   100.0   // maximum distance a player can shoot from
  10. //**BODY PARTS**//
  11. #define BODY_PART_HEAD  1
  12. #define BODY_PART_TORSO 2
  13. #define BODY_PART_LEGS  3
  14. /*x---------------------------------CallBacks-------------------------------------x*/
  15. /*
  16.                                             ---[IsPlayerAimingBodyPart]---
  17.             »playerid: the player
  18.             »bodypart: the body part you want to check
  19.             *Return: 1 if true, 0 if false
  20.         *-------------------------------------------------------------------*
  21.         | Checks if the player is aiming at any player's certain body part. |
  22.         *-------------------------------------------------------------------*
  23. */
  24.  
  25. stock IsPlayerAimingBodyPart(playerid, bodypart)
  26. {
  27.     // Get the camera's positions
  28.     new Float:x, Float:y, Float:z;
  29.     new Float:vx, Float:vy, Float:vz;
  30.     new Float:cx, Float:cy, Float:cz;
  31.     GetPlayerCameraFrontVector(playerid, vx, vy, vz);
  32.     GetPlayerCameraPos(playerid, cx, cy, cz);
  33.  
  34.     // Check if the player is aiming in a certain distance
  35.     for(new Float:d; d < MAX_DISTANCE_UNIT; d += 0.5)
  36.     {
  37.         x = vx*d+cx;
  38.         y = vy*d+cy;
  39.         z = vz*d+cz;
  40.         new Float:dist = floatsqroot((x-cx)*(x-cx)+(y-cy)*(y-cy));
  41.         new Float:offset;
  42.         switch (GetPlayerWeapon(playerid))
  43.         {
  44.             case 24, 29, 22, 23, 25, 26, 27, 28, 32: offset = 0.1122047500310059125919013005129;
  45.             case 30, 31: offset = 0.07867820613690007867820613690008;
  46.             case 33, 34: offset = 0.0;
  47.         }
  48.         new Float:height;
  49.         if (z > cz) height = z-cz;
  50.         else height = cz-z;
  51.         offset *= dist;
  52.         height /= dist;
  53.         new Float:part;
  54.         if (bodypart == BODY_PART_HEAD) part = -0.4;
  55.         else if (bodypart == BODY_PART_TORSO) part = 0.3;
  56.         else if (bodypart == BODY_PART_LEGS) part = 1.0;
  57.         z = z+offset-height+part;
  58.         for(new i, m = GetMaxPlayers(); i < m; i++)
  59.         {
  60.             if (!IsPlayerConnected(i)) continue;
  61.             if (playerid == i) continue;
  62.             if (IsPlayerInRangeOfPoint(i, 0.5, x, y, z-0.5)) return 1;
  63.         }
  64.     }
  65.     return 0;
  66. }
  67.  
  68. /*
  69.                                             ---[IsPlayerAimingTargetBodyPart]---
  70.             »playerid: the player
  71.             »targetid: the target
  72.             »bodypart: the body part you want to check
  73.             *Return: 1 if true, 0 if false
  74.         *-------------------------------------------------------------------*
  75.         | Checks if the player is aiming at target's specific body part.    |
  76.         *-------------------------------------------------------------------*
  77. */
  78.  
  79. stock IsPlayerAimingTargetBodyPart(playerid, targetid, bodypart)
  80. {
  81.     // Get the camera's positions
  82.     new Float:x, Float:y, Float:z;
  83.     new Float:vx, Float:vy, Float:vz;
  84.     new Float:cx, Float:cy, Float:cz;
  85.     GetPlayerCameraFrontVector(playerid, vx, vy, vz);
  86.     GetPlayerCameraPos(playerid, cx, cy, cz);
  87.  
  88.     // Check if the player is aiming in a certain distance
  89.     new Float:px, Float:py, Float:pz;
  90.     GetPlayerPos(targetid, px, py, pz);
  91.     new Float:dist = floatsqroot(((cx-px)*(cx-px)) + ((cy-py)*(cy-py)) + ((cz-pz)*(cz-pz)));
  92.     x = vx*dist+cx;
  93.     y = vy*dist+cy;
  94.     z = vz*dist+cz;
  95.     new Float:offset;
  96.     switch (GetPlayerWeapon(playerid))
  97.     {
  98.         case 24, 29, 22, 23, 25, 26, 27, 28, 32: offset = 0.1122047500310059125919013005129;
  99.         case 30, 31: offset = 0.07867820613690007867820613690008;
  100.         case 33, 34: offset = 0.0;
  101.     }
  102.     new Float:height;
  103.     if (z > cz) height = z-cz;
  104.     else height = cz-z;
  105.     offset *= dist;
  106.     height /= dist;
  107.     new Float:part;
  108.     if (bodypart == BODY_PART_HEAD) part = -0.4;
  109.     else if (bodypart == BODY_PART_TORSO) part = 0.3;
  110.     else if (bodypart == BODY_PART_LEGS) part = 1.0;
  111.     z = z+offset-height+part;
  112.     if (IsPlayerInRangeOfPoint(targetid, 0.5, x, y, z-0.5)) return 1;
  113.    
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement