Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Body Part Detection - Detect a player'ss body part
- By Seif
- */
- /*x---------------------------------Important-------------------------------------x*/
- //**INCLUDES**//
- #include <a_samp>
- /*x---------------------------------Defining-------------------------------------x*/
- #define MAX_DISTANCE_UNIT 100.0 // maximum distance a player can shoot from
- //**BODY PARTS**//
- #define BODY_PART_HEAD 1
- #define BODY_PART_TORSO 2
- #define BODY_PART_LEGS 3
- /*x---------------------------------CallBacks-------------------------------------x*/
- /*
- ---[IsPlayerAimingBodyPart]---
- »playerid: the player
- »bodypart: the body part you want to check
- *Return: 1 if true, 0 if false
- *-------------------------------------------------------------------*
- | Checks if the player is aiming at any player's certain body part. |
- *-------------------------------------------------------------------*
- */
- stock IsPlayerAimingBodyPart(playerid, bodypart)
- {
- // Get the camera's positions
- new Float:x, Float:y, Float:z;
- new Float:vx, Float:vy, Float:vz;
- new Float:cx, Float:cy, Float:cz;
- GetPlayerCameraFrontVector(playerid, vx, vy, vz);
- GetPlayerCameraPos(playerid, cx, cy, cz);
- // Check if the player is aiming in a certain distance
- for(new Float:d; d < MAX_DISTANCE_UNIT; d += 0.5)
- {
- x = vx*d+cx;
- y = vy*d+cy;
- z = vz*d+cz;
- new Float:dist = floatsqroot((x-cx)*(x-cx)+(y-cy)*(y-cy));
- new Float:offset;
- switch (GetPlayerWeapon(playerid))
- {
- case 24, 29, 22, 23, 25, 26, 27, 28, 32: offset = 0.1122047500310059125919013005129;
- case 30, 31: offset = 0.07867820613690007867820613690008;
- case 33, 34: offset = 0.0;
- }
- new Float:height;
- if (z > cz) height = z-cz;
- else height = cz-z;
- offset *= dist;
- height /= dist;
- new Float:part;
- if (bodypart == BODY_PART_HEAD) part = -0.4;
- else if (bodypart == BODY_PART_TORSO) part = 0.3;
- else if (bodypart == BODY_PART_LEGS) part = 1.0;
- z = z+offset-height+part;
- for(new i, m = GetMaxPlayers(); i < m; i++)
- {
- if (!IsPlayerConnected(i)) continue;
- if (playerid == i) continue;
- if (IsPlayerInRangeOfPoint(i, 0.5, x, y, z-0.5)) return 1;
- }
- }
- return 0;
- }
- /*
- ---[IsPlayerAimingTargetBodyPart]---
- »playerid: the player
- »targetid: the target
- »bodypart: the body part you want to check
- *Return: 1 if true, 0 if false
- *-------------------------------------------------------------------*
- | Checks if the player is aiming at target's specific body part. |
- *-------------------------------------------------------------------*
- */
- stock IsPlayerAimingTargetBodyPart(playerid, targetid, bodypart)
- {
- // Get the camera's positions
- new Float:x, Float:y, Float:z;
- new Float:vx, Float:vy, Float:vz;
- new Float:cx, Float:cy, Float:cz;
- GetPlayerCameraFrontVector(playerid, vx, vy, vz);
- GetPlayerCameraPos(playerid, cx, cy, cz);
- // Check if the player is aiming in a certain distance
- new Float:px, Float:py, Float:pz;
- GetPlayerPos(targetid, px, py, pz);
- new Float:dist = floatsqroot(((cx-px)*(cx-px)) + ((cy-py)*(cy-py)) + ((cz-pz)*(cz-pz)));
- x = vx*dist+cx;
- y = vy*dist+cy;
- z = vz*dist+cz;
- new Float:offset;
- switch (GetPlayerWeapon(playerid))
- {
- case 24, 29, 22, 23, 25, 26, 27, 28, 32: offset = 0.1122047500310059125919013005129;
- case 30, 31: offset = 0.07867820613690007867820613690008;
- case 33, 34: offset = 0.0;
- }
- new Float:height;
- if (z > cz) height = z-cz;
- else height = cz-z;
- offset *= dist;
- height /= dist;
- new Float:part;
- if (bodypart == BODY_PART_HEAD) part = -0.4;
- else if (bodypart == BODY_PART_TORSO) part = 0.3;
- else if (bodypart == BODY_PART_LEGS) part = 1.0;
- z = z+offset-height+part;
- if (IsPlayerInRangeOfPoint(targetid, 0.5, x, y, z-0.5)) return 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement