SatanIsGood

GetTargetClosestToCrosshair

Sep 14th, 2020 (edited)
891
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //General syntax, can work for any game
  2.  
  3.  
  4. Ent* GetBestTarget(Ent* localPlayer, EntList* entList)
  5. {
  6.     float oldDistance = FLT_MAX;
  7.     float newDistance = 0;
  8.     Ent* target = nullptr;
  9.  
  10.     for (auto ent : entList)
  11.     {
  12.         if (ent && ent->clientId != localPlayer->clientId && ent->lifeState == 0)
  13.         {
  14.             vec3 angleTo = CalcAngle(localPlayer->pos, ent->pos);
  15.             newDistance = Distance(localPlayer->angles, angleTo);
  16.             if (newDistance < oldDistance)
  17.             {
  18.                 oldDistance = newDistance;
  19.                 target = ent;
  20.             }
  21.         }
  22.     }
  23.     return target;
  24. }
RAW Paste Data