Advertisement
Guest User

12 - Calculate closest player to you

a guest
Aug 5th, 2010
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 12 - Calculate closest player to you
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21. //------------------------------------//
  22. #include <Windows.h>
  23.  
  24. #define NEG_TARGET -1
  25.  
  26. int GetClosestPlayer()
  27. {
  28.     int iPlayerRet = NEG_TARGET; // Dont want forced player index
  29.  
  30.     float   fMinDistance    = FLT_MAX;
  31.  
  32.     for( int i = 0; i < CPBase->m_uiPlayersInMap; i++ ) // enumerate players
  33.     {
  34.         if( !CEManager.PlayerTable[ i ] ) // if player exists
  35.             continue;
  36.  
  37.         if( !CEManager.PlayerTable[ i ]->m_iHealth ) // if player is alive
  38.             continue;
  39.  
  40.         FVect3* vBoneTarget = &CEManager.PlayerTable[ i ]->m_vBoneNeck; // get player position
  41.  
  42.         FVect3 vTotalDistance = {   CLEntity->m_vPos.x - vBoneTarget->x, // Get even distance
  43.                                     CLEntity->m_vPos.y - vBoneTarget->y,
  44.                                     CLEntity->m_vPos.z - vBoneTarget->z   };
  45.                      
  46.         // Formula for hypotenuse
  47.         float fDistance = sqrt( vTotalDistance .x * vTotalDistance .x + vTotalDistance .z * vTotalDistance .z );
  48.    
  49.         if( fDistance < fMinDistance ) // if distance is smaller than the last
  50.         {
  51.             fMinDistance = fDistance; // set it
  52.             iPlayerRet = i; // set target player
  53.         }
  54.     }
  55.  
  56.     return iPlayerRet;
  57. }
  58. //------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement