Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold
Node

[Snippet] Menu Hovering

Recommended Posts

I noticed the API doesn't have a built-in method to hover over menu options after right clicking. Here's a simple snippet could be handy for someone.

 

This isn't ABCL compliant - change the General.sleep(50, 100) to suit your requirements.

import org.tribot.api.Clicking;import org.tribot.api.General;import org.tribot.api.input.Mouse;import org.tribot.api.interfaces.Clickable;import org.tribot.api2007.ChooseOption;import org.tribot.api2007.types.RSMenuNode;import java.awt.*;/** * A simple menu hovering utility. * * @author Node * @[member="see"]  */public class MenuHovering {    /**     * Right clicks on a <tt>Clickable</tt> entity and hovers over a menu option.     *     * @param entity the <tt>Clickable</tt> entity (<tt>RSItem</tt>, <tt>RSNPC</tt>, <tt>RSGroundItem</tt>, etc)     * @param option the text of the option to hover over, eg <i>Examine</i>     * @return <tt>true</tt> if successful, <tt>false</tt> otherwise     */    public static boolean hover(Clickable entity, String option) {        return hover(entity, option, General.random(-20, 20), General.random(-5, 5));    }    /**     * Right clicks on a <tt>Clickable</tt> entity and hovers over a menu option.     *     * @param entity the clickable entity (<tt>RSItem</tt>, <tt>RSNPC</tt>, <tt>GroundItem</tt>, etc)     * @param option the text of the option to hover over, eg <i>Examine</i>     * @param offsetX the X offset to apply     * @param offsetY the Y offset to apply     * @return <tt>true</tt> if successful, <tt>false</tt> otherwise     */    public static boolean hover(Clickable entity, String option, int offsetX, int offsetY) {        if (entity == null || option == null) {            return false;        }        if (Clicking.hover(entity)) {            Point pos = Mouse.getPos();            Mouse.click((int) pos.getX(), (int) pos.getY(), 3);            General.sleep(50, 100); // CHANGE THIS TO YOUR REQUIREMENTS            if (!ChooseOption.isOpen()) {                return false;            }            for (RSMenuNode node : ChooseOption.getMenuNodes()) {                if (node.contains(option)) {                    int x = (int) node.getArea().getCenterX() + offsetX;                    int y = (int) node.getArea().getCenterY() + offsetY;                    Mouse.move(x, y);                    return true;                }            }        }        return false;    }}

Cheers,

Node.

Edited by Node

Share this post


Link to post
Share on other sites
Array

I have a snippet I used to rig up something similar in the past.

I think it would be a nice suggestion to have the nodes implement the clicking interface.

Also the Ability to right click clickable's, as I'm not aware of any client methods able to right click.

other than those within the Mouse class, and DynamicClicking( the aforementioned being a source of numerous script shortcomings).

There is a fine line to walk though, because methods like that encourage custom clicking methods (which we all know are 99.9% of the time terrible)

DynamicClicking being the class of choice to adhere to client based methods, and the advantages that are inherited from doing so.

Basically I created a fake RSItem object and set it's area.

By doing so, I was able to utilize all standard client clicking methods.

 

Also @Node your snippet can get stuck in certain cases if the chooseoption open is not the intended chooseoption,

causing an infinite loop(if called sequentially) .

	boolean hoverNPCOption(RSNPC npc, final String option){		if(!ChooseOption.isOptionValid(option)){			if(ChooseOption.isOpen()){				ChooseOption.close();			}			else{				if(DynamicClicking.clickRSNPC(npc, 3)){					Timing.waitCondition(new Condition(){						@Override						public boolean active() {							return ChooseOption.isOptionValid(option);						}											}, General.random(300,500));				}			}		}		if(ChooseOption.isOptionValid(option)){			for(RSMenuNode i: ChooseOption.getMenuNodes()){				if(i.contains(option)){					Rectangle r = i.getArea();					if(r!=null){						if(!r.contains(Mouse.getPos())){							RSItem dummyItem = new RSItem(-1,-1,-1,RSItem.TYPE.OTHER);							dummyItem.setArea(r);							return dummyItem.hover();						}						else{							return true;						}					}				}			}		}		return false;	}
Edited by warfront1

Share this post


Link to post
Share on other sites

@warfront1 There's no chance of this getting stuck - it will always return whether successful or not. Anyone who implements this should put in their own failsafes in case the ChooseOption isn't available. This isn't the remit of a utility method. The responsibility should be with the caller, like most methods in TRiBot's API. I agree with everything else though.

 

A suggestion on your snippet I would put forward is:

if(!r.contains(Mouse.getPos())){      RSItem dummyItem = new RSItem(-1,-1,-1,RSItem.TYPE.OTHER);      dummyItem.setArea(r);      return dummyItem.hover();}   else {       return true;}

You could probably lose the if and else altogether as, from a human perspective, you would probably move the mouse slightly even if you're already hovering over it, but that's debatable.

 

Other than that, your snippet looks like a good workaround too.

Edited by Node

Share this post


Link to post
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.


  • Similar Content

    • By drunksigma
      I'm trying to get the bot to click the nearest cowhide ground item. If i don't open it with right click using dynamicclick or any other clicking method which can be used to right left click then it just clicks on the grounditem stack and does not left click and then click the right take item option from the menunode.
      When i do it like i have done in this code snippet it only picks the first take option which is not the correct one. How can i solve this?
       
      RSGroundItem items[] = GroundItems.find("Cowhide"); GroundItems.sortByDistanceA(Player.getPosition(), items);; if(!items.equals(null)) { println("here2"); for(RSGroundItem index: items) { println("here3"); println(index); if(!index.isClickable()) { Camera.turnToTile(index.getPosition()); if(DynamicClicking.clickRSGroundItem(index,3)) { ChooseOption.select("Take"); } }else { if(DynamicClicking.clickRSGroundItem(index,3)) { ChooseOption.select("Take"); } } sleep(1000); break; } //DynamicClicking.clickRSGroundItem(items[0],"Take") }  
  • Our picks

    • [CONTEST ANNOUNCEMENT] 2019 Botter's Choice Awards
      2019 Botter’s Choice Awards

      To celebrate the launch of our TRiBot Official RuneScape Bot Blog,

      we’re doing a giveaway! 

      The TRiBot Official RuneScape Bot Blog: 

      Teaching you how to do more advanced botting, faster.
      Contest Details

      Prize: 3 winners will be selected to win 25 TRiBot credits.

      How to enter:

      Respond to this forum post by November 12th tagging the thread for: 

      Your favorite script

      Provide a brief explanation (1-2 sentences) why you think that script should be put in the top 5. 

      Who can enter?

      Botter’s who are not currently scripters. Sorry scripters, the people are going to vote. Your contest is here.

      The top 5 in each category will be showcased on our TRiBot Official RuneScape Bot Blog in a “People’s Choice” section and promoted across the TRiBot website. 

      -- Credits will be awarded based on thoughtfulness and humor -- 

      Bonus points

      Use a meme in your explanation. Because we all love memes.

      *no purchase necessary. Winners will be announced on Friday, November 15, 2019 at 4:00 p.m. on our News and Announcements forum. 

      -- Vote Below -- 
        • Like
      • 28 replies
    • [READ TO THE END FOR A TEASER]

      I've noticed some new TRiBotters have had some troubles finding out sources of how to do certain things, such as using advanced scripts and often get lost in the forums.

      We are still getting posts asking where to start, what to do, recommended scripts, etc. 

      As many of you know, I am new to the team, and had troubles myself learning how to bot, let alone script. 

      So, what our team decided to do was make it easier to learn how to bot, how to script, and just become an overall better botter and scripter faster. 

      As some of you might have seen, I've posted 3 new blogs, you can check it out by clicking on the following picture or here.


      These first 3 blogs are the first of many blogs that will be TRiBot official. They are encouraged to be challenged, improved upon and act as A Best Practices Guide for Botters.

      What information would you like to see in the blogs?

      👇 [TEASER] 👇

      .

      .

      .

      We are going to be hosting a  CONTEST  this  OCTOBER.

      Its scary to think how soon you'll find out.👻

      Stay tuned.


      - RileyZ
      • 8 replies
    • Today marks a big day for TRiBot! To make it easier for users to use TRiBot, we've created installers available for every platform! These installers are all bundled with the latest version of OpenJDK 1.8 (Java 😎, which is LG compatible.

      Using TRiBot is now easy. Simply download the installer for your platform, install TRiBot, and run it. The TRiBot Loader will correctly identify the bundled JDK so there's no need to change the Java selection.

      Windows

      EXE installer: TRiBot-windows-x64-4.0.3.exe


      MSI installer: TRiBot-windows-x64-4.0.3.msi


      Portable version: TRiBot-windows-x64-4.0.3.zip


      Mac OS

      Installer: TRiBot-macos-4.0.3.dmg


      Portable version: TRiBot-macos-4.0.3.tgz


      Unix/Linux

      Installer: TRiBot-unix-4.0.3.sh


      RPM installer (CentOS/Fedora): TRiBot-linux-4.0.3.rpm


      DEB installer (Debian): TRiBot-linux-4.0.3.deb


      Portable version: TRiBot-unix-4.0.3.tar.gz


      Platform Independent

      JAR file: tribot-loader-4.0.3.jar


      Note that this jar file does not include the bundled JDK.



      Windows and Mac OS users may notice a warning message stating that the installer/application is un-recognized or un-trusted. Please ignore this message and proceed with running the installer/application. We need to acquire a code signing certificate so that we can sign the installers letting the operating system know that these files can be trusted. It will take a week or more to acquire one, so please hold tight.

      Other notable changes to the TRiBot Loader:

      Support getting the version from OpenJDK distributions


      Add check for bundled JDK


      Copy OpenJDK tools.jar to the bundled JDK if not present


      Set the current java as the first available list entry


      Ignore Java versions which are symbolic links


      Make the bundled JDK the preferred Java version


      Update icon images


      Reduce the number of HTTP calls
      • 32 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
      • 18 replies
    • Hello TRiBot,

      Today we have a significant release that has been in the works for the last month addressing several key issues, features and bugs in the backlog.

      With these changes, we are also including a new TRiBot Loader which will allow you to select any version that is released. This adds the flexibility of allowing you to revert to a previous version should an issue arise, run development only builds, view an accurate change log between versions etc. we are very proud to offer this feature and think it will add a lot more functionality down the road as we continue to release new versions.

      These changes include 80+ commits by our development team, a list of them is summarized below and also available for your viewing pleasure in the new TRiBot Loader.

      In addition, we have taken additional steps to improve as a development team by adding continuous integration and deployment into our workflow to assist in delivering timely releases such as bug fixes as well as new features on a weekly basis depending on our development cycle.
      • 39 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...