Jump to content

Move away from other player


digitaltoaster

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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) {
  // ..
}

?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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