Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------
- * Game hacking QTS ( Quickie Tip Series )
- * no. 12 - Calculate closest player to you
- -----------------------------------------
- * Author: SEGnosis - GHAnon.net
- * Thanks to:
- * bitterbanana - No known site
- * Drunken Cheetah - No known site
- * fatboy88 - No known site
- * Geek4Ever - No known site
- * learn_more - www.uc-forum.com
- * Novocaine - http://ilsken.net/blog/?page_id=64
- * Philly0494 - No known site
- * Roverturbo - www.uc-forum.com
- * SilentKarma - www.halocoders.com - offline
- * Strife - www.uc-forum.com
- * Wieter20 - No known site
- */
- //------------------------------------//
- #include <Windows.h>
- #define NEG_TARGET -1
- int GetClosestPlayer()
- {
- int iPlayerRet = NEG_TARGET; // Dont want forced player index
- float fMinDistance = FLT_MAX;
- for( int i = 0; i < CPBase->m_uiPlayersInMap; i++ ) // enumerate players
- {
- if( !CEManager.PlayerTable[ i ] ) // if player exists
- continue;
- if( !CEManager.PlayerTable[ i ]->m_iHealth ) // if player is alive
- continue;
- FVect3* vBoneTarget = &CEManager.PlayerTable[ i ]->m_vBoneNeck; // get player position
- FVect3 vTotalDistance = { CLEntity->m_vPos.x - vBoneTarget->x, // Get even distance
- CLEntity->m_vPos.y - vBoneTarget->y,
- CLEntity->m_vPos.z - vBoneTarget->z };
- // Formula for hypotenuse
- float fDistance = sqrt( vTotalDistance .x * vTotalDistance .x + vTotalDistance .z * vTotalDistance .z );
- if( fDistance < fMinDistance ) // if distance is smaller than the last
- {
- fMinDistance = fDistance; // set it
- iPlayerRet = i; // set target player
- }
- }
- return iPlayerRet;
- }
- //------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement