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

Sell 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
Array

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 2

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

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

    • By Trixztor
      i purchased 8 credits was charged twice and never got the credits, can i just get the 16 credits and call it good? i made a support ticket but 3 days and no response. any advice on what to do? thanks all
    • By Flax
      Debian 7.0 VPS Setup Guide for TRiBot Botting. 
      By: Flax
       
      Hey guys today I'm going to show you how to setup a VPS for TRiBot botting, I'm making it because I got so many questions from people about this & most VPS guides here are pretty outdated.
      Make sure your VPS operating system is Debian 7 32 or 64bit, or else this guide will not work for you!
      Okay, let's begin.
       
      First off you'll need these programs:
      - PuTTy
      - TightVNC Viewer
      Once you've downloaded those files we can begin setting up your VPS.
       
      Step 1: Open PuTTy and enter your IP and click connect (You should keep the port 22)

       
      Step 2: Now a command prompt will pop up and it'll ask you for a username, Type ' root ' and after that it'll ask you for a password, type in the password that was given to you by your VPS provider.
       
      Step 3: Now you should enter the following commands one-by-one, it can take awhile to install depending on the speed:
      apt-get update apt-get install curl curl https://dl.dropboxusercontent.com/s/jabcbltmn5fuevx/install.sh | sh apt-get install iceweasel Step 4: After that's done you should be able to connect with the VPS through TightVNC.
      REMEMBER: MAKE SURE TO ADD :1 BEHIND THE IP.

       
      This is how it should look:
      Once connected, you can download TRiBot/OSBuddy via the Iceweasel browser(similiar to Firefox).
       
      If you're unable to open TRiBot, try this:
       
      Looking for cheap VPS deals and don't know where to look? Check out Lowendbox, FinalHosting
  • Our picks

    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
      • 50 replies
    • Come give us feedback on the next version of TRiBot!
      • 86 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
      • 25 replies
    • Over the last three weeks, I've been working on upgrading our server infrastructure. It's finally ready and is now live!

      Why?

      Increased reliability - less server errors


      Increased availability - less downtime


      Increased security - keeping us and you secure


      Increased capacity - ability to serve you better


      Increased speed - less waiting for things to load


      Faster development - server and service updates will come faster


      What are the changes?

      Move from a single AWS EC2 instance to AWS ECS (Elastic Container Service)


      Distributed computing


      Load balancing


      Git management of server files and filesystem


      Redis caching


      How?

      AWS ECS (with 10 EC2 instances)


      AWS ElastiCache (Redis)


      AWS Load Balancing


      AWS EFS (Elastic file system)


      Please bare with us as I continue to tune the server for maximum performance. Slow loading speeds may occur temporarily. I thank everyone for their patience.

      Please post on this thread if you experience any issues other than slow loading times.
      • 51 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...