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

Sphiinx

[TUTORIAL] Dynamic Sleeping/Conditional Sleeping

Recommended Posts

Conditional Sleeping

upSYdVQ.png

 

 

             Description
7ANo6V1.png

  • I see a lot of new users who are just beginning scripting using static sleep methods. This is really inefficient and a bad habit because your script will sleep every time it reaches that point instead of just when it needs to.

 

  • I will be showing you how to use Tribot's method for Conditional Sleeping.

 

 

 

             What is it?
7ANo6V1.png

  • Conditional sleeping is a way to allow the script to sleep for a given amount of time until the given condition returns a true value.

 

 

 

      Why should I use it?
7ANo6V1.png

  • This will allow your script to continue without sleeping if the current action succeeded, if the action didn't succeed before the timeout it will return false. This will make the overall efficiency of your scripts will be quicker and more human like.

 

 

 

         API Information
7ANo6V1.png

 

 

 

        Implementation
7ANo6V1.png

  • Firstly you must import the Timing class and the Condition class from the Tribot API.
    • import org.tribot.api.Timing;import org.tribot.api.types.generic.Condition;

 

 

  • Next we must call Timing#waitCondition and give it the correct parameters. We will create a new condition.
    • Timing.waitCondition(new Condition() {
                  @Override
                  public boolean active() {
                      General.sleep(100); // Add this in to reduce CPU usage
                      return false;
                  }
              })

       

 

  • Lastly we must return a value and create a timeout.
    • Timing.waitCondition(new Condition() {
                  @Override
                  public boolean active() {
                      General.sleep(100);
                      return //TODO Return value
                  }
              }, General.random(1000, 1200));

       

 

 
               Example
7ANo6V1.png
  • Here is an example of this being used.
    • public void openBank() {
              if (!Banking.isBankScreenOpen()) {
                  if (Banking.openBank()) {
                      Timing.waitCondition(new Condition() {
                          @Override
                          public boolean active() {
                              General.sleep(100); // Add this in to reduce CPU usage
                              return Banking.isBankScreenOpen();
                          }
                      }, General.random(750, 1000));
                  }
              } else {
                  // Do something
              }
          }

       

Edited by Sphiinx
  • Like 10

Share this post


Link to post
Share on other sites

I think the language used in this could be edited to sound more intuitive, you are kind of describing the broad outline of conditional sleeping, rather than specifically what it does or a line by line analysis.

 

For example, you could display that the condition is simply an object which has a boolean method, which returns the boolean if it is true before the timeout, or after the timeout parameter if the boolean has not been fulfilled.

 

You could also go on to say how one should save conditions for additional usage and why a random timeout is used, e.g anti-ban.

 

Possibly even discuss why you would used wait condition over similar methods users have created in the past.

  • Like 1

Share this post


Link to post
Share on other sites

I think the language used in this could be edited to sound more intuitive, you are kind of describing the broad outline of conditional sleeping, rather than specifically what it does or a line by line analysis.

 

For example, you could display that the condition is simply an object which has a boolean method, which returns the boolean if it is true before the timeout, or after the timeout parameter if the boolean has not been fulfilled.

 

You could also go on to say how one should save conditions for additional usage and why a random timeout is used, e.g anti-ban.

 

Possibly even discuss why you would used wait condition over similar methods users have created in the past.

 

The API explains that pretty well and I didn't want to copy the API line by line when its already there for the user. Good points though, thanks!

Share this post


Link to post
Share on other sites
Guest

I thought it is useless to use timing.waitcondition, because banking.openbank will return true when the bankscreen isopen,otherwise it will return false.

 

openBank

public static boolean openBank()

Opens the bank by either RSObject or RSNPC. Will use PathFinding.aStarWalk(..) if the bank is not on the screen.
Returns: True if the bank was successfully opened; false otherwise.

Share this post


Link to post
Share on other sites
On 5/29/2016 at 8:36 PM, Sphiinx said:

Nope

Bump!

thanks for the response, Im getting a new class for every time i use the following in my script...

 

                      if (item[0].click("Use")) {
                        Timing.waitCondition(new Condition() {
                          @Override
                          public boolean active() {
                            General.sleep(100); // Add this in to reduce CPU usage
                            return Game.isUptext("item uptext");
                          }
                        }, General.random(2000, 3000));
                      }

