Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Easy Sleeping Snippet

Featured Replies

I became annoyed at typing sleep x + gRandom(y,z); so I wrote this so you can simply enter three values (you can change it to more) and it will randomize the sleep method furthermore. Not only that, instead of having to type out your sleep every time, you just type:

Sleep();

Here's the code:

 

private boolean dynamicBase;

    int s0 = 750; // Base value
    int s1 = 0;
    double s2 = 0;
    
    public void subSleep() throws InterruptedException {
        sleep(s0 + gRandom(s1, s2));
    }

    public void sleep() throws InterruptedException {
        
        Random sleepRandom = new Random();
        switch (random(1, 3)) {
            case 1:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(500);
                }
                s1 = sleepRandom.nextInt(1000);
                s2 = 250 + (1500 - 500) * sleepRandom.nextDouble();
                subSleep();
            case 2:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(100);
                }
                s1 = sleepRandom.nextInt(250);
                s2 = 500 + (800 - 200) * sleepRandom.nextDouble();
                subSleep();
            case 3:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(45);
                }
                s1 = sleepRandom.nextInt(250);
                s2 = 500 + (800 - 200) * sleepRandom.nextDouble();
                subSleep();
        }
    }
 

Pretty much, your sleep is now: randomBase(optionally) + randomint(randomint + (randomint(randomint)) + (randomDouble(randomDouble))) 

 

Making your sleeps math-ambiguous.

  • Author

l2 use conventions tongue.png

 

Happy? :P

 

So how would you use this.

Sleep(500+200,300);

 

If you want to do that just use the normal method..

 

l2 use conventions tongue.png

 

Happy? tongue.png

 

So how would you use this.

Sleep(500+200,300);

 

If you want to do that just use the normal method..

 

No, you missed a spot.

 

@1st Sleep();

I think you would be much better off using this (quick writeup)

public void newSleep(int min, int max) {
   int x = 0;
   do {
      x = gRandom(min,max,(double)(max-min)/2);
   } while (x < min || x > max);
   sleep(x);
}
This way you can refine it in certain areas of your code, instead of it being generally around one area.

Edited by dreamliner

Nice, would use but I don't use sleeps.

 

l2 use conventions tongue.png

 

Happy? tongue.png

 

So how would you use this.

Sleep(500+200,300);

 

If you want to do that just use the normal method..

 

why not use dynamic sleeps?

import timer.Timer;
import org.osbot.script.Script;

import org.osbot.script.rs2.model.Player;

public class Singleton {


    private final  Script script;
    private static Singleton oneInstance;

    private  Singleton(Script script){
             this.script = script;
    }

    public static Singleton getInstance(final Script script){
        if(oneInstance == null){
            oneInstance = new Singleton(script);
        }
        return oneInstance;
    }



    public boolean isIdle(){
        Player p = script.client.getMyPlayer();
        return !p.isAnimating() && p.getAnimation()==-1 && !p.isMoving() && !p.isUnderAttack();
    }

       public void dynamicSleep(final boolean condition){
         Timer  timer = new Timer(800);
        try{
            while(!isIdle() && condition && timer.isRunning())
                script.sleep(10);
        }
        catch (InterruptedException e){e.printStackTrace();}
          
       }

   }












  • Author

I think you would be much better off using this (quick writeup)

public void newSleep(int min, int max) {
   int x = 0;
   do {
      x = gRandom(min,max,(double)(max-min)/2);
   } while (x < min || x > max);
   sleep(x);
}
This way you can refine it in certain areas of your code, instead of it being generally around one area.

 

 

 

That's not as randomized as the method I posted, nor is it as simplified. 

 

 

 

l2 use conventions tongue.png

 

Happy? tongue.png

 

So how would you use this.

Sleep(500+200,300);

 

If you want to do that just use the normal method..

 

why not use dynamic sleeps?

import timer.Timer;
import org.osbot.script.Script;

import org.osbot.script.rs2.model.Player;

public class Singleton {


    private final  Script script;
    private static Singleton oneInstance;

    private  Singleton(Script script){
             this.script = script;
    }

