Code:Position randomHomePos = Position.of(Misc.random(2) + HOME.getX(), Misc.random(2) + HOME.getY(), HOME.getZ());
|
|
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.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());

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.
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);

I'm sorry. My English is not that good so I don't got you. This is my code:
If u can replace my code with everything u said I wil appricate.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; }
Add public static final to the randomHomePos line of code so it should look like this:
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);
| « Any great tips on how to run a server? | Collection Log not showing items » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |