Jump to content

Interacting with entities


clanket

Recommended Posts

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");
                    }
                }
            }
                        

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");
                    }
                }
            }
            
      

Link to comment
Share on other sites

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

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.

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