Jump to content

Reachable Item checking


Recommended Posts

Posted (edited)

So I ran a few scripts that'd get stuck trying to grab arrows from across the fence on the other side which would stop the bot from ignoring the fact that they can't actually reach it cause of clipped fence.

Here's a neat snippet for reachable ground item checking.

			GroundItem groundItems = getGroundItems().closest("Bronze arrows", "Feather");
			
			if (getMap().canReach(groundItems) && groundItems != null) {
				groundItems.interact("Take");
			}

The white circle is where arrows would appear from drops from the npcs shown right beside the circle or however they would apparently appear there.

SXt7e96.png

 

Should be pretty self explanatory, or even known. But I haven't personally seen this released or used in the few scripts I ran so eh.
For those wonder why I'm collecting arrows, it's to chance collect other players arrow drops, etc.. (just testing purposes right now).

Edited by Booleans YAY
Posted (edited)

How is that neat if you null check AFTER using the object? :???:
 

GroundItem groundItems = getGroundItems().closest("Bronze arrows", "Feather");
			
			if (groundItems != null && getMap().canReach(groundItems)) {
				groundItems.interact("Take");
			}

If you don't want a shitload of NPE's thrown in your face you should null check BEFORE actually using it ;)

Edited by Khaleesi
  • Like 3
Posted

Good job on the contribution, it's nice that somebody is trying to help out;

 

As said above, if you null check after performing an action regarding the item, then it's pretty much redundant, so you should always validate the item first. Though, I don't know why so many are bashing when you're just trying to help.

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