Jump to content

Hopping worlds


Recommended Posts

Posted

Hey guys; I need to be able to hop to worlds basically everytime; for some reason the Hopper supplied by OSbot is a tad buggy and sometimes doesnt actually go hop worlds or hops to a world it cant EG 500 lvl or members if f2p account is used;

I have tried to come up with something that could possibly help me; but Im not sure how to prevent it from trying to log into the world it currently is if the random lands on that world;

int rand = random(10);
			if (rand == 1) {
				hopper.hop(1, () -> false);
			}
			if (rand == 2) {
				hopper.hop(8, () -> false);
			}
			if (rand == 3) {
				hopper.hop(16, () -> false);
			}
			if (rand == 4) {
				hopper.hop(26, () -> false);
			}
			if (rand == 5) {
				hopper.hop(35, () -> false);
			}
			if (rand == 6) {
				hopper.hop(82, () -> false);
			}
			if (rand == 7) {
				hopper.hop(83, () -> false);
			}
			if (rand == 8) {
				hopper.hop(84, () -> false);
			}
			if (rand == 9) {
				hopper.hop(93, () -> false);
			}
			if (rand == 10) {
				hopper.hop(94, () -> false);
			}

any feedback would be sweet (: 

or if someone else has a snippet that could be useful here please post (:

Posted (edited)

So far I've haven't experienced any issues with the hopper. Are you sure you're making use of the correct methods?
Also, consider using a switch instead of multiple if statements.
You should use something of this sort:

int hopTo = -1;
int rand = random(1,10);
  switch (rand) {
  case 1:
  	hopTo = 1;
  break;
  case 2:
  	hopTo = 8;
  break;
  //add remaining cases
}

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

Here's an even better solution with an array instead of a switch

int hopTo = -1;
int[] worlds = {1,8,16}; //add your worlds here
int rand = random(0, worlds.length - 1); //arrays start from index 0
hopTo = worlds[rand];

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

 

Edited by Adept
  • Like 2
Posted
18 minutes ago, Adept said:

So far I've haven't experienced any issues with the hopper. Are you sure you're making use of the correct methods?
Also, consider using a switch instead of multiple if statements.
You should use something of this sort:


int hopTo = -1;
int rand = random(1,10);
  switch (rand) {
  case 1:
  	hopTo = 1;
  break;
  case 2:
  	hopTo = 8;
  break;
  //add remaining cases
}

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

Here's an even better solution with an array instead of a switch


int hopTo = -1;
int[] worlds = {1,8,16}; //add the other worlds (make sure sure you have as much elements as the maximum value of the random)
int rand = random(0,9); //arrays start from index 0
hopTo = worlds[rand];

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

 

Thanks mate Ill give it a try !

9 minutes ago, Zappster said:

@FrostBug did something with this a couple of years ago. Please see:

 

That could be the one I was looking for I saw houses which was a remake of this one I think

 

Posted
1 hour ago, Adept said:

So far I've haven't experienced any issues with the hopper. Are you sure you're making use of the correct methods?
Also, consider using a switch instead of multiple if statements.
You should use something of this sort:


int hopTo = -1;
int rand = random(1,10);
  switch (rand) {
  case 1:
  	hopTo = 1;
  break;
  case 2:
  	hopTo = 8;
  break;
  //add remaining cases
}

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

Here's an even better solution with an array instead of a switch


int hopTo = -1;
int[] worlds = {1,8,16}; //add the other worlds (make sure sure you have as much elements as the maximum value of the random)
int rand = random(0,9); //arrays start from index 0
hopTo = worlds[rand];

if (hopTo != -1 && hopTo != getWorlds().getCurrentWorld){
getWorlds().hop(hopTo);
}

 

The case switches worked better; the bottom one seems to skip world hoping (: thanks so much mate; it doesnt go to wrong worlds now; and if it gets stuck I can set it to continue (: 

Posted (edited)
6 minutes ago, whipz said:

The case switches worked better; the bottom one seems to skip world hoping (: thanks so much mate; it doesnt go to wrong worlds now; and if it gets stuck I can set it to continue (: 

I'd recommend using the bottom one.
I edited the code so that all you have to do is add world to the "worlds" array. Copy the code again from the original reply and try again.

Edited by Adept
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...