how do you implement it so it doesn't create a new class every time?

Edited by seany123456

Share this post


Link to post
Share on other sites
Just now, seany123456 said:

thanks for the response, Im getting a new class for every time i use the following in my script...

 

                      if (item[0].click("Use")) {
                        Timing.waitCondition(new Condition() {
                          @Override
                          public boolean active() {
                            General.sleep(100); // Add this in to reduce CPU usage
                            return Game.isUptext("Use Limpwurt seed ->");
                          }
                        }, General.random(2000, 3000));
                      }

how do you implement it so it doesn't create a new class every time?

 

 

That's odd. it shouldn't be creating a new class. Depending on your IDE, If you type "Timing.waitCondition(new Condition()" or part of it, you should be able to autogenerate the rest. if that doesn't work, I would just copy and paste it into the class until you figure out the issue.

Share this post


Link to post
Share on other sites
10 minutes ago, Sphiinx said:

 

That's odd. it shouldn't be creating a new class. Depending on your IDE, If you type "Timing.waitCondition(new Condition()" or part of it, you should be able to autogenerate the rest. if that doesn't work, I would just copy and paste it into the class until you figure out the issue.

Im not sure then when i type Timing.wait eclipse gives the option of waitCondition, although i would still need to type in the newCondition(){} part in myself.

 

with this code for example: 

package scripts;

import org.tribot.api.General;
import org.tribot.api.Timing;
import org.tribot.api.types.generic.Condition;
import org.tribot.api2007.Game;
import org.tribot.script.Script;

public class TimerTest extends Script {

	@Override
	public void run() {
		// TODO Auto-generated method stub
        Timing.waitCondition(new Condition(){
            public boolean active() {
                General.sleep(100); // Add this in to reduce CPU usage
                return Game.isUptext("Test");
              }
        }, General.random(2000, 3000));
        
        Timing.waitCondition(new Condition(){
            public boolean active() {
                General.sleep(100); // Add this in to reduce CPU usage
                return Game.isUptext("Test");
              }
        }, General.random(2000, 3000));
	}
}

it gives the the following files.

