Hmm 31 Share Posted March 3, 2022 (edited) Hi All, I am wanting to share my implementation of Utility classes for DreamBot which are not available through the DreamBot API. The first one I am going to share is the MinigameTeleporter class. This class is useful for allowing the local player to use the minigame teleports in the grouping tab. Below is the source code and how to use in your project. ALL AVAILABLE CLASSES CAN BE FOUND AT: https://github.com/HMM7777/DreamBotUtility SOURCE CODE Spoiler import org.dreambot.api.input.Mouse; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.MethodProvider; import org.dreambot.api.methods.settings.PlayerSettings; import org.dreambot.api.methods.tabs.Tab; import org.dreambot.api.methods.tabs.Tabs; import org.dreambot.api.methods.widget.Widgets; import org.dreambot.api.wrappers.widgets.WidgetChild; import static org.dreambot.api.Client.getLocalPlayer; //********************************************************************************* // CLASS: MinigameTeleporter // The purpose of this class is to allow the local player to access and // utilise the minigame teleports. // AUTHOR: Hmm //********************************************************************************* public class MinigameTeleporter { private static final int GROUPINGBITVALUE = 3; //Bit value of Grouping tab is 3. private static final int PLAYERSETTINGSINDEX = 13071; //Index 13071 checks which tab is currently selected in the clan tab. private static final int GROUPINGTABPARENT = 707; //Parent of the grouping tab icon. private static final int GROUPINGTABCHILD = 6; //Child of the grouping tab icon. private static final int GROUPINGTABGRANDCHILD = 3; //Grandchild of the grouping tab icon. private static final int ACTIVITYSELECTPARENT = 76; //Parent of the activity selection dropdown menu. private static final int ACTIVITYSELECTCHILD = 8; //Child of the activity selection dropdown menu. private static final int ACTIVITYPANELPARENT = 76; //Parent of the activity selection panel. private static final int ACTIVITYPANELCHILD = 18; //Child of the activity selection panel. private static final int TELEPORTBUTTONPARENT = 76; //Parent of the teleport button. private static final int TELEPORTBUTTONCHILD = 26; //Child of the teleport button. private static final int SCOLLBARPARENT = 76; //Parent of the scroll bar. private static final int SCOLLBARCHILD = 19; //Child of the scroll bar. private static final int SCOLLBARGRANDCHILD = 0; //Grandchild of the scroll bar. private static final int SCOLLBARTHUMBPARENT = 76; //Parent of the scroll bar thumb. private static final int SCOLLBARTHUMBCHILD = 19; //Child of the scroll bar thumb. private static final int SCOLLBARTHUMBGRANDCHILD = 1; //Grandchild of the scroll bar thumb. //********************************************************************************* // BOOLEAN METHOD: isMinigameTabOpen() // Checks if the minigame tab is open. //********************************************************************************* private static boolean isMinigameTabOpen() { return Tabs.isOpen(Tab.CLAN) && PlayerSettings.getBitValue(PLAYERSETTINGSINDEX) == GROUPINGBITVALUE; } //********************************************************************************* // VOID METHOD: selectAnActivity() // Opens the activity panel. //********************************************************************************* private static void selectAnActivity(WidgetChild activitySelect, WidgetChild activityPanel) { if (activitySelect != null && !activityPanel.isVisible()) { activitySelect.interact(); } } //********************************************************************************* // VOID METHOD: resetScrollBar() // Resets the scroll bar. //********************************************************************************* private static void resetScrollBar() { WidgetChild activityPanel = Widgets.getWidgetChild(ACTIVITYPANELPARENT, ACTIVITYPANELCHILD); WidgetChild scrollBar = Widgets.getWidgetChild(SCOLLBARPARENT, SCOLLBARCHILD, SCOLLBARGRANDCHILD); WidgetChild scrollBarThumb = Widgets.getWidgetChild(SCOLLBARTHUMBPARENT, SCOLLBARTHUMBCHILD, SCOLLBARTHUMBGRANDCHILD); if (Mouse.move(activityPanel.getRectangle()) && scrollBarThumb.getRectangle().getY() != scrollBar.getRectangle().getY()) { Mouse.scrollUpUntil(1000, () -> scrollBarThumb.getRectangle().getY() == scrollBar.getRectangle().getY()); MethodProvider.sleepUntil(() -> scrollBarThumb.getRectangle().getY() == scrollBar.getRectangle().getY(), 5000); } } //********************************************************************************* // BOOLEAN METHOD: isScrollBarThumbAtTop() // Checks if the thumb of the scroll bar is at the top. //********************************************************************************* private static boolean isScrollBarThumbAtTop() { WidgetChild scrollBar = Widgets.getWidgetChild(SCOLLBARPARENT, SCOLLBARCHILD, SCOLLBARGRANDCHILD); WidgetChild scrollBarThumb = Widgets.getWidgetChild(SCOLLBARTHUMBPARENT, SCOLLBARTHUMBCHILD, SCOLLBARTHUMBGRANDCHILD); return scrollBar.getRectangle().getY() == scrollBarThumb.getRectangle().getY(); } //********************************************************************************* // VOID METHOD: openMinigameTab() // Opens minigame tab. //********************************************************************************* public static void openMinigameTab() { if (Tabs.open(Tab.CLAN)) { if (!isMinigameTabOpen()) { WidgetChild groupingTab = Widgets.getWidgetChild(GROUPINGTABPARENT, GROUPINGTABCHILD, GROUPINGTABGRANDCHILD); groupingTab.interact(); MethodProvider.sleepUntil(() -> isMinigameTabOpen(), Calculations.random(5000, 6000)); } } } //********************************************************************************* // VOID METHOD: teleportMinigame() // Teleports player to desired minigame location. //********************************************************************************* public static void teleportMinigame(String minigameName) { WidgetChild activitySelect = Widgets.getWidgetChild(ACTIVITYSELECTPARENT, ACTIVITYSELECTCHILD); WidgetChild activityPanel = Widgets.getWidgetChild(ACTIVITYPANELPARENT, ACTIVITYPANELCHILD); if (!isMinigameTabOpen()) { openMinigameTab(); MethodProvider.sleepUntil(() -> activitySelect != null && activitySelect.isVisible(), 10000); } else { if (!activitySelect.getText().equals(minigameName)) { selectAnActivity(activitySelect, activityPanel); WidgetChild nameOfMinigame = Widgets.getMatchingWidget(w -> w != null && w.getText().equals(minigameName)); if (isScrollBarThumbAtTop()) { Mouse.move(activityPanel.getRectangle()); if (!activityPanel.getRectangle().contains(nameOfMinigame.getRectangle())) { Mouse.scrollDownUntil(1000, () -> activityPanel.getRectangle().contains(nameOfMinigame.getRectangle())); } nameOfMinigame.interact(); MethodProvider.sleepUntil(() -> activitySelect.getText().equals(minigameName), 1500); } else { resetScrollBar(); } } else { WidgetChild teleportButton = Widgets.getWidgetChild(TELEPORTBUTTONPARENT, TELEPORTBUTTONCHILD); if (teleportButton != null) { if (teleportButton.interact()) { MethodProvider.sleepUntil(() -> getLocalPlayer().isAnimating(), 15000); MethodProvider.sleepWhile(() -> getLocalPlayer().isAnimating(), 15000); } } } } } } HOW TO USE IN YOUR PROJECT The MinigameTeleporter is easy to use. The MinigameTeleporter class contains the method teleportMinigame(String minigameName). The teleportMinigame method takes a String parameter. This String literal is the name of the minigame you wish to teleport to. Note: the String literal has to be spelt appropriately in accordance with the widget text value in the minigame tab. Below is an example of teleporting to Clan Wars using the minigame teleports via the grouping tab. MinigameTeleporter.teleportMinigame("Clan Wars"); ADDITIONAL NOTES The sleep times used can be changed to your convenience. The sleep times I used were made quickly for my test environment. The MinigameTeleporter does not check if your minigame teleport is available (cooldown 20 minutes). You can wrap the teleportMinigame with a boolean checker to see if the teleport is on cooldown or not. I did play with Varbit 8354 which is the counter for the minigame teleport. Most minigames are made available in the grouping tab and are selectable within the interface however some of these minigames do not have a teleport. Be weary of this. This class will most likely be used for F2P accounts or niche use cases. Please let me know how it goes. Any constructive criticism will be appreciated. Regards, Hmm. MinigameTeleporter.java Edited March 4, 2022 by NEWPROG Added GitHub link. yeeter, camelCase, Hashtag and 3 others 4 2 Link to comment Share on other sites More sharing options...
Hans Zimmer 18 Share Posted March 3, 2022 Ty Hmm 1 Link to comment Share on other sites More sharing options...
Hashtag 8670 Share Posted March 4, 2022 Thank you for the contribution 🙂 Hmm 1 Link to comment Share on other sites More sharing options...
Hans Zimmer 18 Share Posted March 31, 2022 Thanks for the contribution, added to one of my scripts! Link to comment Share on other sites More sharing options...
Hmm 31 Author Share Posted April 1, 2022 On 4/1/2022 at 12:07 AM, Hans Zimmer said: Thanks for the contribution, added to one of my scripts! You're welcome! Great to hear. Link to comment Share on other sites More sharing options...
mamo95 0 Share Posted June 11, 2022 Thanks for the script but not working with me Link to comment Share on other sites More sharing options...
Hmm 31 Author Share Posted June 12, 2022 12 hours ago, mamo95 said: Thanks for the script but not working with me I will look into it and get back to you. Link to comment Share on other sites More sharing options...
Hmm 31 Author Share Posted June 12, 2022 @mamo95 It is still functioning. Are you trying to develop a script using this class? mamo95 1 Link to comment Share on other sites More sharing options...
mamo95 0 Share Posted June 13, 2022 23 hours ago, Hmm said: @mamo95 It is still functioning. Are you trying to develop a script using this class? No i just want to teleport and l did it with my function . Thank you your class was help me a lot. ❤️🌹 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now