Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Checking distance between an NPC and GroundItem?

Featured Replies

Hey guys, I'm trying to check the distance between an NPC and GroundItem, so that whichever one is closer, I'll either attack it or loot it. How would I go upon doing this?

 

Also, what's the most efficient and fastest way of attacking an NPC?

 

Thanks!

 

EDIT: I think I figured it out:

if (myPlayer().getPosition().distance(npc) < myPlayer()
                        .getPosition().distance(grounditem))

Thanks anyways!

Edited by Annointed

Hey guys, I'm trying to check the distance between an NPC and GroundItem, so that whichever one is closer, I'll either attack it or loot it. How would I go upon doing this?

 

Also, what's the most efficient and fastest way of attacking an NPC?

 

Thanks!

 

You can get the real (walking) distance to the npc / ground item using:

int distance = getMap().realDistance(entity); // entity is the npc or ground item

Or the direct distance:

int distance = myPosition().distance(entity.getPosition());

Then just compare the two distances to find which is less.

 

For attacking the NPC you can just do something like:

NPC cow = getNpcs().closest(npc -> npc.getName().equals("Cow") && npc.isAttackable());

if (cow != null && cow.interact("Attack")) {
   new ConditionalSleep(5000) {
       @ Override
       public boolean condition() throws InterruptedException {
           return !cow.isAttackable();
       }
   }.sleep();
}

Edited by Explv

  • Author

 

You can get the real (walking) distance to the npc / ground item using:

int distance = getMap().realDistance(entity); // entity is the npc or ground item

Or the direct distance:

int distance = myPosition().distance(entity.getPosition());

Then just compare the two distances to find which is less.

 

For attacking the NPC you can just do something like:

NPC cow = getNpcs().closest(npc -> npc.getName().equals("Cow") && npc.isAttackable());

if (cow != null && cow.interact("Attack")) {
   new ConditionalSleep(5000) {
       @ Override
       public boolean condition() throws InterruptedException {
           return !cow.isAttackable();
       }
   }.sleep();
}

 

Thank you! Also, what's the difference between the normal sleep method, and ConditionalSleep? When would I use which?

Thank you! Also, what's the difference between the normal sleep method, and ConditionalSleep? When would I use which?

 

ConditionalSleep will sleep for MAX the amount of time you specify (in this case 5 seconds) OR until the condition is satisfied.

 

So in the example I gave it would sleep for up to 5 seconds or until the NPC is no longer attackable (either it is dead, someone else is attacking it, or we are attacking it)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.