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

Question Interact with GameObject while player us moving

Discussion in 'Developer Support' started by lb25, Dec 11, 2019.

  1. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    This is more conclusion by observation. Though it appears when I query for a GameObject, it returns the correct one. If i do
    obj.interact("interaction...")
    it looks like it will only interact with the object of the "interaction" is still at the old mouse position. But if the player was to move, this would only be successful if the player was stationary. On the other hand if I do:
    obj.click();
    It will click on the target mouse position regardless if target is still there. What I wanted to find out, was what is the best way for a player to be moving while correctly interacting with an object, is it possible to get an up-to-date mouse position of target while player is moving to give a new position without doing the full query?

    It appears the calculation isn't quite fast enough to return out of the function and interact with the object while my player is on the move, by then the mouse position is already too old. This could be my hardware or whatever else.

    Nonetheless is there a better way to interact with these objects while on the move? Or is the only way to have the camera so I am running directly at the target where the mouse position doesn't require to be moved?
     
  2. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,113
    Likes Received:
    1,371
    I haven't written bots in a while but it sounds like you're probably doing something wrong here and the bot is performing the action on the next iteration or something. Is there a lot of code in your project? Could you post the relevant chunk of code so we can double check it?

    Unless anyone else has proper advice.
     
  3. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    The debug message "burning 3 click on fire" appears, but does not click. If I change this line to obj.click instead, it will click past the object if my player is moving

    Code (Text):
    1. GameObject fire_position = GameObjects.newQuery().names("Brazier", "Burning brazier").on(this.coordList_BraziersRef[this.targetLocation]).results().first();
    2. if (fire_position != null) {
    3.     GameObjectDefinition def = fire_position.getDefinition();
    4.     if (def.getActions().contains("Feed")) {
    5.         //System.out.println("Burning 1 -> Try to feed fire!");
    6.         //check to see if we have anything to burn!
    7.         this.roundStart_LightBrazier = false;
    8.         if (fire_position.isVisible() && item_burn_count > 0) {
    9.             if (Players.getLocal().getHitsplats().size() > 0 || com.lb25.api.LocalPlayer.isLastAnimation(3000, animation_FeedingBrazier)) {
    10.                 System.out.println("Burning 3 -> click on fire!");
    11.                 //Camera.concurrentlyTurnTo(fire_position);
    12.                 fire_position.interact("Feed");
    13.                 //fire_position.click();
    14.                 Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
    15.             }
    16.             else {
    17.                 System.out.println("Burning Skipped");
    18.             }
    19.         }
    20.     }
    21. }
     
  4. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,113
    Likes Received:
    1,371
    Oh, I think I might have gotten it. Like I said I'm pretty out of practice, but this might help.

    Things like obj.interact("..."); return a boolean saying if the action was completed or not, and if it returns false it means the bot is still in progress of performing the action. Behind the scenes, interact is actually multiple actions being performed and might take more than 1 bot iteration to actually complete. obj.click() is less actions so more likely to perform it, but it might miss (which also returns false).

    So I assume both obj.interact and obj.click are currently returning false.

    Surround
    Code (Text):
    1. fire_position.interact("Feed");
    2. Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
    with something like
    Code (Text):
    1. if(fire_position.interact("Feed")){
    2. Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
    3. System.out.println("We successfully interacted!");
    4. }
    It's best practice to put all your action executions in if statements to check the boolean returned and see if they actually happened, or they're in the process of happening, or the bot misclicked and needs to click again.
     
  5. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    I like your thinking, skip the animation check if the object never clicked successfully.

    Just FYI it doesn't always return true, even if it did successfully click on it ;) nonetheless i'll keep you posted.
    --- Double Post Merged, Dec 11, 2019, Original Post Date: Dec 11, 2019 ---
    Doing some timing on how long certain tasks for taking in my bot, it appears from the start of the method, it took 2.5s.
    Specifically over:
    if(fire_position.interact("Feed"))
    it took 700ms to execute this one operation :/
    A few other tasks like checking if my inventory was empty of wood and 2 other gameobject queries took another 1200ms :|

    Going to have to go through my code and find ways to optimise these queries. They appear to be what is slowing me down atm. Either that I am doing too many, or trying to do them by matching strings is the wrong way. Java, not exactly the most efficient language for this stuff :)
     

Share This Page

Loading...