clanket Posted August 18, 2017 Share Posted August 18, 2017 I'm trying to make a bot script for powermining. Is there any code that interacts with an entity at a specific location instead of proximity. EX: RS2Object rock1 = getObjects().position(1,2,3); if(MINING_AREA.contains(myPlayer())) { if (rocks != null) { if (!myPlayer().isAnimating()) { rock1.interact("Mine"); } } } instead of RS2Object rocks = getObjects().closest("Rocks"); if(MINING_AREA.contains(myPlayer())) { if (rocks != null) { if (!myPlayer().isAnimating()) { rocks.interact("Mine"); } } } Quote Link to comment Share on other sites More sharing options...
Team Cape Posted August 18, 2017 Share Posted August 18, 2017 What you'll want to use is a Filter - this will use only objects that match your conditions. Position desiredPosition = new Position(1, 1, 1); //this definition should go right beneath your class definition RS2Object rock = getObjects().closest(o -> o != null && o.getName().equals("Rocks") && o.getPosition().equals(desiredPosition)); //o represents the object. The conditions you'll want to check are that it is not null, it is in fact the correct type //of RS2Object, and that it has the correct position (all shown in the filter above). Note, this does not differentiate between different types of rocks. Quote Link to comment Share on other sites More sharing options...
clanket Posted August 19, 2017 Author Share Posted August 19, 2017 I'm a little lost and have been trying to figure this out for over an hours now. Is there any way to do it without lambda expressions. The code is probably all wrong, but any help would be appreciated. Still a novice here so you might have to be a little more specific. case MINE: RS2Object rocks = getObjects().closest("Rocks"); RS2Object rock = getObjects().closest(rock -> rock != null && rock.getName().equals("Rocks") && rock.getPosition().equals(rock1)); if(!MINING_AREA.contains(myPlayer()) && !inventory.isFull()) { getWalking().walk(mining_spot); } if(MINING_AREA.contains(myPlayer())) { if (rocks != null) { if (!myPlayer().isAnimating()) { rocks.interact("Mine"); } } } Quote Link to comment Share on other sites More sharing options...
Lemons Posted August 19, 2017 Share Posted August 19, 2017 (edited) class MyMiner extends Script { Position rockLocation = new Position(1, 2, 0); // ... public int onLoop() { // ... case MINE: // This is incorrect, this will simply return the closest rock regardless of position. Define a position ahead of time, else explain what your end goal is. //RS2Object rocks = getObjects().closest("Rocks"); // This is the correct way to filter by location with Lambdas, not the null check is note needed (@Team Cape) // Also note I changed the variable to "o", as it is not a rock but an RS2Object RS2Object rock = getObjects().closest(o -> o.getName().equals("Rocks") && o.getPosition().equals(rockLocation)); // If you'd like to use OSBots Filter's you can also do: (commented to avoid errors) //RS2Object rock = getObjects().closest(new NameFilter<RS2Object>("Rocks"), new PositionFilter<RS2Object>(rockLocation)); // Really, this should be moved to another state assuming you're using a state model. Your loading null rocks for no reason. if(!MINING_AREA.contains(myPlayer()) && !inventory.isFull()) { getWalking().walk(mining_spot); } // This if could simply be an else of the previous if statement if(MINING_AREA.contains(myPlayer())) { // Switched everything from "rocks" to "rock" if (rock != null && rock.exists() && !myPlayer().isAnimating()) { rock.interact("Mine"); } } It would really help if you would explain the end goal. Do you really just want to mine one rock at a specific location? This still doesn't check if the rock contains ore. If you'd like to mine certain rocks like Copper/Tin or Iron. Edited August 19, 2017 by Lemons Quote Link to comment Share on other sites More sharing options...
clanket Posted August 19, 2017 Author Share Posted August 19, 2017 I'm setting it up so it will powermine a 3 spawn of iron in one spot. I had a working version earlier but it would often click on ores that were gone. My goal with the nodes is that it will mine them in order and not mess up on inactive veins. I may later adapt to it do 2S2G 3 tick mining once this version is working. Quote Link to comment Share on other sites More sharing options...