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 Interacting with a moving target

Joined
Jan 3, 2020
Messages
4
I'm having issues with the bot interacting with a moving target, such an an NPC. The mouse seems to go to the last position of the NPC, but by the time it gets there the NPC has moved so the mouse just slowly trails the NPC until they stop moving. There are no issues when the NPC is not moving; the code executes instantaneously.

I've tried using the hover command, forcing menu interactions, increasing the mouse speed multiplier and using the MLP mouse path.

Any help would be appreciated.

Sample code below

Code:
while(Secondfloor.contains(Player.getlocal()){
     target = Npcs.newQuery().actions("Trade").results.nearest();
     if(target !=null){
          if(target.interact("Trade"){
......
          }
     }
.......
}
......
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
6,661
I'm having issues with the bot interacting with a moving target, such an an NPC. The mouse seems to go to the last position of the NPC, but by the time it gets there the NPC has moved so the mouse just slowly trails the NPC until they stop moving. There are no issues when the NPC is not moving; the code executes instantaneously.

I've tried using the hover command, forcing menu interactions, increasing the mouse speed multiplier and using the MLP mouse path.

Any help would be appreciated.

Sample code below

Code:
while(Secondfloor.contains(Player.getlocal()){
     target = Npcs.newQuery().actions("Trade").results.nearest();
     if(target !=null){
          if(target.interact("Trade"){
......
          }
     }
.......
}
......
My first reaction is why are you using a while() loop here? That should just be an if() statement. Loops should be avoided in your bot unless you fully understand why you're using it and have a good reason.

There's a good chance just changing while to if will fix this.
 
Joined
Jan 3, 2020
Messages
4
There's a lot more code in the while loop that I didn't post to keep things concise. From trial and error I found writing while statements around some actions made the code run faster. If, for whatever reason the script misses the command, it can just re-loop that section of code until it is successful instead running through the whole tree. This is especially helpful if a number of menus or actions need to be done in succession.

Removing the while loop and replacing with an if statement didn't resolve the issue. What I noticed is that the interact option has to hover the target before it can execute. If the NPC has moved from the coordinate since the command was issued, it will continue to loop until it is able to hover the NPC. This results in the mouse slowly trailing the NPC until they stop moving (I have a custom overlay to see the mouse).

I ended up writing a separate block of code that forces the mouse to the location of the NPC with a high mouse speed multiplier and creates a menu interaction (right click) when the NPC is moving.

In any case, I appreciate your input as I've noticed that a lot of threads don't end up receiving replies.
 
Last edited:
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
6,661
There's a lot more code in the while loop that I didn't post to keep things concise. From trial and error I found writing while statements around some actions made the code run faster. If, for whatever reason the script misses the command, it can just re-loop that section of code until it is successful instead running through the whole tree. This is especially helpful if a number of menus or actions need to be done in succession.

Removing the while loop and replacing with an if statement didn't resolve the issue. What I noticed is that the interact option has to hover the target before it can execute. If the NPC has moved from the coordinate since the command was issued, it will continue to loop until it is able to hover the NPC. This results in the mouse slowly trailing the NPC until they stop moving (I have a custom overlay to see the mouse).

I ended up writing a separate block of code that forces the mouse to the location of the NPC with a high mouse speed multiplier and creates a menu interaction (right click) when the NPC is moving.

In any case, I appreciate your input as I've noticed that a lot of threads don't end up receiving replies.
Ah yeah, that makes enough sense then, it was just the only thing that stood out to me as the rest of the code looks correct to me.

Just as a side note, if you're having an issue like this and not getting a response on forum, I'd recommend asking either the slack or discord development channels, they're fairly active.
 
Top