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.

Null check

Featured Replies

script keeps getting stuck on a if(closestObject(9345) != null)    the object is a bird snare and it is on the ground when it cycles through to the null check but it never gets passed. I've tried using closestNPC(), closestObjectForName(), ClosestNPCForName() all dont make it passed the null check.

	public void LaySnare() throws InterruptedException {
		Inventory Inven = client.getInventory();
		final RS2Object GroundSnare = closestObject(9345);
		final Entity player = client.getMyPlayer();
		if (player != null)
			if (HuntingGround.contains(player)) {
				if (Inven.contains(BirdSnareItem) == true) {
					Inven.interactWithName(BirdSnareItem, InteractSnare);
					sleep(10000);
					if(GroundSnare != null){
						log("logging snare position");
					snare = GroundSnare.getPosition();
					if(!Inven.contains(BirdSnareItem)){
						log(DetectState);
						StateHolder = 0;}
				 }
				}
			} else {
				walkExact(HuntingGround);
			}
	}

Edited by jua1

script keeps getting stuck on a if(closestObject(9345) != null)    the object is a bird snare and it is on the ground when it cycles through to the null check but it never gets passed. I've tried using closestNPC(), closestObjectForName(), ClosestNPCForName() all dont make it passed the null check.

 

do you want to pick it back up off the floor when it collapses?

  • Author

nah after the null check i log its position so that you can run this with other people hunting in the same area and not try to pick up their snares, but the problem is the getPosition() requires a null check and i've also tried exist().

 

Edited by jua1

  • Author
RS2Object snare = closestObjectForName("Bird snare");

if(snare != null){
     snare.interact("Dismantle");
}

 

tried this it didn't work.

If it's on the ground, it could be a GroundItem

so GroundItem birdsnare = closestGroundItemForName("Bird snare");

if(birdsnare != null)
   do stuff

  • Author

thats possible but when i place it on the ground i get no value for ground item. Worth trying though il try it right now.


Yea its not a ground item

 

thats possible but when i place it on the ground i get no value for ground item. Worth trying though il try it right now.

Yea its not a ground item

First things first I think you need to be more clear as to what you're trying to do with the trap, bird traps have 4 states: 

  • Layed (Waiting for Bird to smoke) id  = 9345
  • Smoked (Failed to catch crimson) id = 9344
  • Caught (Caught the Crimson) id = 9373
  • Fell down (This is a  GroundItem now) id: 10006

With the ID you provided in the OP you are trying to do something with the "Layed" trap which doesn't really make sense but hope this gives some clarity:

 

I'll give you a snippet of what's in my Divinity Birds script which works perfectly:

RS2Object setTrap = closestObjectForId(9345);

if(setTrap != null){
  if(setTrap.isVisible()){
     setTrap.interact("Dismantle");
     sleep(random(700,1200));
  } else {
    client.moveCameraToEntity(setTrap);
  }
}

Edited by Divinity

  • Author

this is only a snippet of the code that is where its getting stuck. If i dont getPosition of the snare my script works perfectly. I need to log their positions though so you can run the script next to other bots or else its going to try to pick up other ppls snares. Im telling you guys I am only having problem with the null check for closestObjectForName("Bird Snare")

this is only a snippet of the code that is where its getting stuck. If i dont getPosition of the snare my script works perfectly. I need to log their positions though so you can run the script next to other bots or else its going to try to pick up other ppls snares. Im telling you guys I am only having problem with the null check for closestObjectForName("Bird Snare")

Ahhhh in that case you need to make sure it's spelt correctly... it's "Bird snare" with a small "s"

  • Author

yea sorry i spelt it correctly in the script

 I think im going to do it a different way because this is not working it seems that the null check doesnt work for this object.

yea sorry i spelt it correctly in the script

 I think im going to do it a different way because this is not working it seems that the null check doesnt work for this object.

If you would like me to teamview you to sort the issue I would be more than happy. Just pm me your credentials if so ^_^

Just so you can get better:

  1. NEVER EVER EVER EVER EVERRRRRR check for a boolean value by doing "==" or anything of the sort
  2. Final variables should be all caps separated by _ characters for spaces
  3. Variables/methods should be camelCased (unless their final)
  4. Not sure if just how you copy/pasted but your brackets are all over the place
  5. What is the point of making those variables final

As for your question, try logging before that line what the ground snare is equal to.

  • Author

so all those who have had trouble with this use getX() and getY() don't check for null just keep the same position for both snares.

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.