    public static Singleton getInstance(final Script script){
        if(oneInstance == null){
            oneInstance = new Singleton(script);
        }
        return oneInstance;
    }



    public boolean isIdle(){
        Player p = script.client.getMyPlayer();
        return !p.isAnimating() && p.getAnimation()==-1 && !p.isMoving() && !p.isUnderAttack();
    }

       public void dynamicSleep(final boolean condition){
         Timer  timer = new Timer(800);
        try{
            while(!isIdle() && condition && timer.isRunning())
                script.sleep(10);
        }
        catch (InterruptedException e){e.printStackTrace();}
          
       }

   }












 

As I said, I was trying to make it as random as possible.

I became annoyed at typing sleep x + gRandom(y,z); so I wrote this so you can simply enter three values (you can change it to more) and it will randomize the sleep method furthermore. Not only that, instead of having to type out your sleep every time, you just type:

Sleep();

Here's the code:

 

private boolean dynamicBase;

    int s0 = 750; // Base value
    int s1 = 0;
    double s2 = 0;
    
    public void subSleep() throws InterruptedException {
        sleep(s0 + gRandom(s1, s2));
    }

    public void sleep() throws InterruptedException {
        
        Random sleepRandom = new Random();
        switch (random(1, 3)) {
            case 1:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(500);
                }
                s1 = sleepRandom.nextInt(1000);
                s2 = 250 + (1500 - 500) * sleepRandom.nextDouble();
                subSleep();
            case 2:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(100);
                }
                s1 = sleepRandom.nextInt(250);
                s2 = 500 + (800 - 200) * sleepRandom.nextDouble();
                subSleep();
            case 3:
                if (dynamicBase) {
                    s0 = sleepRandom.nextInt(45);
                }
                s1 = sleepRandom.nextInt(250);
                s2 = 500 + (800 - 200) * sleepRandom.nextDouble();
                subSleep();
        }
    }
 

Pretty much, your sleep is now: randomBase(optionally) + randomint(randomint + (randomint(randomint)) + (randomDouble(randomDouble))) 

 

Making your sleeps math-ambiguous.

Kati! Finally Yay A Snippet :D

Thanks! I Will Be Using This! :D

What's wrong with sleep(random(min, max));

 

Why make something simple, complicated? -,-

 

I think you would be much better off using this (quick writeup)

public void newSleep(int min, int max) {
   int x = 0;
   do {
      x = gRandom(min,max,(double)(max-min)/2);
   } while (x < min || x > max);
   sleep(x);
}
This way you can refine it in certain areas of your code, instead of it being generally around one area.

 

 

 

That's not as randomized as the method I posted, nor is it as simplified. 

I'd have to disagree.  I did a little bit of statistical analysis on your method:

 

Case one yields an average range of 750 to 2000 if not using a dynamic base. 

Case one yields an average range of 250 to 1500 if using a dynamic base. 

 

Case two yields an average range of 750 to 1675 if not using a dynamic base.

Case two yields an average range of 50 to 975 if using a dynamic base.

 

Case three yields an average range of 750 to 1675 if not using a dynamic base.

Case three yields an average range of 23 to 948 if using a dynamic base.

 

(all of these are bell curves with their peak at the mean)

 

If you logged every time the bot slept, you would have a graph that looks like 2 or 3 superimposed bell curves (or 5 if you randomly use the dynamic base).

 

To have something truly random, you have to use this method along with a way of changing the base to better suit your needs in a script.  Such as an action that requires 1 tick compared to something that needs 5.  If you slept the same way every time, it would look obvious by the randomness of it.

 

By default, humans are not random.  There was a study done that asked a human to flick on and off a light switch in a random pattern.  The study concluded that there was a non-random pattern that the person followed subconsciously.  When humans do actions, they get tuned to what they are doing.  It is very easy to keep the beat in a song, compared to trying to play something in random intervals.  Its not how our brains work.

 

This is a very well written video explaining what I'm walking about http://www.youtube.com/watch?v=H2lJLXS3AYM

Edited by dreamliner

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.