# Solvedcsgo making the aimbot switch player to target constantly

#### manpower

##### They call me the noob coder 😎
Dank Tier Donator
Game Name
csgo
Anticheat
vac
N/A
How long you been coding/hacking?
4 months
Coding Language
c++
hello, im using the aimbot tutorial from bdk. i wanted to call calc angle to all enemies but the aimbot doesent switch entity. this is the code i have now.

C++:
``````for (int i = 1; i < *Player::GetMaxPlayer(); i++)
{

Player* currentPlayer = Player::GetPlayer(i);

if (!currentPlayer || !(*(uint32_t*)currentPlayer) || (uint32_t)currentPlayer == (uint32_t)localPlayer)
{
continue;
}

if (*currentPlayer->GetTeam() == *localPlayer->GetTeam())
{
continue;
}

if (*currentPlayer->GetHealth() < 1 || *localPlayer->GetHealth() < 1)
{
continue;
}

closesDistanceIndex = i;
LocalPlayer::Get()->AimAt(currentPlayer->GetBonePos(8));

}``````
i have tried for a while now if u guys have any solutions let me know how to call calc angle for all entities so i can compare them to get the enemy closest to my crosshair.

Last edited:

#### .visual

Dank Tier Donator
Full Member
And where do you actually calculate the distance between your currentplayer and localplayer? If you leave it like this you just iterate through all enemies.
Calculate the distance between you and the currentPlayer and if it's less than the current closestDistance set the closestDistanceIndex to it

#### luckygambet

##### Newbie
Full Member
If you can calculate the needed angles for your aimbot you can loop through your entity list and store it into an array then loop over that and find the closest enemy to your cross hair

#### manpower

##### They call me the noob coder 😎
Dank Tier Donator
And where do you actually calculate the distance between your currentplayer and localplayer? If you leave it like this you just iterate through all enemies.
Calculate the distance between you and the currentPlayer and if it's less than the current closestDistance set the closestDistanceIndex to it
i have removed the get closest function i just forgot to remove the integer.

Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

• Fill out the form correctly
• Tell us the game name & coding language
• Post everything we need to know to help you
• Ask specific questions, be descriptive
• Post errors, line numbers & screenshots
• Post code snippets using code tags
• If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.