# SolvedTargeting Logic

#### Obsta

##### Jr.Hacker
Meme Tier VIP
So my current logic requirements for firing are as follows:
-Aimbot key is pressed
-Is an enemy player
-Is closer than 30 meters
-Is within 100pixels of crosshair
-Is aiming at a player
-> Then Fire.

The issue is that if multiple targets check all of the above requirements then it flicks between them. I can't use a 'lock onto player untill player is dead' because if they run out of the player's vision it leaves the bot spraying the wall.

Any suggestions?

ps. I also used a 'Is Spotted' variable, however the game has a ~1 second update delay on that which makes it very inconsistent and slow to react for playing against real people.

#### Obsta

##### Jr.Hacker
Meme Tier VIP
Ok so the issue is fixed, works fine now. Implemented a Distance check alongside team, hp and mouse down

C++:
``````int getClosestEnemy() //Find closest player
{
int closestPlayer = 5;
float closestDistance = 999;

for (int p = 1; p < 11; p++) //Have to skip 0 or else it targets self with closest distance of 0
{
if (getDistance(p) < closestDistance && PlayerList[p].hp != 0 && PlayerList[p].team != PlayerStruct.team)
{
closestDistance = getDistance(p);
closestPlayer = p;

}
}

return closestPlayer;
}``````
I know its baby stuff but i'll post the solution anyway cause i hate threads that close without sharing the answer.

#### Syntax Error

##### Coder
Silenced
Meme Tier VIP
Disclaimer : I've never made an aimbot

Could you possibly put an if statement in your while loop to check if these conditions are met to decrement your counter so you keep targeting the same player?

#### Obsta

##### Jr.Hacker
Meme Tier VIP
Disclaimer : I've never made an aimbot

Could you possibly put an if statement in your while loop to check if these conditions are met to decrement your counter so you keep targeting the same player?
Possibly, i'll give it a test and let you know how i go.

Edit: While this might have been the cleanest and most practical way to go about it, i ended up just using another while loop that breaks upon release of the aimbot key. Whilst inside the second while loop it just locks onto the indexed player and shoots.

Last edited:

#### till0sch

##### Respected Hacker
Dank Tier VIP
Dank Tier Donator
Possibly, i'll give it a test and let you know how i go.

Edit: While this might have been the cleanest and most practical way to go about it, i ended up just using another while loop that breaks upon release of the aimbot key. Whilst inside the second while loop it just locks onto the indexed player and shoots.
Do you compare those enemies' distances to you and aim at the closer one?

#### Obsta

##### Jr.Hacker
Meme Tier VIP
Do you compare those enemies' distances to you and aim at the closer one?
I don't, I suppose that's another working solution though.

#### till0sch

##### Respected Hacker
Dank Tier VIP
Dank Tier Donator
I don't, I suppose that's another working solution though.
After all your validations, this is what you also gotta do, I guess that'd fix your issue

#### GAFO666

##### Hacker
Meme Tier VIP
hmm eez way to fix that is a static bool combined with the keypress event.
once the key is pressed it aims to one target and then it locks there until the button is released or the player is dead.. or commonly known as target lock

#### Obsta

##### Jr.Hacker
Meme Tier VIP
hmm eez way to fix that is a static bool combined with the keypress event.
once the key is pressed it aims to one target and then it locks there until the button is released or the player is dead.. or commonly known as target lock
Yeah this is pretty much what i did, feels cheap and dirty though.

#### GAFO666

##### Hacker
Meme Tier VIP
hmm your looping from 1 to 10 on your playerlist, may reverse the maxplayers or the connected player ammount

#### Obsta

##### Jr.Hacker
Meme Tier VIP
hmm your looping from 1 to 10 on your playerlist, may reverse the maxplayers or the connected player ammount
There's never more than ten players on a competitive server though.

#### GAFO666

##### Hacker
Meme Tier VIP
There's never more than ten players on a competitive server though.
nvm then
#10chars

Attention! Before you post:

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