Booleans YAY Posted March 27, 2017 Share Posted March 27, 2017 (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. 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 March 27, 2017 by Booleans YAY Quote Link to comment Share on other sites More sharing options...
Explv Posted March 27, 2017 Share Posted March 27, 2017 (edited) So your snippet is just the API method: getMap().canReach() ?... I think most people are already aware of the existence of that method Also you probably want to put the null check before the call to canReach() Edited March 27, 2017 by Explv 8 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted March 27, 2017 Share Posted March 27, 2017 (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 March 27, 2017 by Khaleesi 3 Quote Link to comment Share on other sites More sharing options...
Rudie Posted March 27, 2017 Share Posted March 27, 2017 Damn I've been missing out! Great find! 2 Quote Link to comment Share on other sites More sharing options...
Acerd Posted March 27, 2017 Share Posted March 27, 2017 dank snippet fam 1 Quote Link to comment Share on other sites More sharing options...
Saiyan Posted March 27, 2017 Share Posted March 27, 2017 hey why does this throw a null pointer exception? 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted March 27, 2017 Share Posted March 27, 2017 Quote Link to comment Share on other sites More sharing options...
Pseudo Posted March 27, 2017 Share Posted March 27, 2017 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. Quote Link to comment Share on other sites More sharing options...
Juggles Posted March 27, 2017 Share Posted March 27, 2017 At first I thought you were saying there was an error with map.canReach. Then I saw it was a snippet I don't think it's necessary to post snippets of basic API codes. Might as well post snippets on how to open the bank using bank.open(); 1 Quote Link to comment Share on other sites More sharing options...