Short story:
I'm making an aimbot by moving the mouse, aiming to the nearest enemy to the player, if that enemy is visible on the screen.

PHP Code:

bool isVisible = false;
float dist = FLT_MAX;
int nearIndex = -1;

for (
int a = 0; a < gInfo.totalPlayers; a++)
//usual checking if player is enemy and alive
if (gInfo.totalPlayers != myPlayerIndex && playerBuf0&#91;a&#93;.team != && playerBuf0&#91;a&#93;.hp > 0)
playerBuf0&#91;a&#93;.screenCoordinates = //my world to screen function
//isVisible is also a parameter in w2s, where it states if the player is
//on the screen
if (isVisible)
//if the player is visible (on screen) then check if his distance
//is smaller than than the previous checked player
//The index is saved in "nearIndex"
if (playerBuf0&#91;a&#93;.distance < dist)
nearIndex = a;
dist = playerBuf0&#91;a&#93;.distance;

if (
nearIndex != -1 && GetAsyncKeyState(CSGO_AIMKEY))
//move mouse


This is a seperate thread to the thread getting the information. The other thread is also the thread, where the distance for each player to my player is calculated.
The problem now is, that it won't aim to the closest enemy, but to the on first in the list.

Thanks for any help

Original Writen by tomatocake in General Programming and Reversing Category, the date of 26-06-2015 16:39.