Advertisement
Guest User

Untitled

a guest
Dec 31st, 2023
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.28 KB | Gaming | 0 0
  1. // Copyright 2023 Maicol Castro (maicolcastro.abc@gmail.com).
  2. // Distributed under the BSD 3-Clause License.
  3. // See at https://opensource.org/license/bsd-3-clause.
  4.  
  5. #if defined _GETPLAYERTARGET_INC
  6.     #endinput
  7. #endif
  8. #define _GETPLAYERTARGET_INC 1
  9.  
  10. #include <foreach>
  11.  
  12. stock Float:fmin(Float:a, Float:b) { return a > b ? b : a; }
  13. stock Float:fmax(Float:a, Float:b) { return a > b ? a : b; }
  14. stock fswap(&Float:a, &Float:b) { new Float:t = a; a = b; b = t; }
  15.  
  16. stock bool:_IntersectBox(const Float:ray[6], const Float:box[6])
  17. {
  18.     new Float:tMin = (box[0] - ray[0]) / ray[3];
  19.     new Float:tMax = (box[3] - ray[0]) / ray[3];
  20.  
  21.     if (tMin > tMax)
  22.         fswap(tMin, tMax);
  23.  
  24.     new Float:tyMin = (box[1] - ray[1]) / ray[4];
  25.     new Float:tyMax = (box[4] - ray[1]) / ray[4];
  26.  
  27.     if (tyMin > tyMax)
  28.         fswap(tyMin, tyMax);
  29.  
  30.     if ((tMin > tyMax) || (tyMin > tMax))
  31.         return false;
  32.  
  33.     if (tyMin > tMin)
  34.         tMin = tyMin;
  35.  
  36.     if (tyMax < tMax)
  37.         tMax = tyMax;
  38.  
  39.     new Float:tzMin = (box[2] - ray[2]) / ray[5];
  40.     new Float:tzMax = (box[5] - ray[2]) / ray[5];
  41.  
  42.     if (tzMin > tzMax)
  43.         fswap(tzMin, tzMax);
  44.  
  45.     if ((tMin > tzMax) || (tzMin > tMax))
  46.         return false;
  47.  
  48.     if (tzMin > tMin)
  49.         tMin = tzMin;
  50.  
  51.     if (tzMax < tMax)
  52.         tMax = tzMax;
  53.  
  54.     return true;
  55. }
  56.  
  57. stock GetPlayerTargetPlayerEx(playerid)
  58. {
  59.     new keys, updown, leftright;
  60.     GetPlayerKeys(playerid, keys, updown, leftright);
  61.  
  62.     if (keys & KEY_HANDBRAKE == 0)
  63.         return INVALID_PLAYER_ID;
  64.  
  65.     if (IsPlayerInAnyVehicle(playerid))
  66.         return INVALID_PLAYER_ID;
  67.  
  68.     new Float:ray[6];
  69.     new Float:box[6];
  70.  
  71.     GetPlayerCameraPos(playerid, ray[0], ray[1], ray[2]);
  72.     GetPlayerCameraFrontVector(playerid, ray[3], ray[4], ray[5]);
  73.  
  74.     foreach (new i : Character)
  75.     {
  76.         if (!IsPlayerConnected(i) || !IsPlayerStreamedIn(i, playerid) || i == playerid)
  77.             continue;
  78.  
  79.         GetPlayerPos(i, box[0], box[1], box[2]);
  80.         GetPlayerPos(i, box[3], box[4], box[5]);
  81.  
  82.         box[0] += 0.25;
  83.         box[1] -= 0.4;
  84.         box[2] -= 0.5;
  85.         box[3] -= 0.25;
  86.         box[4] += 0.1;
  87.  
  88.         GetPlayerKeys(i, keys, updown, leftright);
  89.  
  90.         if (keys & KEY_CROUCH == 0)
  91.             box[5] += 0.5;
  92.  
  93.         if (_IntersectBox(ray, box))
  94.             return i;
  95.     }
  96.  
  97.     return INVALID_PLAYER_ID;
  98. }
  99.  
  100. stock GetPlayerTargetActorEx(playerid)
  101. {
  102.     new keys, updown, leftright;
  103.     GetPlayerKeys(playerid, keys, updown, leftright);
  104.  
  105.     if (keys & KEY_HANDBRAKE == 0)
  106.         return INVALID_ACTOR_ID;
  107.  
  108.     if (IsPlayerInAnyVehicle(playerid))
  109.         return INVALID_ACTOR_ID;
  110.  
  111.     new Float:ray[6];
  112.     new Float:box[6];
  113.  
  114.     GetPlayerCameraPos(playerid, ray[0], ray[1], ray[2]);
  115.     GetPlayerCameraFrontVector(playerid, ray[3], ray[4], ray[5]);
  116.  
  117.     foreach (new i : Actor)
  118.     {
  119.         if (!IsActorStreamedIn(i, playerid))
  120.             continue;
  121.  
  122.         GetActorPos(i, box[0], box[1], box[2]);
  123.         GetActorPos(i, box[3], box[4], box[5]);
  124.  
  125.         box[0] += 0.25;
  126.         box[1] -= 0.4;
  127.         box[2] -= 0.5;
  128.         box[3] -= 0.25;
  129.         box[4] += 0.1;
  130.         box[5] += 0.5;
  131.  
  132.         if (_IntersectBox(ray, box))
  133.             return i;
  134.     }
  135.  
  136.     return INVALID_ACTOR_ID;
  137. }
  138.  
Tags: mobile pawn SA-MP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement