Simply clicking

Discussion in 'Developer Support' started by Philosobyte, Dec 22, 2014.

  1. I'm sorry if this is basic, but I'm getting very frustrated because something that should be absurdly simple is not working out.

    For some reason, with the following code, the mouse would have an approximately 1/3 chance of not pulling the second click off and skipping directly to that last part of the code. The mouse always moves right next to the actual SpriteItem, without getting to it.

    SpriteItem arrowShafts;
    SpriteItem feathers;

    if(Inventory.containsAllOf(ARROW_SHAFT_ID, FEATHER_ID))
    {
    arrowShafts = Inventory.getItems(ARROW_SHAFT_ID).first();
    feathers = Inventory.getItems(FEATHER_ID).first();
    }

    arrowShafts.click();
    // Execution.delay(56, 256, 128);

    feathers.click();
    // Execution.delay(56, 256, 128);

    Execution.delayUntil(() -> someInterface.isVisible(), 400, 800);
    Keyboard.typeKey(" ");

    I tried amending this with various constructs, such as

    Execution.delay,
    surrounding the clicks with if statements,
    clicking the interactable bounds instead of the SpriteItem itself,
    delayUntil() -> feathers.click().

    None of them made any difference except the last one, which caused problems by clicking more than once every time. Is the mouse is clicking on the edge of the inventory slot without clicking on the SpriteItem itself? Is there a way to ascertain that the second click will happen?
     
    #1 Philosobyte, Dec 22, 2014
    Last edited: Dec 22, 2014
  2. if (shafts are selected){
    if(feathers.click()){
    delay until interface;
    send space;
    }
    } else {
    select feathers;
    }
    Maybe try something like that instead?
     
  3. Thanks. Just had to add more conditions, like Hax said, and split everything into different methods to enable the loop to start over. The clicks still fail 1/3 of the time, but the loop starts over if that happens.
    Code (Text):
    1.  
    2. @Override
    3.     public void onLoop()
    4.     {
    5.         clickSpriteItems();
    6.         Execution.delayUntil(() -> addFeather.isVisible(), 400, 800);
    7.         getAddFeather();
    8.         if(addFeather.isVisible())
    9.         {
    10.         Keyboard.typeKey(" ");
    11.         Execution.delayUntil(() -> count >= 9);
    12.         count = 0;
    13.         }
    14.         else
    15.         {
    16.             return;
    17.         }
    18.         Execution.delay((long)Random.nextGaussian(0, 20260, 256, 0.477));
    19.     }
    20.  
    21.     public void clickSpriteItems()
    22.     {
    23.         getSpriteItems();
    24.         if(Inventory.getSelectedItem() != null)
    25.         {
    26.             Inventory.getSelectedItem().getBounds().click();
    27.         }
    28.         if(arrowShafts.getInteractionPoint().click())
    29.         {
    30.             Execution.delay((long) Random.nextGaussian(56, 256, 128));
    31.             System.out.println("click");
    32.             if(feathers.getInteractionPoint().click())
    33.             {
    34.                 Execution.delay((long) Random.nextGaussian(56, 256, 128));
    35.                 System.out.println("click");
    36.                 Execution.delay(500);
    37.                 getAddFeather();
    38.             }
    39.         }
    40.     }
    41.  
     
  4. As a note, the logic shown in this thread is rather bad and prevents the script bot from being able to "humanly" handle many situations. For example, if interacting with the arrow shafts is successful but then it fails to interact with the feathers, it will deselect the arrow shafts, reselect them, and then repeat the process. Also, you can and should be directly interacting with the sprite items, not necessarily the bound or point objects. This is because interacting with the objects themselves occasionally has special per-entity behavior.
     
  5. Yes, I was unaccustomed to the client's execution of the API and was frustrated at unsuccessful clicks returning true. I think I've improved and hope you can give me feedback on the logic in my Nature Altar Runner, which I will submit tomorrow in a messy state, but which will be cleaner and more conceptually sound in the commit after that. I will also improve this script bot tomorrow.
     
    #5 Philosobyte, Dec 28, 2014
    Last edited: Dec 28, 2014

Share This Page

Loading...