• Amused
  • Angry
  • Annoyed
  • Awesome
  • Bemused
  • Cocky
  • Cool
  • Crazy
  • Crying
  • Down
  • Drunk
  • Embarrased
  • Enraged
  • Friendly
  • Geeky
  • Godly
  • Happy
  • Hateful
  • Hungry
  • Innocent
  • Meh
  • Piratey
  • Poorly
  • Sad
  • Secret
  • Shy
  • Sneaky
  • Tired
  • Wtf
  • At Work
  • CodenzHub
  • Coding
  • Deejaying
  • Donating
  • Drinking
  • Eating
  • Editing
  • Hacking
  • Hate Mailing
  • Jamin'
  • Lagging
  • Live Streaming
  • Lurking
  • No Status
  • Pawning
  • PC Gaming
  • PS Gaming
  • Raging
  • Reversing
  • Sleeping
  • Steam Gaming
  • Trolling
  • TwitchStreamer
  • Vodka!
  • Watching TV/Movie
  • Xbox Gaming
  • Youtuber
  • Zombies
  • Results 1 to 6 of 6
    1. #1
      Hacker
      Turning to page 394...
       
      Coding
       
      Liduen's Avatar
      Join Date
      May 2013
      Location
      Germany
      Posts
      713
      Thanks (-->)
      161
      Thanks (<--)
      225

      Distance (bubble) sort problem

      John Kittz
      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.

      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;
      }
      }


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

      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;
      }
      }
      }
      }


      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:

      Click image for larger version. 

Name:	distanceproblem.JPG 
Views:	12 
Size:	27.1 KB 
ID:	2493

      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 by Liduen; 02-23-2014 at 02:48 PM.
      My contributions
      UrbanTerror | OpenGL - ModelLogger | Polymorphic junk code | Tutorial/Article Collection
      Admiring technological singularity

    2. #2
      Hacker
      shell toes yes
       
      Lagging
       
      squeenie's Avatar
      Join Date
      Mar 2013
      Posts
      717
      Thanks (-->)
      598
      Thanks (<--)
      221
      Its hard to read this clearly on my phone but your bubble sort looks all wrong.

      You only need a single greater/less than comparison in your if statement.

      For(i = 0; i < 32; ++i)
      For(j = 0; j < 32; ++j)
      If( item[j]<item[i])
      Swap

      Keep in mind bubble sort is a bit slow.

      EDIT: What I do is just loop through them all once and just compare one to the next and store the closest one. Once you have gone through them all you'll have the closest one.
      Last edited by squeenie; 02-24-2014 at 06:03 AM.

    3. #3
      Global Moderator
      give me my colorz back
      FeelsBadMan
       
      Coding
       
      till0sch's Avatar
      Join Date
      Oct 2012
      Location
      Germany.
      Posts
      1,168
      Thanks (-->)
      179
      Thanks (<--)
      340
      Well for lowest just go for int lowest= item[0], then loop through and if something's smaller (item[i]<lowest) then make lowest be that item

    4. #4
      Hacker
      shell toes yes
       
      Lagging
       
      squeenie's Avatar
      Join Date
      Mar 2013
      Posts
      717
      Thanks (-->)
      598
      Thanks (<--)
      221
      Quote Originally Posted by till0sch97 View Post
      Well for lowest just go for int lowest= item[0], then loop through and if something's smaller (item[i]<lowest) then make lowest be that item
      This is what I meant to say, just worded much better.
      You type better english than I do

    5. #5
      Hacker
      Turning to page 394...
       
      Coding
       
      Liduen's Avatar
      Join Date
      May 2013
      Location
      Germany
      Posts
      713
      Thanks (-->)
      161
      Thanks (<--)
      225
      Quote Originally Posted by squeenie View Post
      Its hard to read this clearly on my phone but your bubble sort looks all wrong.

      You only need a single greater/less than comparison in your if statement.

      For(i = 0; i < 32; ++i)
      For(j = 0; j < 32; ++j)
      If( item[j]<item[i])
      Swap

      Keep in mind bubble sort is a bit slow.

      EDIT: What I do is just loop through them all once and just compare one to the next and store the closest one. Once you have gone through them all you'll have the closest one.
      Okay that would look like this:

      int nNearestTarget = 0;
      for(int i = 0; i < 32; i++){
      for(int j = 0; j < 32; j++){
      if(p[j].fDistance < p[nNearestTarget].fDistance) nNearestTarget = j;
      }
      }


      But I wanted to keep my list principle as I need it to simply switch to the second one in case the first one is not valid (in my team or sth.)
      Now I wrote it like this:

      for(int i = 0; i < 32; i++){
      for(int j = 0; j < 32; j++){
      if((p[i].fDistance > p[j].fDistance && p[i].nDistancePriority < p[j].nDistancePriority) || (p[i].fDistance < p[j].fDistance && p[i].nDistancePriority > p[j].nDistancePriority)){
      //swap
      }
      }
      }


      The last one works fine. Allthough I have no idea why my first try won't work, it's simliar in logic and I can't find a mistake yet.
      Squeenie you said the bubble sort was messed up- could you explain it a bit further what exactly was wrong?
      Thanks as always guys!

      Liduen
      Last edited by Liduen; 02-24-2014 at 12:30 PM.
      My contributions
      UrbanTerror | OpenGL - ModelLogger | Polymorphic junk code | Tutorial/Article Collection
      Admiring technological singularity

    6. #6
      Hacker
      shell toes yes
       
      Lagging
       
      squeenie's Avatar
      Join Date
      Mar 2013
      Posts
      717
      Thanks (-->)
      598
      Thanks (<--)
      221
      Cheats'n'Trainers
      Actually it was right, my bad

    Similar Game Hacker Threads

    1. [Help] VS error C2664 using std::sort on vector of pointers
      By [GH]Rake in forum C/C++
      Replies: 3
      Last Post: 02-01-2015, 08:02 PM
    2. Distance
      By simonpaa in forum Hacking Help
      Replies: 3
      Last Post: 12-15-2014, 02:12 PM
    3. [Help] Finding distance
      By xeltic in forum Hacking Help
      Replies: 1
      Last Post: 10-22-2014, 06:17 PM
    4. Bubble Trouble Trainer
      By Soulreaper93 in forum Other Game Hacks
      Replies: 8
      Last Post: 03-24-2013, 05:01 PM
    5. [IDEAS] What sort of games would you like?
      By supercjb1 in forum Misc Coding
      Replies: 9
      Last Post: 06-09-2012, 05:25 AM

    Tags for this Thread