Hi guys,

I've got a problem with my code.

The idea behind it:

- I have an array of objects/players "p[ ]".

- All of the objects have 3d coordinates so I can calculate the distance "fDistance" between me and this player.

- All of them have a distance priority "nDistancePriority". The smaller the distance, the smaller the distance priority. The player with nDistancePriority == 0 is nearest to me.

Now I'm outputting all the numbers with this piece of code:

But now most of the times I see pretty small values as distances somewhere in the middl of the list and not as it should be on the top of it.

To be honest the list doesn't seem sorted at all:

So somewhere must be a mistake with the sorting or something.

Does someone spot my mistake?

I would really appreciate it!!

Greetings,

Liduen

I've got a problem with my code.

The idea behind it:

- I have an array of objects/players "p[ ]".

- All of the objects have 3d coordinates so I can calculate the distance "fDistance" between me and this player.

- All of them have a distance priority "nDistancePriority". The smaller the distance, the smaller the distance priority. The player with nDistancePriority == 0 is nearest to me.

C++:

```
if(bAimbot){
switch(nAimbotMode){
case 0:
//legit [...]
case 1:
//slotnumber [...]
case 2:
//distance
//first set all possible priorities from 0 to 31 (0,1,2,...,30,31)
if(bInitDistancePriotities){ //yes I know i wrote it wrong but I'm too lazy to correct it
for(int i = 0; i < 32; i++) p[i].nDistancePriority = i;
bInitDistancePriotities = false; //do this only once
}
//set distance priority to each enemy (bubble sort)
for(int i = 0; i < 32; i++){
for(int u = 0; u < 31; u++){
//check with the object 1 above the actual object in the array
if((p[u].fDistance > p[u+1].fDistance && p[u].nDistancePriority < p[u+1].nDistancePriority) || (p[u].fDistance < p[u+1].fDistance && p[u].nDistancePriority > p[u+1].nDistancePriority)){
//swap the priorities
nTempDistance = p[u].nDistancePriority;
p[u].nDistancePriority = p[u+1].nDistancePriority;
p[u+1].nDistancePriority = nTempDistance;
}
}
}
//search the enemy with the smallest distance priority -> 0 -> 32
bNoTarget = true;
for(int i = 0; i < 32; i++){
for(int x = 0; x < 32; x++){
if(p[x].nDistancePriority == i){
if(p[x].bValidAimTarget){
nTarget = x;
bNoTarget = false;
break;
}
else break;
}
}
//leave outer for-loop if valid target found
if(!bNoTarget) break;
}
if(!bNoTarget){
WriteProcessMemory(hProcess, (LPVOID) aWriteRotationX, &p[nTarget].fAimbotX, sizeof(float), NULL);
WriteProcessMemory(hProcess, (LPVOID) aWriteRotationY, &p[nTarget].fAimbotY, sizeof(float), NULL);
}
break;
case 3:
//flick(slot) [...]
default: break;
}
}
```

C++:

```
if(nCounter == 1){
system("cls");
for(int i = 0; i < 32; i++){
for(int z = 0; z < 32; z++){
if(p[z].nDistancePriority == i){
cout << i << " " << p[z].fDistance << endl;
break;
}
}
}
}
```

To be honest the list doesn't seem sorted at all:

So somewhere must be a mistake with the sorting or something.

Does someone spot my mistake?

I would really appreciate it!!

Greetings,

Liduen

Last edited: