1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question World Switching

Discussion in 'Developer Support' started by CodeNinja, Dec 22, 2016.

  1. CodeNinja

    Joined:
    Dec 20, 2016
    Messages:
    37
    Likes Received:
    3
    Hello there, just wondering if anyone knows any methods to accomplish the following tasks:
    Currently searching through the docs now.

    Detect if there are nearby players (not counting ourselves!): Players.newQuery().filter(player -> !Objects.equals(player, Players.getLocal())).results().isEmpty();

    Return current world: Worlds.getCurrent();

    Hop to specific world: WorldHop.hopTo('int world#');

    Edit: updated hop method below, allows for 7.5 second checking before hopping.

    I've stored all hoppable worlds in a freeWorld and membersWorld int[] array.

    This script bot just hops to the next world.

    Code (Text):
    1.  
    2. public class HopLeaf extends LeafTask {
    3.  
    4.     private int[] freeWorlds = new int[] { 3, 7, 8, 11, 17, 19, 20, 29, 34, 38, 41, 43, 61, 80, 81, 108 ,135, 141};
    5.     private int[] membersWorlds = new int[] { 1, 2, 4, 5, 6, 9, 10, 12, 14, 15, 16, 21, 22, 23, 24, 25, 26, 27 ,28, 31, 32, 35, 36, 37, 40, 42, 44, 45, 46, 49, 50, 51, 53, 54, 56, 58, 59, 60, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 82, 83, 84, 85, 87, 89, 91, 92, 96, 98, 99, 100, 103, 104, 105, 116, 117, 119, 123, 124, 134, 138, 139, 140};
    6.  
    7.     @Override
    8.     public void execute() {
    9.  
    10.         int currentWorld = Worlds.getCurrent();
    11.         int selectedWorld = 0;
    12.         System.out.println("Current World: " + currentWorld);
    13.  
    14.         for (int i = 0; i <= membersWorlds.length - 1; i++){
    15.             if (currentWorld < membersWorlds[i]){
    16.                 selectedWorld = membersWorlds[i];
    17.                 i = membersWorlds.length;
    18.             } else if (membersWorlds[membersWorlds.length - 1] == currentWorld){
    19.                 selectedWorld = membersWorlds[0];
    20.             }
    21.         }
    22.  
    23.         if (ChatDialog.getContinue() != null) {
    24.             System.out.println("Detected continue dialogue.");
    25.             // PRESSES SPACE
    26.             Keyboard.typeKey(32);
    27.         }
    28.  
    29.         if (!WorldHop.isOpen()){
    30.             System.out.println("Opening world switcher.");
    31.             // PRESSES KEY: ESC
    32.             Keyboard.typeKey(27);
    33.             System.out.println("Pressed Escape");
    34.             WorldHop.open();
    35.             System.out.println("World Hopper should be open.");
    36.         }
    37.  
    38.         if (selectedWorld != 0){
    39.             System.out.println("Detected nearby players, preparing to hop worlds.");
    40.             Execution.delayUntil(() -> Players.newQuery().filter(player -> !Objects.equals(player, Players.getLocal())).results().isEmpty(), 7500);
    41.             if (WorldHop.isOpen() && Players.newQuery().filter(player -> !Objects.equals(player, Players.getLocal())).results().isEmpty()){
    42.                 System.out.println("Cancelling world hop.");
    43.                 // PRESSES KEY: ESC
    44.                 Keyboard.typeKey(27);
    45.             } else {
    46.                 System.out.println("Hopping.");
    47.                 WorldHop.hopTo(selectedWorld);
    48.             }
    49.         }
    50.     }
    51. }
    52.  
     
    #1 CodeNinja, Dec 22, 2016
    Last edited: Dec 25, 2016
  2. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    WorldHop
    ^WorldHop was added in latest few releases.

    WorldHop.to(int) to hop world, also WorldHop
    Players.newQuery() to find players
    Worlds.getCurrent() to get current world

    Join the #development channel on Slack if you have any more questions.
     
    CodeNinja likes this.
  3. CodeNinja

    Joined:
    Dec 20, 2016
    Messages:
    37
    Likes Received:
    3
    Awesome thanks, I'm thinking:
    !Players.newQuery().results().isEmpty()

    Not sure if this will detect my own player, will test.

    EDIT: doesn't detect own player, works fine. TY
     
  4. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    That will return true all of the time because your player would be returned.

    You could filter it:
    Code (Text):
    1. public boolean isPlayers() {
    2.     return !Players.newQuery().filter(player -> !Objects.equals(player, Players.getLocal())).results().isEmpty();
    3. }
     
    CodeNinja likes this.

Share This Page

Loading...