Tele home is always in the same pos(X.Y), I want it Mics random teleports.
This is my code:
I will thanks and rep for the helpers.Quote:
public static final Position HOME = Position.of(3085, 3488, 0);
Printable View
Tele home is always in the same pos(X.Y), I want it Mics random teleports.
This is my code:
I will thanks and rep for the helpers.Quote:
public static final Position HOME = Position.of(3085, 3488, 0);
Code:Position randomHomePos = Position.of(Misc.random(2) + HOME.getX(), Misc.random(2) + HOME.getY(), HOME.getZ());
[Only registered and activated users can see links. Click Here To Register...]Quote:
Originally Posted by JayArrowz [Only registered and activated users can see links. Click Here To Register...]
I imported the first Mics but the 2nd one still in red error.
You should not declare that there, you need to find where the HOME variable gets USED (NOT DECLARED). Then place the position on top of that.Quote:
Originally Posted by Ilgaz [Only registered and activated users can see links. Click Here To Register...]
What you are searching for should look like this:
Once you find the code above or similar code to it then change it to:Code:player.startTeleport(HOME);
Code:Position randomHomePos = Position.of(Misc.random(2) + HOME.getX(), Misc.random(2) + HOME.getY(), HOME.getZ());
player.startTeleport(randomHomePas);
[Only registered and activated users can see links. Click Here To Register...]Quote:
Originally Posted by JayArrowz [Only registered and activated users can see links. Click Here To Register...]
Now I'm getting random error.. Ugh..
Please read carefully what i said.Quote:
Originally Posted by Ilgaz [Only registered and activated users can see links. Click Here To Register...]
This is a declaration:
Code:public static Position HOME = Position.of(x, x, x);
This is using the declared variable:
Also it seems you dont have Misc.java?Code:player.startTeleport(HOME);
I'm sorry. My English is not that good so I don't got you. This is my code:Quote:
Originally Posted by JayArrowz [Only registered and activated users can see links. Click Here To Register...]
If u can replace my code with everything u said I wil appricate.Quote:
public static final Position HOME = Position.of(3085, 3488, 0);
Position randomHomePos = Position.of(Misc.random(2) + HOME.getX(), Misc.random(2) + HOME.getY(), HOME.getZ());
player.startTeleport(randomHomePas);
Don't listen to JayArrowz, you have Misc.java just not the random method. Also avoid using Positon.of I ran into buggy errors with teleporting/player saving. Use new Position(3085, 3488, 0); instead.
Also use this for random ints:
So your whole code should look like this:Code:Random ran = new Random();
// Print next int value
// Returns number between 0-9
int nxt = ran.nextInt(10);
If you want you can add this method to Misc.java to use the random method in the future for other things:Code:Random ran = new Random();
public static final Position HOME = new Position(3085, 3488, 0);
Position randomHomePos = new Position(ran.nextInt(2) + HOME.getX(), ran.nextInt(2) + HOME.getY(), HOME.getZ());
player.getMovement().teleport(randomHomePos);
Code:public static int random(int randomInt) {
Random ran = new Random();
// Print next int value
// Returns number between 0-9
int nxt = ran.nextInt(randomInt);
return nxt;
}
Nice one bro. Awesome to have you here <3Quote:
Originally Posted by Armo [Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]Quote:
Originally Posted by Armo [Only registered and activated users can see links. Click Here To Register...]
Oh I did not notice this.
Add public static final to the randomHomePos line of code so it should look like this:Quote:
Originally Posted by Ilgaz [Only registered and activated users can see links. Click Here To Register...]
Then add this code to wherever you want it to be called (Command, clicking a teleport, teleport interface, etc)Code:public static final Position randomHomePos = new Position(ran.nextInt(2) + HOME.getX(), ran.nextInt(2) + HOME.getY(), HOME.getZ());
Code:player.getMovement().teleport(World.randomHomePos);