Jump to content

Interact with Entity, Not with Players


toxicity959

Recommended Posts

EDIT: Thanks to @HeyImJamie and @Explv for pointing out that this was much more complicated than necessary. This snippet accomplishes the same but more efficiently and reliably than my own method:

RS2Object furnace = objects.closest("Furnace");
if(getInventory().interact("Use", "Item") && getObjects().closest("Furnace") != null && getObjects().closest("Furnace").interact("Use")) {
	//Do things here
}

-----

While working on a script, I noticed that calling entity.interact() to use an object on an entity, such as in the case of using an item on a furnace to open the crafting interface, would occasionally (for me, more often than not) click on players standing in front of the furnace, rather than on the furnace itself. Although the method was clicking inside the furnace, players standing in front of the furnace would take priority, and I would end up using my item on the player standing in front of the furnace, resulting in a "Nothing interesting happens." message. I solved this problem using the following snippet: 

RS2Object furnace = objects.closest("Furnace");
if (!furnace.isVisible())
	camera.toEntity(furnace);
furnace.hover();
sleep(random(100, 500));
if(mouse.getEntitiesOnCursor().size() == 1 && mouse.getEntitiesOnCursor().get(0).equals(furnace)) {
	mouse.click(false);
	//Do things here
}

This simply moves the mouse over the furnace, then checks if the furnace is the only thing under the mouse. If this is true, then it will interact with the furnace, and then continue normally. If not, this cycle of the loop will be complete, and the next cycle will move the mouse once more and check again. This method has proven successful over many hours of testing my script, and has completely eliminated the "Nothing interesting happens." message.

Edited by toxicity959
Link to comment
Share on other sites

8 minutes ago, toxicity959 said:

While working on a script, I noticed that calling entity.interact() to use an object on an entity, such as in the case of using an item on a furnace to open the crafting interface, would occasionally (for me, more often than not) click on players standing in front of the furnace, rather than on the furnace itself. Although the method was clicking inside the furnace, players standing in front of the furnace would take priority, and I would end up using my item on the player standing in front of the furnace, resulting in a "Nothing interesting happens." message. I solved this problem using the following snippet: 


RS2Object furnace = objects.closest("Furnace");
if (!furnace.isVisible())
	camera.toEntity(furnace);
furnace.hover();
sleep(random(100, 500));
if(mouse.getEntitiesOnCursor().size() == 1 && mouse.getEntitiesOnCursor().get(0).equals(furnace)) {
	mouse.click(false);
	//Do things here
}

This simply moves the mouse over the furnace, then checks if the furnace is the only thing under the mouse. If this is true, then it will interact with the furnace, and then continue normally. If not, this cycle of the loop will be complete, and the next cycle will move the mouse once more and check again. This method has proven successful over many hours of testing my script, and has completely eliminated the "Nothing interesting happens." message.

 

This is what you should be doing:

if (getObjects().closest("Furnace").interact("Smelt")) {
    new ConditionalSleep(5000) {
        @Override
        public boolean condition() {
            return getWidgets().getWidgetContainingText("What would you like to smelt?") != null;
        }
    }.sleep();
}

 

Link to comment
Share on other sites

15 minutes ago, Explv said:

 

This is what you should be doing:


if (getObjects().closest("Furnace").interact("Smelt")) {
    new ConditionalSleep(5000) {
        @Override
        public boolean condition() {
            return getWidgets().getWidgetContainingText("What would you like to smelt?") != null;
        }
    }.sleep();
}

 

 

23 minutes ago, HeyImJamie said:

Why would you not just use the interact method with a String, such as "Use"? 

Because I didn't realize I could just use "Use" as my interact argument (whoops!). Here I was thinking I was so clever with my workaround. Thanks guys, I'll update OP to reflect my mistake for posterity.

  • Like 1
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...