timertestclass.png

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 sslippi
      I want to start by saying I'm new to programming.
       
      I'm trying to make a basic script that completes Druidic Ritual. I'm trying to withdraw all of the quest items and teleports needed with Banking.withdraw().
       
      Like this:
      Banking.withdraw(0, 2138, 2136, 2132, 2134, 8007, 3853); I'm wanting to avoid adding a static wait just so I can get good practice with implementing anti-ban. How would I go about making this method not spam click the items when trying to withdraw them?
    • By notsmile
      So I wanted to make a GUI for my Runecrafter and use TitledBorders instead of using tabs since it looks nicer imo.
      I can't seem to get the TitledBorder to appear fully (I think that's the problem anyway) properly in the GUI.
      It looks like this:
       
      Here is the code for it:
      JPanel runesPanel = new JPanel(); runesPanel.setBackground(Color.DARK_GRAY); TitledBorder runesBorder = BorderFactory.createTitledBorder("Runes"); runesBorder.setTitleColor(Color.lightGray); runesBorder.setTitleJustification(TitledBorder.LEFT); runesPanel.setBorder(runesBorder); JComboBox<String> runeOptions = new JComboBox<String>(new String[] { "Select Runes", "Air", "Astral*", "Blood*", "Cosmic", "Earth", "Fire", "Law", "Mud", "Nature", "Soul*", "Water", "Wrath*", "ZMI*"}); runesPanel.setBounds(20,20,200,200); runesPanel.add(runeOptions); mainGuiSettingsPanel.add(runesPanel); mainGuiFrame.setVisible(true); } }  
      Sorry for the nooby question, new to using Swing and Java
      Thanks!
    • By jerrycan314
      when i open a tribot client it crashes and i get this error :c

      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7a0e3d9d, pid=1608, tid=0x00000e54
      #
      # JRE version: Java(TM) SE Runtime Environment (8.0_251-b08) (build 1.8.0_251-b08)
      # Java VM: Java HotSpot(TM) Client VM (25.251-b08 mixed mode windows-x86 )
      # Problematic frame:
      # C  [atiglpxx.dll+0x3d9d]
      #
    • By Heroinkid
      Hi I got a proxy server from Virmach. I cannot seem to get Tribot to connect to it. I have gotten a 3rd party internet browser called Maxthus to get it to work so I don't think that its the server that's not working. Yes I have VIP-E as well. Please help thanks!

    • By porkthug
      So I've been playing OSRS casually for a couple years now and only tried botting a handful of times, mostly out of curiosity. I'm looking to get back into botting more seriously (as in enough to make a real profit from it). I know some of the basic measures to take for safe botting and whatnot, but I have some general questions.
      Can I expect a profit from only botting 2-3 accounts for around 12 hours a day? I'm running a not-so-speedy computer that probably can't handle much more than that. How many accounts should I trade my gold through to avoid bans? And how often should I dump the gold off of a botted account? I know I should use proxies if I'm doing multiple accounts, but it seems like a VPS isn't necessary right now. I'm new to both so any suggestions are welcome. Should I start with F2P bots? I have about 40m on my main that I could spend on bonds. I have no experience coding or writing scripts. Is it worth learning right now or am I okay to just download/buy other people's scripts? Sorry if this isn't the right place to ask these questions or if they're too general. I'm a little overwhelmed with all the technical stuff involved in botting. Seems like most guides are kind of dated too.
    • By QNDLF
      Has been fine for the past few days however doesn't work today, have deleted the full .jar file and redownloaded again and it has the same problem
       
      Any ideas how to fix it? 
       

    • By tomking50
      Hello, 
      I've just purchased this bot and im wondering how do i set breaks to avoid bans?
       
      Thank you,   
    • By Fluffee
      Creating this thread to provide an easy way for me to link new users to my tutorials, as well as have them all in my Signature, without making it obnoxious.
      -- Fluffee's Ultimate Guide to Botting Series --
      -- General Tutorials --
      -- AutoHotKey Releases --
    • By will6100
      I really love the process of developing a script, testing it, debugging it, etc.. So after writing my first really simple script that would tan hides, I got my first botting account banned, which is something I knew was gonna happen since my lack of scripting knowledge. Im ready to get a new one up and going and continue to develop more basic scripts to sharpen my scripting skills. Im sharing my first script here and looking to hear what I should do and should not do. Also get some tips on what to look for to reduce the banning rates of my testing accounts. The account I was using was only combat lvl 5 and didnt have any quests done, I guess that didnt help too? I was also about to introduce ABC2 into the script and learn how to use it but my account got banned right before I could implement it. So looking forward to hear your criticisms about my script and tips to not get the script bannable. Also have in mind I didnt really refactor anything, some parts may look ugly, beware!
      package scripts; import org.tribot.api.DynamicClicking; import org.tribot.api.General; import org.tribot.api.Timing; import org.tribot.api.input.Mouse; import org.tribot.api2007.*; import org.tribot.api2007.types.RSNPC; import org.tribot.api2007.types.RSObject; import org.tribot.api2007.types.RSTile; import org.tribot.api2007.util.ThreadSettings; import org.tribot.script.Script; import org.tribot.script.ScriptManifest; import java.awt.*; import java.util.function.BooleanSupplier; @ScriptManifest(category = "Moneymaking", authors = "will6100" , name = "Tanner") public class Tanner extends Script { private final static int BLACK_DHIDE_ID = 1747; private final static int TANNED_LEATHER_ID = 2509; private final static int ELLIS_ID = 3231; private final static int BANK_BOOTH_ID = 10355; private final static int COINS_ID = 995; private boolean isBankable() { RSObject[] booths = Objects.findNearest(100, BANK_BOOTH_ID); if (booths.length > 1) { return booths[0].isOnScreen(); } return false; } private boolean coinsCheck() { if (Inventory.find(COINS_ID).length < 1) { if (Banking.find(COINS_ID).length > 0) { if (!Inventory.isFull()) { return Banking.withdraw(0, COINS_ID); } else { if (Inventory.find(BLACK_DHIDE_ID).length > 0) { return Banking.deposit(1, BLACK_DHIDE_ID); } else if (Inventory.find(TANNED_LEATHER_ID).length > 0){ return Banking.depositAll() > 0; } } } } else { return true; } return false; } private boolean bank() { if (!openBank()) { General.println("Couldnt open bank"); return false; } if (!coinsCheck()) { General.println("No more gold"); return false; } if (!setupInventory()) { General.println("No more hides"); return false; } sleep(100,1000); return true; } private boolean setupInventory() { if (Inventory.find(TANNED_LEATHER_ID).length > 0) { sleep(50,1000); if (Banking.deposit(0,TANNED_LEATHER_ID)) { if (Banking.find(BLACK_DHIDE_ID).length > 0){ sleep(50,1000); Banking.withdraw(0, BLACK_DHIDE_ID); return Timing.waitCondition(this::readyToTan, General.random(3000,5000)); } } } else if (Inventory.find(TANNED_LEATHER_ID).length < 1) { sleep(50,1000); if (Banking.find(BLACK_DHIDE_ID).length > 0){ Banking.withdraw(0, BLACK_DHIDE_ID); return Timing.waitCondition(this::readyToTan, General.random(3000,5000)); } } return false; } private boolean openBank() { if (!Banking.isBankScreenOpen()) { if (!isBankable()){ if(!walkToDestCondition(this::isBankable)) { return false; } } return clickBankBooth(); } return true; } private boolean clickBankBooth() { RSObject[] bankBooths = Objects.findNearest(40, BANK_BOOTH_ID); RSObject booth; if(bankBooths.length > 1) { do { sleep(50); booth = bankBooths[General.random(0, bankBooths.length - 2)]; } while (!booth.isOnScreen() && !booth.isClickable()); booth.hover(); if (isHoverRendered(Mouse.getPos())){ Mouse.click(1); }else { clickBankBooth(); } return Timing.waitCondition(Banking::isBankScreenOpen, General.random(25000,27000)); } return false; } private boolean isHoverRendered (Point toHover) { return !Screen.getColorAt(Mouse.getPos()).equals(new Color(0, 0, 0)); } private boolean isTannable() { RSNPC[] ellis = NPCs.find(ELLIS_ID); if (ellis.length < 1) { return false; } else if (isTanningWindowOpen()){ return true; } return ellis[0].isOnScreen(); } private boolean tanLeather() { RSNPC ellis; if (isTannable()) { sleep(100,200); ellis = NPCs.find(ELLIS_ID)[0]; while (!isTanningWindowOpen()) { Mouse.setSpeed(190); sleep(300,500); if (DynamicClicking.clickRSNPC(ellis,"Trade " + ellis.getName())){ Mouse.setSpeed(115); Timing.waitCondition(this::isTanningWindowOpen, General.random(15000, 17000)); sleep(200,500); Interfaces.get(324,107).click("Tan all"); return Timing.waitCondition(() -> !isTanningWindowOpen(), General.random(3000,5000)); } } } else { return walkToDestCondition(this::isTannable); } return false; } private boolean walkToDestCondition(BooleanSupplier waitCondition) { Walking.blindWalkTo(new RSTile(3278 + General.random(-2,2), 3180 + General.random(-1, 1))); return Timing.waitCondition(waitCondition, General.random(11000,12000)); } private boolean isTanningWindowOpen() { return Interfaces.isInterfaceValid(324); } private boolean readyToTan() { return Inventory.find(BLACK_DHIDE_ID).length > 0 && Inventory.find(COINS_ID).length > 0 ; } @Override public void run() { Mouse.setSpeed(115); ThreadSettings ts = new ThreadSettings(); ts.setClickingAPIUseDynamic(true); while (true) { sleep(50); if (isTannable()) { if (readyToTan()) { if(!tanLeather()){ General.println("1"); break; } } else { if(!bank()) { General.println("2"); break; } } } else if (isBankable()) { if (readyToTan()) { if(!tanLeather()){ General.println("3"); break; } } else { if(!bank()) { General.println("4"); break; } } } else if (readyToTan()) { if(!tanLeather()){ General.println("5"); break; } } else { if(!bank()) { General.println("6"); break; } } } } }  
    • By schenkelenkel
      Getting this error, client won't start.

  • Our picks

    • Gradle is a build tool used to accelerate developer productivity.

      We recently setup a Maven repository (TRiBot Central) to make it easier for scripters to create scripts. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-central/-/packages

      Furthermore, we've released a simple Gradle project to make it easy to run TRiBot and develop scripts for it. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-gradle-launcher

      The goals of TRiBot Central are to:

      Deliver updates to TRiBot faster


      Better organize TRiBot's dependencies (AKA dependancies)


      Make it easier to develop scripts for TRiBot


      Make it easier to use and run TRiBot


      Note: TRiBot won't be able to run scripts from within this project until TRiBot's next release.
        • Like
      • 8 replies
    • Hi everyone,

      I'd like to thank everyone for their patience in this transition period. Since last week, we've worked out the remaining bugs with this integration.

      Some users have still been having issues with connecting their forums account to their Auth0 account. To resolve this, we've imported all forums accounts into Auth0.

      Unfortunately, the accounts which were imported today were using an unsupported password hashing algorithm. Hence, random passwords were set during the import.

      What does this mean for me?

      If you've previously linked your forums account to your Auth0 account, you don't have to do anything. Nothing changes for you.


      If you haven't logged in via our new login yet,

      Try logging in with your forums email address and the last password you used


      If you are unable to login, please use the "Forgot password" tool on the login page:
      Follow the instructions to reset your password
       
        • thonking
        • Like
      • 15 replies
    • Hello everyone,

      Last week we tried to roll out Auth0 Login, but we lost that battle. Now it's time to win the war!

      Important changes

      When logging into the client, you'll now have to enter your Auth0 account credentials instead of your forums credentials

      Note: 2FA is still handled through your forums account (for the time being)



      Changes for existing users

      You'll have to link your Auth0 account to your forums account here: https://tribot.org/forums/settings/login/?service=11


      Auth0 accounts have been created for most existing users. Please use your forums email address and password to login.



      Important notes

      Make sure to verify your email address upon creating a new Auth0 account


      When we mention your Auth0 account, we mean your account used for auth.tribot.org as displayed below
      • 81 replies
    • To better support the upcoming changes (TRiBot X, new repository), we're switching our login handler to Auth0. Instead of logging in with the standard form, you'll now be required to login through our Auth0 application.

      All existing accounts which have been used within approximately the past year have been imported into Auth0 using the same email and password combination which has been stored on the forums.

      What does this mean for users?

      Your account credentials are now even more securely stored


      You'll be able to login via Facebook, Google, and others in the future


      Is there anything users have to do differently now?

      Existing users: You'll have to login with the standard login, open your Account Settings, then link your Auth0 account


      New users: You'll be redirected to our Auth0 app (auth.tribot.org) where you'll be able to create an account


      Why was this change made?

      The new apps we are creating (such as the new repository) aren't able to use the forums to handle user logins


      To centralize all user accounts in one area


      To ensure that the client login doesn't go down when the forums are having problems


      To speed up our development


      Other considerations

      There's no documentation or official support for using Invision Community combined with Auth0, so there are still a few kinks we're working out


      We're in the works of creating an account management panel specifically for Auth0 accounts (ETA August)


      It's not possible to change email addresses for the time being (this will be resolved this August)


      Changing passwords is a weird process for the time being. To change your password, you'll have to use the "Don't remember your password" tool on the Auth0 login page
        • Like
      • 11 replies
    • Over the past month, we've been working hard on TRiBot's new repository - a much needed update. This change has been deemed necessary for TRiBot X, and will allow us to really speed up development of all aspects of TRiBot.

      Today we are going to share what we've been working on!


      Now you must be wondering what kind of features the new repository will have.... well, you'll have to be patient for a little while longer. We're still figuring out various technical aspects so we can't provide answers to all possible questions. We're also focusing on development rather than writing about it so that everyone can get access to our latest developments at lightning speed. I will however answer a few users' questions.

      We're planning on a release of this early to mid August, giving users some goodies before TRiBot X's release.

      Thank you all for being patient. I hope everyone is excited as much as I am!
        • Like
      • 17 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...