Jump to content

Move away from other player


Recommended Posts

Posted

Im trying to move away my player of another player is standing next to it, but it does not seem to do anything.

I have tried alot of different methods, but none seem to work.

Here is what I have now:

 

    private void moveAway(Player player) throws InterruptedException
    {
        try {
            if (isRanger) {

                if (!(abs(myPlayer().getPosition().getX() - player.getPosition().getX()) > 1) && !(abs(myPlayer().getPosition().getY() - player.getPosition().getY()) > 1)) {
                    log("Trying to move");

                    WalkingEvent event = new WalkingEvent(player).setMinDistanceThreshold(3);
                    execute(event);
                }
            }
        }catch (RuntimeException ex)
        {
            log(ex);
        }
    }

Best would be if it clicked on the screen and not he minimap.

 

Thanks in advance.

Posted

Couple of things. Firstly, it might be worth taking a look at the WalkingEvent API https://osbot.org/api/org/osbot/rs07/event/WalkingEvent.html (specifically setMinDistanceThreshold, which presumably doesn't do what you think it does)

Secondly, it is worth noting that a Position (https://osbot.org/api/org/osbot/rs07/api/map/Position.html) represents an in-game tile. You might find your 'same tile' check can be simplified:

if (myPlayer().getPosition().equals(player.getPosition())) {
  // ..
}

Best of luck

Apa

Posted

Instead of calculating the distance like that what you can do is

if (myPosition().equals(player.getPosition())

And the reason why you're not moving is because your walking event is trying to walk to the player itself.

WalkingEvent event = new WalkingEvent(player).setMinDistanceThreshold(3);
should be
WalkingEvent event = new WalkingEvent(the position you want to walk to);

 

Posted
7 minutes ago, d0zza said:

Instead of calculating the distance like that what you can do is


if (myPosition().equals(player.getPosition())

And the reason why you're not moving is because your walking event is trying to walk to the player itself.


WalkingEvent event = new WalkingEvent(player).setMinDistanceThreshold(3);
should be
WalkingEvent event = new WalkingEvent(the position you want to walk to);

 

I got it working now thanks. 

And yes I know I can use 

if (myPosition().equals(player.getPosition())

But that only checks if iets the exact same position. And I also need to know if it is next to him. So I need to absolute difference between player and use X and Y.

Posted
6 minutes ago, digitaltoaster said:

I got it working now thanks. 

And yes I know I can use 


if (myPosition().equals(player.getPosition())

But that only checks if iets the exact same position. And I also need to know if it is next to him. So I need to absolute difference between player and use X and Y.

Have you considered:

if (getMap().distance(player) <= 1) {
  // ..
}

?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...