Jump 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.

Fast Question

Featured Replies

Here's the code

 

NPC cow = npcs.closest("Cow", "Cow calf");

 

if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack()  && !cow.isUnderAttack() && cow != null)

{

cow.interact("Attack");

}

 

Now basically what happens is it will target the closest cow even if it's in combat so it will just wait until the cow is dead to target a new cow. How would I make it do something like: npc.closest("Cow", "Cow calf").!isUnderAttack

 

Sorry for all the questions, but this script i'm working on i'll put in the local script section so hopefully if it works

Edited by Snowydell

Make a filter for it. A filter will basically only accept npcs that meet a specific criteria, i.e. the cow is not under attack. There might be something in the api for this already, but this is a way you can do it without an api method.

 

Here's the code
 
NPC cow = npcs.closest("Cow", "Cow calf");
 
if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack()  && !cow.isUnderAttack() && cow != null)
{
cow.interact("Attack");
}
 
Now basically what happens is it will target the closest cow even if it's in combat so it will just wait until the cow is dead to target a new cow. How would I make it do something like: npc.closest("Cow", "Cow calf").!isUnderAttack
 
Sorry for all the questions, but this script i'm working on i'll put in the local script section so hopefully if it works

 

you could always try

 NPC cow = npcs.closest(new Filter<NPC>() {
             @Override
             public boolean match(NPC npc) {
                 return npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null
                         && npc.getHealth() >0 && npc.isAttackable() && !npc.isUnderAttack();
             }
         });
if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack() && cow != null)
{
cow.interact("Attack");
}

 
 

Edited by Isolate

 

you could always try

return npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null
                         && npc.getHealth() >0 && npc.isAttackable() && !npc.isUnderAttack();
             

why are you checking for if the pointer is null after your already using the instance

why are you checking for if the pointer is null after your already using the instance

Because I like to be sure ;) long time no doge

why are you checking for if the pointer is null after your already using the instance

 

 

Because I like to be sure wink.png long time no doge

 

He means why are you doing this:

npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null

null checking npc after you call npc.getName is pointless. If there is an NPE you will get it on npc.getName, and thus null checking after you call a method from that object is pointless. The NPE will not be avoided at all.

He means why are you doing this:

npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null

null checking npc after you call npc.getName is pointless. If there is an NPE you will get it on npc.getName, and thus null checking after you call a method from that object is pointless. The NPE will not be avoided at all.

move it to the start then.

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

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.