Jump to content

Reachable Item checking


Booleans YAY

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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