Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Interact with GameObject while player us moving

Joined
Feb 9, 2019
Messages
44
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?
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
6,966
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.
 
Joined
Feb 9, 2019
Messages
44
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:
GameObject fire_position = GameObjects.newQuery().names("Brazier", "Burning brazier").on(this.coordList_BraziersRef[this.targetLocation]).results().first();
if (fire_position != null) {
    GameObjectDefinition def = fire_position.getDefinition();
    if (def.getActions().contains("Feed")) {
        //System.out.println("Burning 1 -> Try to feed fire!");
        //check to see if we have anything to burn!
        this.roundStart_LightBrazier = false;
        if (fire_position.isVisible() && item_burn_count > 0) {
            if (Players.getLocal().getHitsplats().size() > 0 || com.lb25.api.LocalPlayer.isLastAnimation(3000, animation_FeedingBrazier)) {
                System.out.println("Burning 3 -> click on fire!");
                //Camera.concurrentlyTurnTo(fire_position);
                fire_position.interact("Feed");
                //fire_position.click();
                Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
            }
            else {
                System.out.println("Burning Skipped");
            }
        }
    }
}
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
6,966
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:
GameObject fire_position = GameObjects.newQuery().names("Brazier", "Burning brazier").on(this.coordList_BraziersRef[this.targetLocation]).results().first();
if (fire_position != null) {
    GameObjectDefinition def = fire_position.getDefinition();
    if (def.getActions().contains("Feed")) {
        //System.out.println("Burning 1 -> Try to feed fire!");
        //check to see if we have anything to burn!
        this.roundStart_LightBrazier = false;
        if (fire_position.isVisible() && item_burn_count > 0) {
            if (Players.getLocal().getHitsplats().size() > 0 || com.lb25.api.LocalPlayer.isLastAnimation(3000, animation_FeedingBrazier)) {
                System.out.println("Burning 3 -> click on fire!");
                //Camera.concurrentlyTurnTo(fire_position);
                fire_position.interact("Feed");
                //fire_position.click();
                Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
            }
            else {
                System.out.println("Burning Skipped");
            }
        }
    }
}

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:
fire_position.interact("Feed");
Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);

with something like
Code:
if(fire_position.interact("Feed")){
Execution.delayUntil(()->Players.getLocal().getAnimationId() != -1, 750, 1500);
System.out.println("We successfully interacted!");
}

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.
 
Joined
Feb 9, 2019
Messages
44
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.
 
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 :)
 
Top