Jump to content

Hopping worlds


whipz

Recommended Posts

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 (:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 (: 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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